Skip to content

Commit

Permalink
extend test_wbemconnectionmock
Browse files Browse the repository at this point in the history
  • Loading branch information
KSchopmeyer committed May 17, 2018
1 parent 755e425 commit ef6c9d0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 44 deletions.
92 changes: 52 additions & 40 deletions testsuite/test_wbemconnection_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,22 @@ def tst_class():
Builds and returns a single class: CIM_Foo that to be used as a
test class for the mock class tests.
"""
pkey = {'Description': CIMQualifier('Description', 'property')}
qkey = {'Key': CIMQualifier('Key', True)}
dkey = {'Description': CIMQualifier('Description', 'blah blah')}
qkey = {'Key': CIMQualifier('Key', True, propagated=False)}
dkey = {'Description': CIMQualifier('Description', 'class description',
propagated=False)}
pkey = {'Description': CIMQualifier('Description', 'property',
propagated=False)}

c = CIMClass(
'CIM_Foo', qualifiers=dkey,
properties={'InstanceID':
CIMProperty('InstanceID', None, qualifiers=qkey,
type='string', class_origin='CIM_Foo',
propagated=False)},
methods={'Delete': CIMMethod('Delete', 'uint32', qualifiers=dkey,
methods={'Delete': CIMMethod('Delete', 'uint32', qualifiers=pkey,
class_origin='CIM_Foo',
propagated=False),
'Fuzzy': CIMMethod('Fuzzy', 'string', qualifiers=dkey,
'Fuzzy': CIMMethod('Fuzzy', 'string', qualifiers=pkey,
class_origin='CIM_Foo',
propagated=False)})
return c
Expand All @@ -185,26 +187,30 @@ def tst_classes(tst_class):
qkey = {'Key': CIMQualifier('Key', True, propagated=False)}
dkey = {'Description': CIMQualifier('Description', 'blah blah',
propagated=False)}
pkey = {'Description': CIMQualifier('Description', 'property')}
pkey = {'Description': CIMQualifier('Description', 'property',
propagated=False)}

c2 = CIMClass(
'CIM_Foo_sub', superclass='CIM_Foo', qualifiers=dkey,
properties={'cimfoo_sub':
CIMProperty('cimfoo_sub', None, type='string',
qualifiers=pkey,
class_origin='CIM_Foo_sub',
propagated=False)})

c3 = CIMClass(
'CIM_Foo_sub2', superclass='CIM_Foo', qualifiers=dkey,
properties={'cimfoo_sub2':
CIMProperty('cimfoo_sub2', None, type='string',
qualifiers=pkey,
class_origin='CIM_Foo_sub2',
propagated=False)})

c4 = CIMClass(
'CIM_Foo_sub_sub', superclass='CIM_Foo_sub', qualifiers=dkey,
properties={'cimfoo_sub_sub':
CIMProperty('cimfoo_sub_sub', None, type='string',
qualifiers=pkey,
class_origin='CIM_Foo_sub_sub',
propagated=False)})

Expand All @@ -214,7 +220,7 @@ def tst_classes(tst_class):
CIMProperty('InstanceID', None, qualifiers=qkey,
type='string', class_origin='CIM_Foo_nokey',
propagated=False),
CIMProperty('cimfoo', None, qualifiers=None,
CIMProperty('cimfoo', None, qualifiers=pkey,
type='string', class_origin='CIM_Foo_nokey',
propagated=False),
])
Expand Down Expand Up @@ -1503,35 +1509,40 @@ def test_getclass_iqico(self, conn, tst_classes, ns, cn, iq, ico):
assert tst_class is not None

conn.add_cimobjects(tst_classes, namespace=ns)
if iq is None:
cl = conn.GetClass(cn, namespace=ns, IncludeQualifiers=iq,
LocalOnly=True)
else:
cl = conn.GetClass(cn, namespace=ns, IncludeQualifiers=iq,
LocalOnly=True)

cl.path = None

c_tst = tst_class.copy()
# test with LocalOnly True to get just the local properties
cl = conn.GetClass(cn, namespace=ns, IncludeQualifiers=iq,
LocalOnly=True, IncludeClassOrigin=ico)

# remove all qualifiers and class_origins and test for equality
if not iq:
c_tst.qualifiers = NocaseDict()

for prop in c_tst.properties:
c_tst.properties[prop].qualifiers = NocaseDict()
for method in c_tst.methods:
c_tst.methods[method].qualifiers = NocaseDict()
for param in c_tst.methods[method].parameters:
c_tst.methods[method].parameters[param].qualifiers = \
tst_class.qualifiers = NocaseDict()
for prop in cl.properties:
tst_class.properties[prop].qualifiers = NocaseDict()
for method in cl.methods:
tst_class.methods[method].qualifiers = NocaseDict()
for param in cl.methods[method].parameters:
tst_class.methods[method].parameters[param].qualifiers = \
NocaseDict()

# remove class origin if ico = None. Else test
if not ico:
for prop in c_tst.properties:
c_tst.properties[prop].class_origin = None
for method in c_tst.methods:
c_tst.methods[method].class_origin = None
for prop in tst_class.properties:
tst_class.properties[prop].class_origin = None
for method in tst_class.methods:
tst_class.methods[method].class_origin = None
else:
# The following is a test
for pname in tst_class.properties:
tst_class.properties[pname].class_origin == tst_class.classname
for mname in tst_class.methods:
tst_class.methods[mname].class_origin == tst_class.classname

# Test the modified tst_class against the returned class
tst_ns = ns if ns else conn.default_namespace
tst_class.path = CIMClassName(cn, host='FakedUrl', namespace=tst_ns)

assert(cl == c_tst)
assert(cl == tst_class)

@pytest.mark.parametrize(
"ns", [None, 'root/blah'])
Expand All @@ -1556,18 +1567,24 @@ def test_getclass_lo(self, conn, ns, tst_classes, cn, lo, pl_exp):
"""
conn.add_cimobjects(tst_classes, namespace=ns)

if not lo:
cl = conn.GetClass(cn, namespace=ns, LocalOnly=lo,
IncludeQualifiers=True)
else:
cl = conn.GetClass(cn, namespace=ns, LocalOnly=lo,
IncludeQualifiers=True)
cl = conn.GetClass(cn, namespace=ns, LocalOnly=lo,
IncludeQualifiers=True,
IncludeClassOrigin=True)

assert cl.classname == cn
assert len(cl.properties) == len(pl_exp)
rtn_props = cl.properties.keys()
assert set(rtn_props) == set(pl_exp)

tst_cls_dict = dict()
for cl in tst_classes:
tst_cls_dict[cl.classname] = cl
for pname, prop in cl.properties.items():
prop_class_origin = prop.class_origin
class_prop_qualifiers = \
tst_cls_dict[prop_class_origin].properties[pname].qualifiers
assert prop.qualifiers == class_prop_qualifiers

@pytest.mark.parametrize(
"ns", [None, 'root/blah'])
# property list, expected properties in response
Expand Down Expand Up @@ -1916,14 +1933,9 @@ def test_createclass(self, conn, pre_tst_classes, tcl, tst_qualifiers_mof,
# and propagated set
for cl in tst_classes:
if cl.classname == exp_rtn_cl:
if cl != rtn_class:
print('cl==rtn_class\n%r\n%r' % (cl, rtn_class))
assert cl == rtn_class
else:
if isinstance(tcl, CIMClass):
if tcl != rtn_class:
print('\ntcl==rtn_class\n%r\n%r' % (tcl, rtn_class))
# tcl does not have propagated False on override qualifier
assert tcl == rtn_class
else:
assert set(rtn_class.properties) == \
Expand Down
8 changes: 4 additions & 4 deletions testsuite/test_wbemserverclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ class TestServerClass(BaseMethodsForTests):
def build_obj_mgr_inst(self, conn, namespace, system_name,
object_manager_name):
"""
Build an instance of the CIM_ObjectManager Class
Build the Faked Class Repository and build the core instances for
this test.
"""
omdict = {"SystemCreationClassName": "CIM_ComputerSystem",
"CreationClassName": "CIM_ObjectManager",
"SystemName": system_name,
"Name": object_manager_name,
"ElementName": "PywbemMock",
"Description": "PywbemMock CIM Server Version 2.15.0 "
"Released"}
"ElementName": "Pegasus",
"Description": "Pegasus CIM Server Version 2.15.0 Released"}

ominst = self.inst_from_classname(conn, "CIM_ObjectManager",
namespace=namespace,
Expand Down

0 comments on commit ef6c9d0

Please sign in to comment.