Fix wrong default JsonDataReader() argument
It expect to use new JsonDataReader() instance as default argument in function call, but it will be only created once when the function is defined, and the same object is used in each successive call. It does not work as expected. So Use default argument None to signal that Reader was provided. Change-Id: I8b659132e4699c2f9a1b8109869c3a6c1b3ca096
This commit is contained in:
parent
798458d444
commit
fc311f9ddb
|
@ -313,7 +313,7 @@ class ResourceBase(object):
|
|||
connector,
|
||||
path='',
|
||||
redfish_version=None,
|
||||
reader=JsonDataReader()):
|
||||
reader=None):
|
||||
"""A class representing the base of any Redfish resource
|
||||
|
||||
Invokes the ``refresh()`` method of resource for the first
|
||||
|
@ -322,8 +322,7 @@ class ResourceBase(object):
|
|||
:param path: sub-URI path to the resource.
|
||||
:param redfish_version: The version of Redfish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
:param reader: Reader to use to fetch JSON data. Defaults to
|
||||
JsonDataReader
|
||||
:param reader: Reader to use to fetch JSON data.
|
||||
"""
|
||||
self._conn = connector
|
||||
self._path = path
|
||||
|
@ -334,6 +333,8 @@ class ResourceBase(object):
|
|||
# attribute values are fetched.
|
||||
self._is_stale = True
|
||||
|
||||
if reader is None:
|
||||
reader = JsonDataReader()
|
||||
reader.set_connection(connector, path)
|
||||
self._reader = reader
|
||||
|
||||
|
|
|
@ -129,6 +129,15 @@ class ResourceBaseTestCase(base.TestCase):
|
|||
reader=resource_base.
|
||||
JsonArchiveReader('Test.2.0.json'))
|
||||
|
||||
def test_init_default_reader(self):
|
||||
resource_a = BaseResource(connector=self.conn)
|
||||
resource_b = BaseResource(connector=self.conn)
|
||||
|
||||
self.assertIsInstance(resource_a._reader, resource_base.JsonDataReader)
|
||||
self.assertIsInstance(resource_b._reader, resource_base.JsonDataReader)
|
||||
|
||||
self.assertIsNot(resource_a._reader, resource_b._reader)
|
||||
|
||||
def test__parse_attributes(self):
|
||||
for oem_vendor in self.base_resource2.oem_vendors:
|
||||
self.assertTrue(oem_vendor in ('Contoso', 'EID_412_ASB_123'))
|
||||
|
|
Loading…
Reference in New Issue