class LogicalInterconnectGroupsTest(unittest.TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._lig = LogicalInterconnectGroups(self.connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' self._lig.get_all(2, 500, filter, sort) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once_with_default(self, mock_get_all): self._lig.get_all() mock_get_all.assert_called_once_with(0, -1, filter='', sort='') @mock.patch.object(ResourceClient, 'get') def test_get_by_id_called_once(self, mock_get): lig_id = "f0a0a113-ec97-41b4-83ce-d7c92b900e7c" self._lig.get(lig_id) mock_get.assert_called_once_with(lig_id) @mock.patch.object(ResourceClient, 'get') def test_get_by_uri_called_once(self, mock_get): lig_uri = "/rest/logical-interconnect-groups/f0a0a113-ec97-41b4-83ce-d7c92b900e7c" self._lig.get(lig_uri) mock_get.assert_called_once_with(lig_uri) @mock.patch.object(ResourceClient, 'get') def test_get_default_settings_called_once(self, mock_get): lig_settings_uri = "/rest/logical-interconnect-groups/defaultSettings" self._lig.get_default_settings() mock_get.assert_called_once_with(lig_settings_uri) @mock.patch.object(ResourceClient, 'get') def test_get_settings_called_once_when_lig_uri_provided(self, mock_get): lig_uri = "/rest/logical-interconnect-groups/f0a0a113-ec97-41b4-83ce-d7c92b900e7c" lig_settings_uri = "/rest/logical-interconnect-groups/f0a0a113-ec97-41b4-83ce-d7c92b900e7c/settings" self._lig.get_settings(lig_uri) mock_get.assert_called_once_with(lig_settings_uri) @mock.patch.object(ResourceClient, 'get') def test_get_settings_called_once_when_lig_id_provided(self, mock_get): lig_id = "f0a0a113-ec97-41b4-83ce-d7c92b900e7c" lig_settings_uri = "/rest/logical-interconnect-groups/f0a0a113-ec97-41b4-83ce-d7c92b900e7c/settings" self._lig.get_settings(lig_id) mock_get.assert_called_once_with(lig_settings_uri) @mock.patch.object(ResourceClient, 'create') def test_create_called_once_with_defaults(self, mock_create): lig = { "type": "logical-interconnect-groupV3", "name": "OneView Test Logical Interconnect Group", "interconnectMapTemplate": { "interconnectMapEntryTemplates": [] }, "uplinkSets": [], "enclosureType": "C7000", } self._lig.create(lig) mock_create.assert_called_once_with(lig, timeout=-1) @mock.patch.object(ResourceClient, 'create') def test_create_called_once(self, mock_create): lig = { "type": "logical-interconnect-groupV3", "name": "OneView Test Logical Interconnect Group", "interconnectMapTemplate": { "interconnectMapEntryTemplates": [] }, "uplinkSets": [], "enclosureType": "C7000", } self._lig.create(lig, 70) mock_create.assert_called_once_with(lig, timeout=70) @mock.patch.object(ResourceClient, 'update') def test_update_called_once_with_defaults(self, update): lig = { "type": "logical-interconnect-groupV3", "name": "OneView Test Logical Interconnect Group", "interconnectMapTemplate": { "interconnectMapEntryTemplates": [] }, "uplinkSets": [], "enclosureType": "C7000", } self._lig.update(lig) update.assert_called_once_with(lig, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_update_called_once(self, mock_update): lig = { "type": "logical-interconnect-groupV3", "name": "OneView Test Logical Interconnect Group", "interconnectMapTemplate": { "interconnectMapEntryTemplates": [] }, "uplinkSets": [], "enclosureType": "C7000", } self._lig.update(lig, 70) mock_update.assert_called_once_with(lig, timeout=70) @mock.patch.object(ResourceClient, 'delete') def test_delete_called_once(self, mock_delete): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._lig.delete(id, force=True, timeout=50) mock_delete.assert_called_once_with(id, force=True, timeout=50) @mock.patch.object(ResourceClient, 'delete') def test_delete_called_once_with_defaults(self, mock_delete): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._lig.delete(id) mock_delete.assert_called_once_with(id, force=False, timeout=-1) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_called_once(self, mock_get_by): self._lig.get_by("name", "test name") mock_get_by.assert_called_once_with("name", "test name")
class LogicalInterconnectGroupsTest(unittest.TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._lig = LogicalInterconnectGroups(self.connection) self.uri = "/rest/logical-interconnect-groups/f0a0a113-ec97-41b4-83ce-d7c92b900e7c" self._lig.data = {"uri": self.uri} @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' scope_uris = 'TestScope' self._lig.get_all(2, 500, filter, sort, scope_uris) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, scope_uris=scope_uris) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_called_once_with_default(self, mock_get_all): self._lig.get_all() mock_get_all.assert_called_once_with(0, -1, filter='', sort='', scope_uris='') @mock.patch.object(ResourceHelper, 'do_get') def test_get_default_settings_called_once(self, mock_get): lig_settings_uri = "/rest/logical-interconnect-groups/defaultSettings" self._lig.get_default_settings() mock_get.assert_called_once_with(lig_settings_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_settings_called_once_when_lig_uri_provided(self, mock_get): lig_settings_uri = "{}/settings".format(self.uri) self._lig.get_settings() mock_get.assert_called_once_with(lig_settings_uri) @mock.patch.object(ResourceHelper, 'create') def test_create_called_once(self, mock_create): lig = { "type": "logical-interconnect-groupV3", "name": "OneView Test Logical Interconnect Group", "interconnectMapTemplate": { "interconnectMapEntryTemplates": [] }, "uplinkSets": [], "enclosureType": "C7000", } self._lig.create(lig, timeout=70) mock_create.assert_called_once_with(lig, None, 70, None, False) @mock.patch.object(Resource, 'ensure_resource_data') @mock.patch.object(ResourceHelper, 'update') def test_update_called_once(self, mock_update, mock_ensure_client): lig = { "type": "logical-interconnect-groupV3", "name": "OneView Test Logical Interconnect Group", "interconnectMapTemplate": { "interconnectMapEntryTemplates": [] }, "uplinkSets": [], "enclosureType": "C7000", } self._lig.update(lig, timeout=70) lig["uri"] = self.uri mock_update.assert_called_once_with(lig, self.uri, False, 70, None) @mock.patch.object(ResourceHelper, 'delete') def test_delete_called_once(self, mock_delete): self._lig.delete(force=True, timeout=50) mock_delete.assert_called_once_with(self.uri, custom_headers=None, force=True, timeout=50) @mock.patch.object(ResourceHelper, 'delete') def test_delete_called_once_with_defaults(self, mock_delete): self._lig.delete() mock_delete.assert_called_once_with(self.uri, custom_headers=None, force=False, timeout=-1) @mock.patch.object(ResourcePatchMixin, 'patch_request') def test_patch_should_use_user_defined_values(self, mock_patch): mock_patch.return_value = {} self._lig.patch('replace', '/scopeUris', ['rest/fake/scope123'], timeout=-1) mock_patch.assert_called_once_with(self.uri, body=[{'path': '/scopeUris', 'value': ['rest/fake/scope123'], 'op': 'replace'}], custom_headers=None, timeout=-1)