summaryrefslogtreecommitdiffstats
path: root/src/software/test/test_software_package.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/test/test_software_package.py')
-rwxr-xr-xsrc/software/test/test_software_package.py121
1 files changed, 75 insertions, 46 deletions
diff --git a/src/software/test/test_software_package.py b/src/software/test/test_software_package.py
index f6fdf9c..d0144ca 100755
--- a/src/software/test/test_software_package.py
+++ b/src/software/test/test_software_package.py
@@ -18,91 +18,120 @@
#
# Authors: Michal Minar <miminar@redhat.com>
#
+"""
+Unit tests for LMI_SoftwareInstalledPackage provider.
+"""
-from common import *
+import pywbem
+import unittest
-class TestSoftwarePackage(SoftwareBaseTestCase):
+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, name, epoch, ver, rel, arch, ses=2):
- op = self.op.copy()
- op["Name"] = name
- op["SoftwareElementID"] = make_nevra(
- name, epoch, ver, rel, arch, "ALWAYS")
- op["SoftwareElementState"] = pywbem.Uint16(ses)
- op["TargetOperatingSystem"] = pywbem.Uint16(36)
- op["Version"] = ver
- return op
+ 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):
- for pkg in packages:
- if is_installed(pkg.name):
- remove_pkg(pkg.name)
- op = self.make_op(pkg.name, pkg.epoch, pkg.ver,
- pkg.rel, pkg.arch, 1)
- inst = self.conn.GetInstance(InstanceName=op, LocalOnly=False)
- self.assertEqual(inst.path, op)
+ """
+ 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)
for key in self.KEYS:
self.assertTrue(inst.properties.has_key(key))
self.assertEqual(inst.path[key], inst[key])
- self.assertEqual(inst['Release'], pkg.rel)
- install_pkg(*pkg[:5])
- op['SoftwareElementState'] = pywbem.Uint16(2)
- inst = self.conn.GetInstance(InstanceName=op, LocalOnly=False)
- self.assertEqual(inst.path, op)
+ self.assertEqual(inst['Release'], pkg.up_rel)
+ common.install_pkg(pkg)
+ objpath['SoftwareElementState'] = pywbem.Uint16(2)
+ inst = self.conn.GetInstance(InstanceName=objpath, LocalOnly=False)
+ self.assertEqual(inst.path, objpath)
# try to leave out epoch part
if pkg.epoch == "0":
- op_no_epoch = op.copy()
- op_no_epoch["SoftwareElementID"] = make_nevra(pkg.name, pkg.epoch,
- pkg.ver, pkg.rel, pkg.arch, "NEVER")
+ 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, (op, op_no_epoch))
+ self.assertIn(inst.path, (objpath, op_no_epoch))
+ @common.mark_dangerous
def test_method_install(self):
- for pkg in packages:
- if is_installed(pkg.name):
- remove_pkg(pkg.name)
- op = self.make_op(pkg.name, pkg.epoch, pkg.ver,
- pkg.rel, pkg.arch, 1)
+ """
+ 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=op)
+ ObjectName=objpath)
self.assertEqual(rval, pywbem.Uint32(1))
self.assertEqual(len(oparms), 1)
self.assertTrue(oparms.has_key('Installed'))
- op['SoftwareElementState'] = pywbem.Uint16(2)
- self.assertEqual(oparms['Installed'], op)
- self.assertTrue(is_installed(pkg.name))
+ objpath['SoftwareElementState'] = pywbem.Uint16(2)
+ self.assertEqual(oparms['Installed'], objpath)
+ self.assertTrue(common.is_installed(pkg.name))
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Install",
- ObjectName=op)
+ ObjectName=objpath)
self.assertEqual(rval, pywbem.Uint32(0))
self.assertEqual(len(oparms), 1)
- self.assertEqual(oparms['Installed'], op)
+ self.assertEqual(oparms['Installed'], objpath)
+ @common.mark_dangerous
def test_method_remove(self):
- for pkg in packages:
- if not is_installed(pkg.name):
- install_pkg(*pkg[:5])
- op = self.make_op(*pkg[:5])
+ """
+ Tests Remove method invocation.
+ """
+ for pkg in self.pkgdb:
+ if not common.is_installed(pkg.name):
+ common.install_pkg(pkg)
+ objpath = self.make_op(pkg)
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Remove",
- ObjectName=op)
+ ObjectName=objpath)
self.assertEqual(rval, pywbem.Uint16(1))
self.assertEqual(len(oparms), 0)
- self.assertFalse(is_installed(pkg.name))
- op["SoftwareElementState"] = pywbem.Uint16(1)
+ self.assertFalse(common.is_installed(pkg.name))
+ objpath["SoftwareElementState"] = pywbem.Uint16(1)
(rval, oparms) = self.conn.InvokeMethod(
MethodName="Remove",
- ObjectName=op)
+ ObjectName=objpath)
self.assertEqual(rval, pywbem.Uint32(0))
self.assertEqual(len(oparms), 0)
+def suite():
+ """For unittest loaders."""
+ return unittest.TestLoader().loadTestsFromTestCase(
+ TestSoftwarePackage)
+
if __name__ == '__main__':
unittest.main()