diff options
Diffstat (limited to 'src/software/test/test_software_package.py')
-rwxr-xr-x | src/software/test/test_software_package.py | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/src/software/test/test_software_package.py b/src/software/test/test_software_package.py deleted file mode 100755 index 4cd5da9..0000000 --- a/src/software/test/test_software_package.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2012 Red Hat, Inc. All rights reserved. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# Authors: Michal Minar <miminar@redhat.com> -# -""" -Unit tests for LMI_SoftwareInstalledPackage provider. -""" - -import pywbem -import unittest - -import common -import rpmcache - -class TestSoftwarePackage(common.SoftwareBaseTestCase): #pylint: disable=R0904 - """ - Basic cim operations test. - """ - - CLASS_NAME = "LMI_SoftwarePackage" - KEYS = ( "Name", "SoftwareElementID", "SoftwareElementState" - , "TargetOperatingSystem", "Version") - - def make_op(self, pkg, newer=True, ses=2): - """ - @param ses SoftwareElementState property value - @return object path of SoftwarePackage - """ - objpath = self.objpath.copy() - objpath["Name"] = pkg.name - objpath["SoftwareElementID"] = pkg.get_nevra(newer, "ALWAYS") - objpath["SoftwareElementState"] = pywbem.Uint16(ses) - objpath["TargetOperatingSystem"] = pywbem.Uint16(36) - objpath["Version"] = getattr(pkg, 'up_ver' if newer else 'ver') - return objpath - - @common.mark_dangerous - def test_get_instance(self): - """ - Tests GetInstance call on packages from our rpm cache. - TODO: test this in non-dangerous way - """ - for pkg in self.pkgdb: - if common.is_installed(pkg.name): - common.remove_pkg(pkg.name) - objpath = self.make_op(pkg, ses=1) - inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False) - self.assertEqual(inst.path, objpath, - "Object paths should match for %s"%pkg) - for key in self.KEYS: - self.assertTrue(inst.properties.has_key(key), - "OP is missing \"%s\" key for package %s"%(key, pkg)) - if key == "TargetOperatingSystem": - self.assertIsInstance(inst.path[key], (int, long)) - else: - self.assertEqual(inst.path[key], inst[key], - "Object paths of instance should match for %s"%pkg) - self.assertEqual(pkg.up_rel, inst['Release'], - "Release property should match for %s"%pkg) - self.install_pkg(pkg) - objpath['SoftwareElementState'] = pywbem.Uint16(2) - inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False) - self.assertEqual(inst.path, objpath, - "Object paths should match for %s"%pkg) - - # try to leave out epoch part - if pkg.epoch == "0": - op_no_epoch = objpath.copy() - op_no_epoch["SoftwareElementID"] = rpmcache.make_nevra(pkg.name, - pkg.up_epoch, pkg.up_ver, pkg.up_rel, pkg.arch, "NEVER") - self.assertNotIn(":", op_no_epoch["SoftwareElementID"]) - inst = self.conn.GetInstance( - InstanceName=op_no_epoch, LocalOnly=False) - self.assertIn(inst.path, (objpath, op_no_epoch)) - - @common.mark_dangerous - def test_method_install(self): - """ - Tests Install method invocation. - """ - for pkg in self.pkgdb: - if common.is_installed(pkg.name): - common.remove_pkg(pkg.name) - objpath = self.make_op(pkg, ses=1) - (rval, oparms) = self.conn.InvokeMethod( - MethodName="Install", - ObjectName=objpath) - self.assertEqual(pywbem.Uint32(1), rval, - "Installation of %s should be successful"%pkg) - self.assertEqual(1, len(oparms)) - self.assertTrue(oparms.has_key('Installed')) - objpath['SoftwareElementState'] = pywbem.Uint16(2) - self.assertEqual(oparms['Installed'], objpath, - "Object paths should match for %s"%pkg) - self.assertTrue(common.is_installed(pkg.name), - "Package %s must be installed"%pkg) - (rval, oparms) = self.conn.InvokeMethod( - MethodName="Install", - ObjectName=objpath) - self.assertEqual(pywbem.Uint32(0), rval, - "Installation of %s should fail"%pkg) - self.assertEqual(len(oparms), 1) - self.assertEqual(oparms['Installed'], objpath, - "Object paths should match for %s"%pkg) - - @common.mark_dangerous - def test_method_remove(self): - """ - Tests Remove method invocation. - """ - for pkg in self.pkgdb: - if not common.is_installed(pkg.name): - self.install_pkg(pkg) - objpath = self.make_op(pkg) - (rval, oparms) = self.conn.InvokeMethod( - MethodName="Remove", - ObjectName=objpath) - self.assertEqual(pywbem.Uint16(1), rval, - "Removal of package should succeed"%pkg) - self.assertEqual(0, len(oparms)) - self.assertFalse(common.is_installed(pkg.name), - "Package %s should not be installed"%pkg) - objpath["SoftwareElementState"] = pywbem.Uint16(1) - (rval, oparms) = self.conn.InvokeMethod( - MethodName="Remove", - ObjectName=objpath) - self.assertEqual(pywbem.Uint32(0), rval, - "Removal of %s should fail"%pkg) - self.assertEqual(len(oparms), 0) - -def suite(): - """For unittest loaders.""" - return unittest.TestLoader().loadTestsFromTestCase( - TestSoftwarePackage) - -if __name__ == '__main__': - unittest.main() |