diff --git a/docs/changes.rst b/docs/changes.rst index fe2f1f145..685729662 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -193,11 +193,11 @@ Enhancements of the generated MOF to be more consistent with the CIM Schema MOF. * Added new methods `CIMInstanceName.to_wbem_uri()` and - `CIMClassName.to_wbem_uri()` that return the path as a WBEM URI compliant to - DSP0207, in order to make the conversion explicit instead of relying - on the string conversion methods. The string conversion methods are still - supported, but see the fix to make them compliant to DSP0207 (added as part - of fixing issue #928). + `CIMClassName.to_wbem_uri()` that return the path as a WBEM URI string that + conforms to untyped WBEM URIs as defined in DSP0207. + The `CIMInstanceName.__str__()` and `CIMClassName.__str__()` methods still + return the same WBEM URI string they previously did, but that is a historical + format close to but not conformant to DSP0207 (issues #928, #943). * Improved the way CIM-XML parsing errors are handled, by providing the original traceback information when re-raising a low-level exception diff --git a/pywbem/cim_http.py b/pywbem/cim_http.py index 4f3f8a8e9..e83f40800 100644 --- a/pywbem/cim_http.py +++ b/pywbem/cim_http.py @@ -966,11 +966,11 @@ def get_cimobject_header(obj): # Local class path if isinstance(obj, CIMClassName): - return obj.to_wbem_uri(omit_local_slash=True) + return obj.to_wbem_uri(format='cimobject') # Local instance path if isinstance(obj, CIMInstanceName): - return obj.to_wbem_uri(omit_local_slash=True) + return obj.to_wbem_uri(format='cimobject') raise TypeError("Invalid object type %s to generate CIMObject header " "value from" % type(obj)) diff --git a/pywbem/cim_obj.py b/pywbem/cim_obj.py index b066921f5..12078a60f 100644 --- a/pywbem/cim_obj.py +++ b/pywbem/cim_obj.py @@ -1686,11 +1686,31 @@ def __hash__(self): def __str__(self): """ - Return the untyped WBEM URI of the CIM instance path represented - by the :class:`~pywbem.CIMInstanceName` object, as returned by + Return a WBEM URI string of the CIM instance path represented by the + :class:`~pywbem.CIMInstanceName` object. + + The returned WBEM URI string is in the historical format returned by :meth:`~pywbem.CIMInstanceName.to_wbem_uri`. + + For new code, it is recommended that the standard format is used; it + is returned by :meth:`~pywbem.CIMInstanceName.to_wbem_uri` as the + default format. + + Examples (for the historical format): + + * With authority and namespace:: + + //acme.com/cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1" + + * Without authority but with namespace:: + + cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1" + + * Without authority and without namespace:: + + CIM_RegisteredProfile.InstanceID="acme.1" """ - return self.to_wbem_uri() + return self.to_wbem_uri(format='historical') def __repr__(self): """ @@ -2146,13 +2166,12 @@ def from_wbem_uri(wbem_uri): return obj - def to_wbem_uri(self, omit_local_slash=False): + def to_wbem_uri(self, format='standard'): """ Return the untyped WBEM URI of the CIM instance path represented by the :class:`~pywbem.CIMInstanceName` object. - The returned WBEM URI is consistent with :term:`DSP0207`, and contains - its components as follows: + The returned WBEM URI contains its components as follows: * it does not contain a namespace type (URI scheme). * it contains an authority component according to the @@ -2169,17 +2188,34 @@ def to_wbem_uri(self, omit_local_slash=False): Parameters: - omit_local_slash (bool): Omit the leading slash in "local" WBEM URIs - (that is, in WBEM URIs without authority component). Note that - :term:`DSP0207` requires a leading slash in "local" WBEM URIs. + format (:term:`string`): Format for the generated WBEM URI string, + using one of the following values: - Examples: + * ``"standard"`` - Standard format that is conformant to untyped + WBEM URIs for instance paths defined in :term:`DSP0207`. + + * ``"cimobject"`` - Format for the `CIMObject` header field in + CIM-XML messages for representing instance paths (used + internally, see :term:`DSP0200`). + + * ``"historical"`` - Historical format for WBEM URIs (used by + :meth:`~pywbem.CIMInstanceName.__str__`; should not be used by + new code). The historical format has the following differences to + the standard format: + + - If the authority component is not present, the slash after the + authority is also omitted. In the standard format, that slash + is always present. + + - If the namespace component is not present, the colon after the + namespace is also omitted. In the standard format, that colon + is always present. + + Examples for the standard format: * With authority and namespace:: - //jdd:test@acme.com:5989/cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1" //acme.com/cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1" - //acme.com/root/cimv2:CIM_ComputerSystem.CreationClassName="ACME_CS",Name="sys1" * Without authority but with namespace:: @@ -2188,11 +2224,11 @@ def to_wbem_uri(self, omit_local_slash=False): * Without authority and without namespace:: /:CIM_RegisteredProfile.InstanceID="acme.1" - /:CIM_SubProfile.Main="/:CIM_RegisteredProfile.InstanceID=\"acme.1\"",Sub="/:CIM_RegisteredProfile.InstanceID=\"acme.2\"" Returns: - :term:`unicode string`: Untyped WBEM URI of the CIM instance path. + :term:`unicode string`: Untyped WBEM URI of the CIM instance path, + in the specified format. Raises: TypeError: Invalid type in keybindings @@ -2204,13 +2240,15 @@ def to_wbem_uri(self, omit_local_slash=False): ret.append('//') ret.append(self.host) - if self.host is not None or not omit_local_slash: + if self.host is not None or format == 'standard': ret.append('/') if self.namespace is not None: ret.append(self.namespace) - ret.append(':') + if self.namespace is not None or format in ('standard', 'cimobject'): + ret.append(':') + ret.append(self.classname) ret.append('.') @@ -3095,11 +3133,36 @@ def __hash__(self): def __str__(self): """ - Return the untyped WBEM URI of the CIM class path represented by the - :class:`~pywbem.CIMClassName` object, as returned by + Return a WBEM URI string of the CIM class path represented by the + :class:`~pywbem.CIMClassName` object. + + The returned WBEM URI string is in the historical format returned by :meth:`~pywbem.CIMClassName.to_wbem_uri`. + + For new code, it is recommended that the standard format is used; it + is returned by :meth:`~pywbem.CIMClassName.to_wbem_uri` as the default + format. + + If you want to access the class name, use the + :attr:`~pywbem.CIMClassName.classname` attribute, instead of relying + on the coincidence that the historical format of a WBEM URI without + authority and namespace happens to be the class name. + + Examples (for the historical format): + + * With authority and namespace:: + + //acme.com/cimv2/test:CIM_RegisteredProfile + + * Without authority but with namespace:: + + cimv2/test:CIM_RegisteredProfile + + * Without authority and without namespace:: + + CIM_RegisteredProfile """ - return self.to_wbem_uri() + return self.to_wbem_uri(format='historical') def __repr__(self): """ @@ -3241,35 +3304,52 @@ def from_wbem_uri(wbem_uri): return obj - def to_wbem_uri(self, omit_local_slash=False): + def to_wbem_uri(self, format='standard'): """ - Return the untyped WBEM URI of the CIM class path represented - by the :class:`~pywbem.CIMClassName` object. + Return the untyped WBEM URI of the CIM class path represented by the + :class:`~pywbem.CIMClassName` object. - The returned WBEM URI is consistent with :term:`DSP0207`, and contains - its components as follows: + The returned WBEM URI contains its components as follows: * it does not contain a namespace type (URI scheme). * it contains an authority component according to the - :attr:`~pywbem.CIMInstanceName.host` attribute, if that is not + :attr:`~pywbem.CIMClassName.host` attribute, if that is not `None`. Othwerise, it does not contain the authority component. * it contains a namespace component according to the - :attr:`~pywbem.CIMInstanceName.namespace` attribute, if that is not + :attr:`~pywbem.CIMClassName.namespace` attribute, if that is not `None`. Othwerise, it does not contain the namespace component. * it contains a class name component according to the - :attr:`~pywbem.CIMInstanceName.classname` attribute. + :attr:`~pywbem.CIMClassName.classname` attribute. Parameters: - omit_local_slash (bool): Omit the leading slash in "local" WBEM URIs - (that is, in WBEM URIs without authority component). Note that - :term:`DSP0207` requires a leading slash in "local" WBEM URIs. + format (:term:`string`): Format for the generated WBEM URI string, + using one of the following values: - Examples: + * ``"standard"`` - Standard format that is conformant to untyped + WBEM URIs for class paths defined in :term:`DSP0207`. + + * ``"cimobject"`` - Format for the `CIMObject` header field in + CIM-XML messages for representing class paths (used + internally, see :term:`DSP0200`). + + * ``"historical"`` - Historical format for WBEM URIs (used by + :meth:`~pywbem.CIMClassName.__str__`; should not be used by + new code). The historical format has the following differences to + the standard format: + + - If the authority component is not present, the slash after the + authority is also omitted. In the standard format, that slash + is always present. + + - If the namespace component is not present, the colon after the + namespace is also omitted. In the standard format, that colon + is always present. + + Examples for the standard format: * With authority and namespace:: - //jdd:test@acme.com:5989/cimv2/test:CIM_RegisteredProfile //acme.com/cimv2/test:CIM_RegisteredProfile * Without authority but with namespace:: @@ -3282,7 +3362,8 @@ def to_wbem_uri(self, omit_local_slash=False): Returns: - :term:`unicode string`: Untyped WBEM URI of the CIM class path. + :term:`unicode string`: Untyped WBEM URI of the CIM class path, + in the specified format. """ ret = [] @@ -3291,13 +3372,15 @@ def to_wbem_uri(self, omit_local_slash=False): ret.append('//') ret.append(self.host) - if self.host is not None or not omit_local_slash: + if self.host is not None or format == 'standard': ret.append('/') if self.namespace is not None: ret.append(self.namespace) - ret.append(':') + if self.namespace is not None or format in ('standard', 'cimobject'): + ret.append(':') + ret.append(self.classname) return _ensure_unicode(''.join(ret)) diff --git a/testsuite/test_cim_obj.py b/testsuite/test_cim_obj.py index b1a46e117..09a34510c 100755 --- a/testsuite/test_cim_obj.py +++ b/testsuite/test_cim_obj.py @@ -2205,11 +2205,6 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): Test CIMInstanceName.to_wbem_uri() and .__str__(). """ - omit_local_slash = [ - # Fixture for omit_local_slash arg of CIMInstanceName.to_wbem_uri(). - True, False - ] - func_name = [ # Fixture for function to be tested 'to_wbem_uri', '__str__' @@ -2221,31 +2216,79 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): # * desc: Short testcase description. # * attrs: Dict of input attributes for the CIMInstanceName object # to be tested. + # * format: Format for to_wbem_uri(): one of 'standard', 'cimobject', + # 'historical'. # * exp_result: Expected WBEM URI string, if expected to succeed. # Exception type, if expected to fail. # * exp_warn_type: Expected warning type. # None, if no warning expected. # * condition: Condition for testcase to run. ( - "all components, normal case", + "all components, standard format", dict( classname=u'CIM_Foo', keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=u'10.11.12.13:5989'), + 'standard', '//10.11.12.13:5989/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), ( - "no authority", + "all components, cimobject format", + dict( + classname=u'CIM_Foo', + keybindings=NocaseDict(k1=u'v1'), + namespace=u'root/cimv2', + host=u'10.11.12.13:5989'), + 'cimobject', + '//10.11.12.13:5989/root/cimv2:CIM_Foo.k1="v1"', + None, CHECK_0_12_0 + ), + ( + "all components, historical format", + dict( + classname=u'CIM_Foo', + keybindings=NocaseDict(k1=u'v1'), + namespace=u'root/cimv2', + host=u'10.11.12.13:5989'), + 'historical', + '//10.11.12.13:5989/root/cimv2:CIM_Foo.k1="v1"', + None, CHECK_0_12_0 + ), + ( + "no authority, standard format", dict( classname=u'CIM_Foo', keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=None), + 'standard', '/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), + ( + "no authority, cimobject format", + dict( + classname=u'CIM_Foo', + keybindings=NocaseDict(k1=u'v1'), + namespace=u'root/cimv2', + host=None), + 'cimobject', + 'root/cimv2:CIM_Foo.k1="v1"', + None, CHECK_0_12_0 + ), + ( + "no authority, historical format", + dict( + classname=u'CIM_Foo', + keybindings=NocaseDict(k1=u'v1'), + namespace=u'root/cimv2', + host=None), + 'historical', + 'root/cimv2:CIM_Foo.k1="v1"', + None, CHECK_0_12_0 + ), ( "authority with user:password", dict( @@ -2253,6 +2296,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=u'jdd:test@10.11.12.13:5989'), + 'standard', '//jdd:test@10.11.12.13:5989/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2263,6 +2307,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=u'jdd@10.11.12.13:5989'), + 'standard', '//jdd@10.11.12.13:5989/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2273,6 +2318,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=u'10.11.12.13'), + 'standard', '//10.11.12.13/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2283,6 +2329,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=u'[10:11:12:13]'), + 'standard', '//[10:11:12:13]/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2293,6 +2340,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=u'[10:11:12:13]:5989'), + 'standard', '//[10:11:12:13]:5989/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2303,19 +2351,43 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2', host=None), + 'standard', '/root/cimv2:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), ( - "local WBEM URI with only class name", + "local WBEM URI with only class name, standard format", dict( classname=u'CIM_Foo', keybindings=NocaseDict(k1=u'v1'), namespace=None, host=None), + 'standard', '/:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), + ( + "local WBEM URI with only class name, cimobject format", + dict( + classname=u'CIM_Foo', + keybindings=NocaseDict(k1=u'v1'), + namespace=None, + host=None), + 'cimobject', + ':CIM_Foo.k1="v1"', + None, CHECK_0_12_0 + ), + ( + "local WBEM URI with only class name, historical format", + dict( + classname=u'CIM_Foo', + keybindings=NocaseDict(k1=u'v1'), + namespace=None, + host=None), + 'historical', + 'CIM_Foo.k1="v1"', + None, CHECK_0_12_0 + ), ( "local WBEM URI with namespace that has only one component", dict( @@ -2323,6 +2395,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root', host=None), + 'standard', '/root:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2333,6 +2406,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=u'v1'), namespace=u'root/cimv2/test', host=None), + 'standard', '/root/cimv2/test:CIM_Foo.k1="v1"', None, CHECK_0_12_0 ), @@ -2343,6 +2417,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=False, k2=True), namespace=u'n', host=None), + 'standard', '/n:C.k1=FALSE,k2=TRUE', None, CHECK_0_12_0 ), @@ -2358,6 +2433,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): klong=9223372036854775808), namespace=u'n', host=None), + 'standard', '/n:C.k1=0,k2=-1,k3=-32769,k4=42,k5=42,' 'klong=9223372036854775808,' 'kmax32=4294967295,' @@ -2378,6 +2454,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): kmin64=2.2250738585072014E-308), namespace=u'n', host=None), + 'standard', '/n:C.k1=0.0,k2=-0.1,k3=0.1,k4=3.14,k5=4.0,' 'kmax32=3.402823466e+38,' 'kmax64=1.7976931348623157e+308,' @@ -2392,6 +2469,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=float('inf')), namespace=u'n', host=None), + 'standard', '/n:C.k1=inf', None, CHECK_0_12_0 ), @@ -2402,6 +2480,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=float('-inf')), namespace=u'n', host=None), + 'standard', '/n:C.k1=-inf', None, CHECK_0_12_0 ), @@ -2412,6 +2491,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1=float('nan')), namespace=u'n', host=None), + 'standard', '/n:C.k1=nan', None, False # float('nan') does not compare equal to itself ), @@ -2423,6 +2503,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): k5='\\', k6='\\"', k7="'"), namespace=u'n', host=None), + 'standard', '/n:C.k1="",k2="a",k3="42",k4="\\\x22",' 'k5="\\\\",k6="\\\\\\\x22",k7="\x27"', None, CHECK_0_12_0 @@ -2434,6 +2515,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1='k2=42,k3=3'), namespace=u'n', host=None), + 'standard', r'/n:C.k1="k2=42,k3=3"', None, CHECK_0_12_0 ), @@ -2444,6 +2526,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): keybindings=NocaseDict(k1='a', k2='1', k3='"', k4="'", k5='\\'), namespace=u'n', host=None), + 'standard', '/n:C.k1="a",k2="1",k3="\\"",k4="\'",k5="\\\\"', None, CHECK_0_12_0 ), @@ -2455,6 +2538,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): k1=CIMDateTime('19980125133015.123456-300')), namespace=u'n', host=None), + 'standard', '/n:C.k1="19980125133015.123456-300"', None, CHECK_0_12_0 ), @@ -2466,6 +2550,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): k1=CIMDateTime('12345678133015.123456:000')), namespace=u'n', host=None), + 'standard', '/n:C.k1="12345678133015.123456:000"', None, CHECK_0_12_0 ), @@ -2481,6 +2566,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): ), namespace=u'n1', host=None), + 'standard', '/n1:C1.k1="/n2:C2.k2=1"', None, CHECK_0_12_0 ), @@ -2496,6 +2582,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): ), namespace=u'n1', host=None), + 'standard', r'/n1:C1.k1="/n2:C2.k2=\"v2\""', None, CHECK_0_12_0 ), @@ -2518,6 +2605,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): ), namespace=u'n1', host=None), + 'standard', r'/n1:C1.k1="/n2:C2.k2=\"/n3:C3.k3=3\""', None, CHECK_0_12_0 ), @@ -2541,6 +2629,7 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): ), namespace=u'n1', host=None), + 'standard', r'/n1:C1.k1="/n2:C2.k2=\"/n3:C3.k3=\\\"v3\\\"\""', None, CHECK_0_12_0 ), @@ -2550,14 +2639,11 @@ class Test_CIMInstanceName_to_wbem_uri_str(object): "func_name", func_name) @pytest.mark.parametrize( - "omit_local_slash", - omit_local_slash) - @pytest.mark.parametrize( - "desc, attrs, exp_result, exp_warn_type, condition", + "desc, attrs, format, exp_result, exp_warn_type, condition", testcases) def test_CIMInstanceName_to_wbem_uri_str( - self, desc, attrs, exp_result, exp_warn_type, condition, - omit_local_slash, func_name): + self, desc, attrs, format, exp_result, exp_warn_type, condition, + func_name): """All test cases for CIMInstanceName.to_wbem_uri() and .__str__().""" if not condition: @@ -2576,10 +2662,12 @@ def test_CIMInstanceName_to_wbem_uri_str( func = getattr(obj, func_name) if func_name == 'to_wbem_uri': - func_kwargs = dict(omit_local_slash=omit_local_slash) + func_kwargs = dict(format=format) if func_name == '__str__': + if format != 'historical': + pytest.skip("Not testing CIMInstanceName.__str__() with " + "format: %r" % format) func_kwargs = dict() - omit_local_slash = False if condition == 'pdb': import pdb @@ -2615,11 +2703,6 @@ def test_CIMInstanceName_to_wbem_uri_str( if exp_uri: assert isinstance(uri, six.text_type) - - if omit_local_slash and obj.host is None: - assert exp_uri[0] == '/' - exp_uri = exp_uri[1:] - assert uri == exp_uri @@ -9323,11 +9406,6 @@ class Test_CIMClassName_to_wbem_uri_str(object): Test CIMClassName.to_wbem_uri() and .__str__(). """ - omit_local_slash = [ - # Fixture for omit_local_slash arg of CIMClassName.to_wbem_uri(). - True, False - ] - func_name = [ # Fixture for function to be tested 'to_wbem_uri', '__str__' @@ -9339,35 +9417,80 @@ class Test_CIMClassName_to_wbem_uri_str(object): # * desc: Short testcase description. # * attrs: Dict of input attributes for the CIMClassName object # to be tested. + # * format: Format for to_wbem_uri(): one of 'standard', 'cimobject', + # 'historical'. # * exp_result: Expected WBEM URI string, if expected to succeed. # Exception type, if expected to fail. # * exp_warn_type: Expected warning type. # None, if no warning expected. # * condition: Condition for testcase to run. ( - "all components, normal case", + "all components, standard format", dict( classname=u'CIM_Foo', namespace=u'root/cimv2', host=u'10.11.12.13:5989'), + 'standard', '//10.11.12.13:5989/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), ( - "no authority", + "all components, cimobject format", + dict( + classname=u'CIM_Foo', + namespace=u'root/cimv2', + host=u'10.11.12.13:5989'), + 'cimobject', + '//10.11.12.13:5989/root/cimv2:CIM_Foo', + None, CHECK_0_12_0 + ), + ( + "all components, historical format", + dict( + classname=u'CIM_Foo', + namespace=u'root/cimv2', + host=u'10.11.12.13:5989'), + 'historical', + '//10.11.12.13:5989/root/cimv2:CIM_Foo', + None, CHECK_0_12_0 + ), + ( + "no authority, standard format", dict( classname=u'CIM_Foo', namespace=u'root/cimv2', host=None), + 'standard', '/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), + ( + "no authority, cimobject format", + dict( + classname=u'CIM_Foo', + namespace=u'root/cimv2', + host=None), + 'cimobject', + 'root/cimv2:CIM_Foo', + None, CHECK_0_12_0 + ), + ( + "no authority, historical format", + dict( + classname=u'CIM_Foo', + namespace=u'root/cimv2', + host=None), + 'historical', + 'root/cimv2:CIM_Foo', + None, CHECK_0_12_0 + ), ( "authority with user:password", dict( classname=u'CIM_Foo', namespace=u'root/cimv2', host=u'jdd:test@10.11.12.13:5989'), + 'standard', '//jdd:test@10.11.12.13:5989/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), @@ -9377,6 +9500,7 @@ class Test_CIMClassName_to_wbem_uri_str(object): classname=u'CIM_Foo', namespace=u'root/cimv2', host=u'jdd@10.11.12.13:5989'), + 'standard', '//jdd@10.11.12.13:5989/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), @@ -9386,6 +9510,7 @@ class Test_CIMClassName_to_wbem_uri_str(object): classname=u'CIM_Foo', namespace=u'root/cimv2', host=u'10.11.12.13'), + 'standard', '//10.11.12.13/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), @@ -9395,6 +9520,7 @@ class Test_CIMClassName_to_wbem_uri_str(object): classname=u'CIM_Foo', namespace=u'root/cimv2', host=u'[10:11:12:13]'), + 'standard', '//[10:11:12:13]/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), @@ -9404,6 +9530,7 @@ class Test_CIMClassName_to_wbem_uri_str(object): classname=u'CIM_Foo', namespace=u'root/cimv2', host=u'[10:11:12:13]:5989'), + 'standard', '//[10:11:12:13]:5989/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), @@ -9413,24 +9540,47 @@ class Test_CIMClassName_to_wbem_uri_str(object): classname=u'CIM_Foo', namespace=u'root/cimv2', host=None), + 'standard', '/root/cimv2:CIM_Foo', None, CHECK_0_12_0 ), ( - "local WBEM URI with only class name", + "local WBEM URI with only class name, standard format", dict( classname=u'CIM_Foo', namespace=None, host=None), + 'standard', '/:CIM_Foo', None, CHECK_0_12_0 ), + ( + "local WBEM URI with only class name, cimobject format", + dict( + classname=u'CIM_Foo', + namespace=None, + host=None), + 'cimobject', + ':CIM_Foo', + None, CHECK_0_12_0 + ), + ( + "local WBEM URI with only class name, historical format", + dict( + classname=u'CIM_Foo', + namespace=None, + host=None), + 'historical', + 'CIM_Foo', + None, CHECK_0_12_0 + ), ( "local WBEM URI with namespace that has only one component", dict( classname=u'CIM_Foo', namespace=u'root', host=None), + 'standard', '/root:CIM_Foo', None, CHECK_0_12_0 ), @@ -9440,6 +9590,7 @@ class Test_CIMClassName_to_wbem_uri_str(object): classname=u'CIM_Foo', namespace=u'root/cimv2/test', host=None), + 'standard', '/root/cimv2/test:CIM_Foo', None, CHECK_0_12_0 ), @@ -9449,14 +9600,11 @@ class Test_CIMClassName_to_wbem_uri_str(object): "func_name", func_name) @pytest.mark.parametrize( - "omit_local_slash", - omit_local_slash) - @pytest.mark.parametrize( - "desc, attrs, exp_result, exp_warn_type, condition", + "desc, attrs, format, exp_result, exp_warn_type, condition", testcases) def test_CIMClassName_to_wbem_uri_str( - self, desc, attrs, exp_result, exp_warn_type, condition, - omit_local_slash, func_name): + self, desc, format, attrs, exp_result, exp_warn_type, condition, + func_name): """All test cases for CIMClassName.to_wbem_uri() and .__str__().""" if not condition: @@ -9475,10 +9623,12 @@ def test_CIMClassName_to_wbem_uri_str( func = getattr(obj, func_name) if func_name == 'to_wbem_uri': - func_kwargs = dict(omit_local_slash=omit_local_slash) + func_kwargs = dict(format=format) if func_name == '__str__': + if format != 'historical': + pytest.skip("Not testing CIMClassName.__str__() with " + "format: %r" % format) func_kwargs = dict() - omit_local_slash = False if condition == 'pdb': import pdb @@ -9514,11 +9664,6 @@ def test_CIMClassName_to_wbem_uri_str( if exp_uri: assert isinstance(uri, six.text_type) - - if omit_local_slash and obj.host is None: - assert exp_uri[0] == '/' - exp_uri = exp_uri[1:] - assert uri == exp_uri