Add unittest for SystemCollection and ProcessorCollection
Change-Id: Ie506b92eedf40f327016ae0ecb052ddd3a4afe53
This commit is contained in:
parent
cb473aeb6d
commit
ec6c7ea66d
@ -3,10 +3,13 @@
|
|||||||
"@odata.id": "/redfish/v1/Systems/System1/Processors",
|
"@odata.id": "/redfish/v1/Systems/System1/Processors",
|
||||||
"@odata.type": "#ProcessorCollection.ProcessorCollection",
|
"@odata.type": "#ProcessorCollection.ProcessorCollection",
|
||||||
"Name": "Processors Collection",
|
"Name": "Processors Collection",
|
||||||
"Members@odata.count": 1,
|
"Members@odata.count": 2,
|
||||||
"Members": [
|
"Members": [
|
||||||
{
|
{
|
||||||
"@odata.id": "/redfish/v1/Systems/System1/Processors/CPU1"
|
"@odata.id": "/redfish/v1/Systems/System1/Processors/CPU1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@odata.id": "/redfish/v1/Systems/System1/Processors/CPU2"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
16
rsd_lib/tests/unit/json_samples/v2_2/system_collection.json
Normal file
16
rsd_lib/tests/unit/json_samples/v2_2/system_collection.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"@odata.context": "/redfish/v1/$metadata#ComputerSystemCollection.ComputerSystemCollection",
|
||||||
|
"@odata.id": "/redfish/v1/Systems",
|
||||||
|
"@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
|
||||||
|
"Name": "Computer System Collection",
|
||||||
|
"Description": "description-as-string",
|
||||||
|
"Members@odata.count": 2,
|
||||||
|
"Members": [
|
||||||
|
{
|
||||||
|
"@odata.id": "/redfish/v1/Systems/System1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@odata.id": "/redfish/v1/Systems/System2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -114,3 +114,47 @@ class ProcessorTestCase(testtools.TestCase):
|
|||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
self.assertIsInstance(self.processor_inst.metrics,
|
self.assertIsInstance(self.processor_inst.metrics,
|
||||||
processor_metrics.ProcessorMetrics)
|
processor_metrics.ProcessorMetrics)
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessorCollectionTestCase(testtools.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(ProcessorCollectionTestCase, self).setUp()
|
||||||
|
self.conn = mock.Mock()
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||||
|
'processor_collection.json', 'r') as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
self.processor_col = processor.ProcessorCollection(
|
||||||
|
self.conn, '/redfish/v1/Systems',
|
||||||
|
redfish_version='1.1.0')
|
||||||
|
|
||||||
|
def test__parse_attributes(self):
|
||||||
|
self.processor_col._parse_attributes()
|
||||||
|
self.assertEqual('1.1.0', self.processor_col.redfish_version)
|
||||||
|
self.assertEqual(('/redfish/v1/Systems/System1/Processors/CPU1',
|
||||||
|
'/redfish/v1/Systems/System1/Processors/CPU2'),
|
||||||
|
self.processor_col.members_identities)
|
||||||
|
|
||||||
|
@mock.patch.object(processor, 'Processor', autospec=True)
|
||||||
|
def test_get_member(self, mock_system):
|
||||||
|
self.processor_col.get_member(
|
||||||
|
'/redfish/v1/Systems/System1/Processors/CPU1')
|
||||||
|
mock_system.assert_called_once_with(
|
||||||
|
self.processor_col._conn,
|
||||||
|
'/redfish/v1/Systems/System1/Processors/CPU1',
|
||||||
|
redfish_version=self.processor_col.redfish_version)
|
||||||
|
|
||||||
|
@mock.patch.object(processor, 'Processor', autospec=True)
|
||||||
|
def test_get_members(self, mock_system):
|
||||||
|
members = self.processor_col.get_members()
|
||||||
|
calls = [
|
||||||
|
mock.call(self.processor_col._conn,
|
||||||
|
'/redfish/v1/Systems/System1/Processors/CPU1',
|
||||||
|
redfish_version=self.processor_col.redfish_version),
|
||||||
|
mock.call(self.processor_col._conn,
|
||||||
|
'/redfish/v1/Systems/System1/Processors/CPU2',
|
||||||
|
redfish_version=self.processor_col.redfish_version)
|
||||||
|
]
|
||||||
|
mock_system.assert_has_calls(calls)
|
||||||
|
self.assertIsInstance(members, list)
|
||||||
|
self.assertEqual(2, len(members))
|
||||||
|
@ -149,3 +149,47 @@ class SystemTestCase(testtools.TestCase):
|
|||||||
# | WHEN & THEN |
|
# | WHEN & THEN |
|
||||||
self.assertIsInstance(self.system_inst.processors,
|
self.assertIsInstance(self.system_inst.processors,
|
||||||
processor.ProcessorCollection)
|
processor.ProcessorCollection)
|
||||||
|
|
||||||
|
|
||||||
|
class SystemCollectionTestCase(testtools.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(SystemCollectionTestCase, self).setUp()
|
||||||
|
self.conn = mock.Mock()
|
||||||
|
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||||
|
'system_collection.json', 'r') as f:
|
||||||
|
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||||
|
self.system_col = system.SystemCollection(
|
||||||
|
self.conn, '/redfish/v1/Systems',
|
||||||
|
redfish_version='1.1.0')
|
||||||
|
|
||||||
|
def test__parse_attributes(self):
|
||||||
|
self.system_col._parse_attributes()
|
||||||
|
self.assertEqual('1.1.0', self.system_col.redfish_version)
|
||||||
|
self.assertEqual(('/redfish/v1/Systems/System1',
|
||||||
|
'/redfish/v1/Systems/System2'),
|
||||||
|
self.system_col.members_identities)
|
||||||
|
|
||||||
|
@mock.patch.object(system, 'System', autospec=True)
|
||||||
|
def test_get_member(self, mock_system):
|
||||||
|
self.system_col.get_member(
|
||||||
|
'/redfish/v1/Systems/System1')
|
||||||
|
mock_system.assert_called_once_with(
|
||||||
|
self.system_col._conn,
|
||||||
|
'/redfish/v1/Systems/System1',
|
||||||
|
redfish_version=self.system_col.redfish_version)
|
||||||
|
|
||||||
|
@mock.patch.object(system, 'System', autospec=True)
|
||||||
|
def test_get_members(self, mock_system):
|
||||||
|
members = self.system_col.get_members()
|
||||||
|
calls = [
|
||||||
|
mock.call(self.system_col._conn,
|
||||||
|
'/redfish/v1/Systems/System1',
|
||||||
|
redfish_version=self.system_col.redfish_version),
|
||||||
|
mock.call(self.system_col._conn,
|
||||||
|
'/redfish/v1/Systems/System2',
|
||||||
|
redfish_version=self.system_col.redfish_version)
|
||||||
|
]
|
||||||
|
mock_system.assert_has_calls(calls)
|
||||||
|
self.assertIsInstance(members, list)
|
||||||
|
self.assertEqual(2, len(members))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user