Ejemplo n.º 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"])
Ejemplo n.º 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'])
Ejemplo n.º 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'])
Ejemplo n.º 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])
Ejemplo n.º 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']))
Ejemplo n.º 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])
Ejemplo n.º 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']))
Ejemplo n.º 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)
Ejemplo n.º 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']))
Ejemplo n.º 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"]))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 19
0
 def test_policy_disallow_create(self):
     pdict = apiutils.service_post_data()
     self._common_policy_check(
         'service:create', self.post_json, '/services', pdict)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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'])
Ejemplo n.º 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)
Ejemplo n.º 25
0
 def test_policy_disallow_create(self):
     pdict = apiutils.service_post_data()
     self._common_policy_check(
         'service:create', self.post_json, '/services', pdict)
Ejemplo n.º 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'])