Skip to content

Commit

Permalink
Add testclient tests and add cim_obj tests
Browse files Browse the repository at this point in the history
Adds tests for create, delete, modify class, setqualifier,
deletequalifier, and execquery to mock tests.

adds unittests to test_cim_obj.py. This was part of getting
the mock tests running for setqualifier, etc.

Adds tests for create, delete, modify class and set/delte
qualifierDeclaration to run_cim_operation.py

Corrects error in CIM_operations where recorder was being called with
incorrect type.

Also added pullinstances yaml so there are mock tests now for
all operations..
Also fixes issues found in some of the other tests, primarily
where someof them did not mark the start of some tests with -
  • Loading branch information
KSchopmeyer committed Dec 28, 2016
1 parent 0a05bc9 commit ed2269a
Show file tree
Hide file tree
Showing 13 changed files with 3,439 additions and 63 deletions.
2 changes: 1 addition & 1 deletion pywbem/cim_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7880,7 +7880,7 @@ def DeleteQualifier(self, QualifierName, namespace=None, **extra):
if self.operation_recorder:
self.operation_recorder.reset()
self.operation_recorder.stage_pywbem_args(
method='SetQualifier',
method='DeleteQualifier',
QualifierName=QualifierName,
namespace=namespace,
**extra)
Expand Down
549 changes: 513 additions & 36 deletions testsuite/run_cim_operations.py

Large diffs are not rendered by default.

163 changes: 156 additions & 7 deletions testsuite/test_cim_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

from pywbem import cim_obj, cim_types
from pywbem import CIMInstance, CIMInstanceName, CIMClass, CIMClassName, \
CIMProperty, CIMMethod, CIMParameter, CIMQualifier, Uint8, Uint16, Uint32, \
CIMProperty, CIMMethod, CIMParameter, CIMQualifier, \
CIMQualifierDeclaration, Uint8, Uint16, Uint32, \
Uint64, Sint8, Sint16, Sint32, Sint64, Real32, Real64, CIMDateTime
from pywbem.cim_obj import NocaseDict

Expand Down Expand Up @@ -236,7 +237,7 @@ def runtest_dict(self, obj, exp_dict):
invalid_propname = 'Cheepy'
self.assertEqual(obj.get(invalid_propname, default_value),
default_value)
except Exception as exc:
except Exception as exc: # pylint: disable=broad-except
self.fail('%s thrown in exception-free get() when accessing '
'undefined key %s\n'
'Object: %r' %
Expand Down Expand Up @@ -2265,7 +2266,80 @@ def test_all(self):
root_elem_CIMQualifier)


# TODO Add testcases for CIMClassName
class InitCIMClassName(unittest.TestCase):

def test_all(self):

# Initialise with classname, superclass

CIMClassName('CIM_Foo')
CIMClassName('CIM_Foo', host='fred', namespace='root/blah')


class CopyCIMClassName(unittest.TestCase):

def test_all(self):

c = CIMClassName('CIM_Foo')
co = c.copy()
self.assertEqual(c, co)
co.classname = 'CIM_Bar'
self.assertEqual(c.classname, 'CIM_Foo')
self.assertEqual(co.host, None)
self.assertEqual(co.namespace, None)

c = CIMClassName('CIM_Foo', host='fred', namespace='root/blah')
co = c.copy()
self.assertEqual(c, co)
self.assertEqual(c.classname, 'CIM_Foo')
self.assertEqual(co.host, 'fred')
self.assertEqual(co.namespace, 'root/blah')


class CIMClassNameAttrs(unittest.TestCase):

def test_all(self):

obj = CIMClassName('CIM_Foo')

self.assertEqual(obj.classname, 'CIM_Foo')
self.assertEqual(obj.host, None)
self.assertEqual(obj.namespace, None)

obj = CIMClassName('CIM_Foo', host='fred', namespace='root/cimv2')

self.assertEqual(obj.classname, 'CIM_Foo')
self.assertEqual(obj.host, 'fred')
self.assertEqual(obj.namespace, 'root/cimv2')


class CIMClassNameEquality(unittest.TestCase):

def test_all(self):

self.assertEqual(CIMClassName('CIM_Foo'), CIMClassName('CIM_Foo'))
self.assertEqual(CIMClassName('CIM_Foo'), CIMClassName('cim_foo'))


class CIMClassNameString(unittest.TestCase, RegexpMixin):

def test_all(self):

s = str(CIMClassName('CIM_Foo'))
self.assertRegexpContains(s, 'CIM_Foo')


class CIMClassNameToXML(ValidateTest):

def test_all(self):
root_elem_CIMClassName = 'CLASSNAME'

self.validate(CIMClassName('CIM_Foo'),
root_elem_CIMClassName)

self.validate(CIMClassName('CIM_Foo', host='fred',
namespace='root/blah'),
'CLASSPATH')


class InitCIMClass(unittest.TestCase):
Expand Down Expand Up @@ -3153,20 +3227,95 @@ def test_all(self):


class InitCIMQualifierDeclaration(unittest.TestCase):
pass
"""Test construction of CIMQualifierDeclarations."""

def test_all(self):
"""Test the constructor options."""

CIMQualifierDeclaration('FooQualDecl', 'uint32')

CIMQualifierDeclaration('FooQualDecl', 'string', value='my string')

CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4,
overridable=True, tosubclass=True,
toinstance=True, translatable=False)
scopes = {'CLASS': False, 'ANY': False, 'ASSOCIATION': False}
CIMQualifierDeclaration('FooQualDecl', 'uint64', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False)


class CopyCIMQualifierDeclaration(unittest.TestCase):
pass

def test_all(self):

qd = CIMQualifierDeclaration('FooQualDecl', 'uint32')
c = qd.copy()
self.assertEqual(qd, c)

scopes = {'CLASS': False, 'ANY': False, 'ASSOCIATION': False}
qd = CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False)
c = qd.copy()
self.assertEqual(qd, c)


class CIMQualifierDeclarationAttrs(unittest.TestCase):
pass


class CIMQualifierDeclarationEquality(unittest.TestCase):
# pylint: disable=invalid-name
pass

def test_all(self):
self.assertEqual(CIMQualifierDeclaration('FooQualDecl', 'uint32'),
CIMQualifierDeclaration('FooQualDecl', 'uint32'))

self.assertNotEqual(
CIMQualifierDeclaration('FooQualDecl1', 'uint32'),
CIMQualifierDeclaration('FooQualDecl2', 'uint32'))

scopes = {'CLASS': False, 'ANY': False, 'ASSOCIATION': False}
self.assertEqual(
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False),
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False))
self.assertNotEqual(
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False),
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=5, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False))
self.assertNotEqual(
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4,
overridable=True, tosubclass=True,
toinstance=True, translatable=False),
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False))
self.assertNotEqual(
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=True, tosubclass=True,
toinstance=True, translatable=False),
CIMQualifierDeclaration('FooQualDecl', 'string', is_array=True,
array_size=4, scopes=scopes,
overridable=False, tosubclass=True,
toinstance=True, translatable=False))
# TODO ks Dec 16. Add more equality tests.


class CIMQualifierDeclarationCompare(unittest.TestCase):
Expand Down
6 changes: 4 additions & 2 deletions testsuite/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def sort_children(root, sort_elements):
# Sort sibling elements with <first> tag by its <second> attribute
("IPARAMVALUE", "NAME"),
("PROPERTY", "NAME"),
("PROPERTY.ARRAY", "NAME"),
("PARAMETER", "NAME"),
("KEYBINDING", "NAME"),
]
Expand Down Expand Up @@ -769,6 +770,8 @@ def runtestcase(self, testcase):
print("- Expected pull_result tuple size: %s" %
len(exp_pull_result_obj))
print("- Actual result len: %s" % len(result))
# print('result %s exp %s' % ((result, ),
# (exp_pull_result_obj, )))
raise AssertionError("PyWBEM CIM result type is not"
" as expected.")
# eos is required result
Expand Down Expand Up @@ -885,8 +888,7 @@ def result_tuple(value, tc_name):


if __name__ == '__main__':
print('args %s len %s type %s' % (sys.argv, len(sys.argv), type(sys.argv)))

"""Main function of test_client. Calls unittest"""
# NonDocumented option to run a single testcase if that testcase name
# is listed on the cmd line.
if len(sys.argv) > 1:
Expand Down
Loading

0 comments on commit ed2269a

Please sign in to comment.