예제 #1
0
 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"])
예제 #2
0
 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'])
예제 #3
0
 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'])
예제 #4
0
 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])
예제 #5
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']))
예제 #6
0
 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])
예제 #7
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']))
예제 #8
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)
예제 #9
0
    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']))
예제 #10
0
    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"]))
예제 #11
0
    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)
예제 #12
0
    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)
예제 #13
0
    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)
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
 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)
예제 #17
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)
예제 #18
0
 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)
예제 #19
0
 def test_policy_disallow_create(self):
     pdict = apiutils.service_post_data()
     self._common_policy_check(
         'service:create', self.post_json, '/services', pdict)
예제 #20
0
 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)
예제 #21
0
 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)
예제 #22
0
 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)
예제 #23
0
 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'])
예제 #24
0
 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)
예제 #25
0
 def test_policy_disallow_create(self):
     pdict = apiutils.service_post_data()
     self._common_policy_check(
         'service:create', self.post_json, '/services', pdict)
예제 #26
0
 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'])