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") 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) @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)