You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2014/01/08 12:49:32 UTC
git commit: AMBARI-4226. Unittests for Package resource an all it's
attributes mocking to both suse and centos (aonishuk)
Updated Branches:
refs/heads/trunk 56b888078 -> 5e5d119d0
AMBARI-4226. Unittests for Package resource an all it's attributes
mocking to both suse and centos (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5e5d119d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5e5d119d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5e5d119d
Branch: refs/heads/trunk
Commit: 5e5d119d0914d070136cf7a8bf6078fad724b61f
Parents: 56b8880
Author: Andrew Onischuk <ao...@hortonworks.com>
Authored: Wed Jan 8 03:45:42 2014 -0800
Committer: Andrew Onischuk <ao...@hortonworks.com>
Committed: Wed Jan 8 03:45:42 2014 -0800
----------------------------------------------------------------------
.../resource_management/TestPackageResource.py | 72 ++++++++++++++++++++
1 file changed, 72 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5e5d119d/ambari-agent/src/test/python/resource_management/TestPackageResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestPackageResource.py b/ambari-agent/src/test/python/resource_management/TestPackageResource.py
new file mode 100644
index 0000000..c67f662
--- /dev/null
+++ b/ambari-agent/src/test/python/resource_management/TestPackageResource.py
@@ -0,0 +1,72 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+from unittest import TestCase
+from mock.mock import patch, MagicMock
+
+from resource_management.core import Environment, Fail
+from resource_management.core.system import System
+from resource_management.core.resources import Package
+
+from resource_management.core import shell
+
+class TestPackageResource(TestCase):
+
+ @patch.object(shell, "checked_call")
+ @patch.object(System, "platform", new = 'redhat')
+ def test_action_install_rhel(self, shell_mock):
+ with Environment('/') as env:
+ Package("some_package",
+ )
+ shell_mock.assert_called_with("/usr/bin/yum -d 0 -e 0 -y install some_package")
+
+ @patch.object(shell, "checked_call")
+ @patch.object(System, "platform", new = 'suse')
+ def test_action_install_suse(self, shell_mock):
+ with Environment('/') as env:
+ Package("some_package",
+ )
+ shell_mock.assert_called_with("/usr/bin/zypper --quiet install --auto-agree-with-licenses --no-confirm some_package")
+
+
+ @patch.object(shell, "checked_call")
+ @patch.object(System, "platform", new = 'redhat')
+ def test_action_remove_rhel(self, shell_mock):
+ with Environment('/') as env:
+ Package("some_package",
+ action = "remove"
+ )
+ shell_mock.assert_called_with("/usr/bin/yum -d 0 -e 0 -y erase some_package")
+
+ @patch.object(shell, "checked_call")
+ @patch.object(System, "platform", new = 'suse')
+ def test_action_remove_suse(self, shell_mock):
+ with Environment('/') as env:
+ Package("some_package",
+ action = "remove"
+ )
+ shell_mock.assert_called_with("/usr/bin/zypper --quiet remove --no-confirm some_package")
+
+ @patch.object(shell, "checked_call")
+ @patch.object(System, "platform", new = 'redhat')
+ def test_action_install_version_attr(self, shell_mock):
+ with Environment('/') as env:
+ Package("some_package",
+ version = "3.5.0"
+ )
+ shell_mock.assert_called_with("/usr/bin/yum -d 0 -e 0 -y install some_package-3.5.0")