def test_create_service_no_id_in_manifest(self): sdict = apiutils.service_post_data() sdict["manifest"] = {} response = self.post_json("/services", sdict, expect_errors=True) self.assertEqual("application/json", response.content_type) self.assertEqual(400, response.status_int) self.assertTrue(response.json["error_message"])
def test_create_service_no_id_in_manifest(self): sdict = apiutils.service_post_data() sdict['manifest'] = {} response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) self.assertTrue(response.json['error_message'])
def test_create_service_doesnt_contain_id(self): with mock.patch.object(self.dbapi, "create_service", wraps=self.dbapi.create_service) as cc_mock: sdict = apiutils.service_post_data() self.post_json("/services", sdict) cc_mock.assert_called_once_with(mock.ANY) # Check that 'id' is not in first arg of positional args self.assertNotIn("id", cc_mock.call_args[0][0])
def test_create_service_generate_uuid(self): sdict = apiutils.service_post_data() del sdict['uuid'] response = self.post_json('/services', sdict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) self.assertTrue(utils.is_uuid_like(response.json['uuid']))
def test_create_service_doesnt_contain_id(self): with mock.patch.object(self.dbapi, 'create_service', wraps=self.dbapi.create_service) as cc_mock: sdict = apiutils.service_post_data() self.post_json('/services', sdict) cc_mock.assert_called_once_with(mock.ANY) # Check that 'id' is not in first arg of positional args self.assertNotIn('id', cc_mock.call_args[0][0])
def test_policy_disallow_create(self): bay = obj_utils.create_test_bay(self.context) pdict = apiutils.service_post_data(bay_uuid=bay.uuid) self._common_policy_check('service:create', self.post_json, '/services', pdict, expect_errors=True)
def test_create_service_generate_uuid(self, mock_service_create): sdict = apiutils.service_post_data() del sdict['uuid'] mock_service_create.return_value = self.service_obj response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) self.assertTrue(utils.is_uuid_like(response.json['uuid']))
def test_create_service_generate_uuid(self, mock_service_create): sdict = apiutils.service_post_data() del sdict["uuid"] mock_service_create.return_value = self.service_obj response = self.post_json("/services", sdict, expect_errors=True) self.assertEqual("application/json", response.content_type) self.assertEqual(201, response.status_int) self.assertTrue(utils.is_uuid_like(response.json["uuid"]))
def test_create_service_set_project_id_and_user_id(self): sdict = apiutils.service_post_data() def _simulate_rpc_service_create(service): self.assertEqual(service.project_id, self.context.project_id) self.assertEqual(service.user_id, self.context.user_id) return service self.mock_service_create.side_effect = _simulate_rpc_service_create self.post_json('/services', sdict)
def test_create_service(self, mock_service_create, mock_utcnow): sdict = apiutils.service_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time mock_service_create.return_value = self.service_obj response = self.post_json("/services", sdict) self.assertEqual("application/json", response.content_type) self.assertEqual(201, response.status_int) # Check location header self.assertIsNotNone(response.location) expected_location = "/v1/services/%s" % sdict["uuid"] self.assertEqual(expected_location, urlparse.urlparse(response.location).path) self.assertEqual(sdict["uuid"], response.json["uuid"]) self.assertNotIn("updated_at", response.json.keys)
def test_create_service(self, mock_service_create, mock_utcnow): sdict = apiutils.service_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time mock_service_create.return_value = self.service_obj response = self.post_json('/services', sdict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) # Check location header self.assertIsNotNone(response.location) expected_location = '/v1/services/%s' % sdict['uuid'] self.assertEqual(expected_location, urlparse.urlparse(response.location).path) self.assertEqual(sdict['uuid'], response.json['uuid']) self.assertNotIn('updated_at', response.json.keys)
def test_create_service(self, mock_utcnow): sdict = apiutils.service_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json('/services', sdict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) # Check location header self.assertIsNotNone(response.location) expected_location = '/v1/services/%s' % sdict['uuid'] self.assertEqual(urlparse.urlparse(response.location).path, expected_location) self.assertEqual(sdict['uuid'], response.json['uuid']) self.assertNotIn('updated_at', response.json.keys) return_created_at = timeutils.parse_isotime( response.json['created_at']).replace(tzinfo=None) self.assertEqual(test_time, return_created_at)
def test_service_init(self): service_dict = apiutils.service_post_data(bay_uuid=None) del service_dict['uuid'] service = api_service.Service(**service_dict) self.assertEqual(wtypes.Unset, service.uuid)
def test_policy_disallow_create(self): bay = obj_utils.create_test_bay(self.context) pdict = apiutils.service_post_data(bay_uuid=bay.uuid) self._common_policy_check( 'service:create', self.post_json, '/services', pdict, expect_errors=True)
def test_create_service_doesnt_contain_id(self, mock_service_create): sdict = apiutils.service_post_data() mock_service_create.return_value = self.service_obj response = self.post_json('/services', sdict) self.assertEqual('application/json', response.content_type)
def test_policy_disallow_create(self): pdict = apiutils.service_post_data() self._common_policy_check( 'service:create', self.post_json, '/services', pdict)
def test_create_service_no_bay_uuid(self): sdict = apiutils.service_post_data() del sdict['bay_uuid'] response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int)
def test_create_service_with_non_existent_bay_uuid(self): sdict = apiutils.service_post_data(bay_uuid=utils.generate_uuid()) response = self.post_json('/services', sdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int) self.assertTrue(response.json['error_message'])