class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' self._resource.get_all(start=2, count=500, filter=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" self._resource.get(template_id) mock_get.assert_called_once_with(id_or_uri=template_id) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_property(self, mock_get_by): template_property = "name" template_name = "BL460c Gen8 1" self._resource.get_by(template_property, template_name) mock_get_by.assert_called_once_with(template_property, template_name) @mock.patch.object(ResourceClient, 'get_by_name') def test_get_by_name(self, mock_get_by_name): template_name = "BL460c Gen8 1" self._resource.get_by_name(template_name) mock_get_by_name.assert_called_once_with(template_name) @mock.patch.object(ResourceClient, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") expected_template = template.copy() expected_template["type"] = "ServerProfileTemplateV1" self._resource.create(resource=template, timeout=TIMEOUT) mock_create.assert_called_once_with(resource=expected_template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'update') def test_update(self, mock_update): uri = "/rest/server-profile-templates/4ff2327f-7638-4b66-ad9d-283d4940a4ae" template = dict(name="BL460c Gen8 1", macType="Virtual") expected_template = template.copy() expected_template["type"] = "ServerProfileTemplateV1" self._resource.update(resource=template, id_or_uri=uri) mock_update.assert_called_once_with(resource=expected_template, uri=uri) @mock.patch.object(ResourceClient, 'delete') def test_delete(self, mock_delete): template = dict(name="BL460c Gen8 1") self._resource.delete(resource=template, timeout=TIMEOUT) mock_delete.assert_called_once_with(resource=template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'get') def test_get_new_profile(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" expected_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6/new-profile' self._resource.get_new_profile(id_or_uri=template_id) mock_get.assert_called_once_with(id_or_uri=expected_uri)
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) self.uri = "/rest/server-profile-templates/test" self._resource.data = {"uri": self.uri} @mock.patch.object(ResourceHelper, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' scope_uris = 'rest/scopes/cd237b60-09e2-45c4-829e-082e318a6d2a' self._resource.get_all( start=2, count=500, filter=query_filter, sort=sort, scope_uris=scope_uris) mock_get_all.assert_called_once_with( start=2, count=500, filter=query_filter, sort=sort, scope_uris=scope_uris) @mock.patch.object(ResourceHelper, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(template, timeout=TIMEOUT) mock_create.assert_called_once_with( template, None, -1, force=True ) @mock.patch.object(Resource, 'ensure_resource_data') @mock.patch.object(ResourceHelper, 'update') def test_update(self, mock_update, mock_ensure_client): template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(template) template["uri"] = self.uri mock_update.assert_called_once_with(template, self.uri, True, -1) @mock.patch.object(ResourceHelper, 'delete') def test_delete(self, mock_delete): self._resource.delete(timeout=TIMEOUT) mock_delete.assert_called_once_with(self.uri, timeout=TIMEOUT, custom_headers=None, force=False) @mock.patch.object(ResourceHelper, 'do_get') def test_get_new_profile(self, mock_get): expected_uri = '{}/new-profile'.format(self.uri) self._resource.get_new_profile() mock_get.assert_called_once_with(expected_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_transformation(self, mock_get): enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format(**locals()) expected_uri = self.uri + transformation_path self._resource.get_transformation(enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(expected_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_available_networks(self, mock_get): uri = '/rest/server-profile-templates/available-networks?profileTemplateUri={}'.format(self.uri) self._resource.get_available_networks(profileTemplateUri=self.uri) mock_get.assert_called_once_with(uri)
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' self._resource.get_all(start=2, count=500, filter=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" self._resource.get(template_id) mock_get.assert_called_once_with(id_or_uri=template_id) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_property(self, mock_get_by): template_property = "name" template_name = "BL460c Gen8 1" self._resource.get_by(template_property, template_name) mock_get_by.assert_called_once_with(template_property, template_name) @mock.patch.object(ResourceClient, 'get_by_name') def test_get_by_name(self, mock_get_by_name): template_name = "BL460c Gen8 1" self._resource.get_by_name(template_name) mock_get_by_name.assert_called_once_with(template_name) @mock.patch.object(ResourceClient, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(resource=template, timeout=TIMEOUT) mock_create.assert_called_once_with( resource=template, timeout=TIMEOUT, default_values=ServerProfileTemplate.DEFAULT_VALUES) @mock.patch.object(ResourceClient, 'update') def test_update(self, mock_update): uri = "/rest/server-profile-templates/4ff2327f-7638-4b66-ad9d-283d4940a4ae" template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(resource=template, id_or_uri=uri) mock_update.assert_called_once_with( resource=template, uri=uri, default_values=ServerProfileTemplate.DEFAULT_VALUES) @mock.patch.object(ResourceClient, 'delete') def test_delete(self, mock_delete): template = dict(name="BL460c Gen8 1") self._resource.delete(resource=template, timeout=TIMEOUT) mock_delete.assert_called_once_with(resource=template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'get') def test_get_new_profile(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" expected_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6/new-profile' self._resource.get_new_profile(id_or_uri=template_id) mock_get.assert_called_once_with(id_or_uri=expected_uri) @mock.patch.object(ResourceClient, 'get') def test_get_transformation(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format( **locals()) template_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6' expected_uri = template_uri + transformation_path self._resource.get_transformation( id_or_uri=template_id, enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(id_or_uri=expected_uri)
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' self._resource.get_all(start=2, count=500, filter=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" self._resource.get(template_id) mock_get.assert_called_once_with(id_or_uri=template_id) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_property(self, mock_get_by): template_property = "name" template_name = "BL460c Gen8 1" self._resource.get_by(template_property, template_name) mock_get_by.assert_called_once_with(template_property, template_name) @mock.patch.object(ResourceClient, 'get_by_name') def test_get_by_name(self, mock_get_by_name): template_name = "BL460c Gen8 1" self._resource.get_by_name(template_name) mock_get_by_name.assert_called_once_with(template_name) @mock.patch.object(ResourceClient, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(resource=template, timeout=TIMEOUT) mock_create.assert_called_once_with( resource=template, timeout=TIMEOUT, default_values=ServerProfileTemplate.DEFAULT_VALUES ) @mock.patch.object(ResourceClient, 'update') def test_update(self, mock_update): uri = "/rest/server-profile-templates/4ff2327f-7638-4b66-ad9d-283d4940a4ae" template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(resource=template, id_or_uri=uri) mock_update.assert_called_once_with( resource=template, uri=uri, default_values=ServerProfileTemplate.DEFAULT_VALUES ) @mock.patch.object(ResourceClient, 'delete') def test_delete(self, mock_delete): template = dict(name="BL460c Gen8 1") self._resource.delete(resource=template, timeout=TIMEOUT) mock_delete.assert_called_once_with(resource=template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'get') def test_get_new_profile(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" expected_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6/new-profile' self._resource.get_new_profile(id_or_uri=template_id) mock_get.assert_called_once_with(id_or_uri=expected_uri) @mock.patch.object(ResourceClient, 'get') def test_get_transformation(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format(**locals()) template_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6' expected_uri = template_uri + transformation_path self._resource.get_transformation(id_or_uri=template_id, enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(id_or_uri=expected_uri)