Пример #1
0
 def test_create_rc_no_id_in_manifest(self):
     rc_dict = apiutils.rc_post_data()
     rc_dict['manifest'] = {}
     response = self.post_json('/rcs', rc_dict, 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_policy_disallow_create(self):
     bay = obj_utils.create_test_bay(self.context)
     pdict = apiutils.rc_post_data(bay_uuid=bay.uuid)
     self._common_policy_check('rc:create',
                               self.post_json,
                               '/rcs',
                               pdict,
                               expect_errors=True)
Пример #3
0
    def test_create_rc_generate_uuid(self):
        rc_dict = apiutils.rc_post_data()
        del rc_dict['uuid']

        response = self.post_json('/rcs', rc_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(rc_dict['images'], response.json['images'])
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
    def test_create_rc_generate_uuid(self):
        rc_dict = apiutils.rc_post_data()
        del rc_dict['uuid']

        response = self.post_json('/rcs', rc_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(rc_dict['images'], response.json['images'])
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
 def test_create_rc_doesnt_contain_id(self):
     with mock.patch.object(self.dbapi, 'create_rc',
                            wraps=self.dbapi.create_rc) as cc_mock:
         rc_dict = apiutils.rc_post_data()
         response = self.post_json('/rcs', rc_dict)
         self.assertEqual(rc_dict['images'], response.json['images'])
         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])
Пример #6
0
 def test_create_rc_generate_uuid(self, mock_rc_create):
     rc_dict = apiutils.rc_post_data()
     del rc_dict['uuid']
     mock_rc_create.return_value = self.rc_obj
     response = self.post_json('/rcs', rc_dict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(201, response.status_int)
     self.assertEqual(rc_dict['images'], response.json['images'])
     self.assertTrue(utils.is_uuid_like(response.json['uuid']))
Пример #7
0
 def test_create_rc_doesnt_contain_id(self):
     with mock.patch.object(self.dbapi,
                            'create_rc',
                            wraps=self.dbapi.create_rc) as cc_mock:
         rc_dict = apiutils.rc_post_data()
         response = self.post_json('/rcs', rc_dict)
         self.assertEqual(rc_dict['images'], response.json['images'])
         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])
Пример #8
0
    def test_create_rc_set_project_id_and_user_id(self):
        rc_dict = apiutils.rc_post_data()

        def _simulate_rpc_rc_create(rc):
            self.assertEqual(rc.project_id, self.context.project_id)
            self.assertEqual(rc.user_id, self.context.user_id)
            return rc
        self.mock_rc_create.side_effect = _simulate_rpc_rc_create

        self.post_json('/rcs', rc_dict)
Пример #9
0
    def test_create_rc(self, mock_rc_create, mock_utcnow):
        rc_dict = apiutils.rc_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        mock_rc_create.return_value = self.rc_obj
        response = self.post_json('/rcs', rc_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/rcs/%s' % rc_dict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(rc_dict['uuid'], response.json['uuid'])
Пример #10
0
    def test_create_rc(self, mock_utcnow):
        rc_dict = apiutils.rc_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/rcs', rc_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/rcs/%s' % rc_dict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(rc_dict['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_create_rc(self, mock_utcnow):
        rc_dict = apiutils.rc_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/rcs', rc_dict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/rcs/%s' % rc_dict['uuid']
        self.assertEqual(urlparse.urlparse(response.location).path,
                         expected_location)
        self.assertEqual(rc_dict['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)
Пример #12
0
 def test_policy_disallow_create(self):
     bay = obj_utils.create_test_bay(self.context)
     pdict = apiutils.rc_post_data(bay_uuid=bay.uuid)
     self._common_policy_check(
         'rc:create', self.post_json, '/rcs', pdict, expect_errors=True)
Пример #13
0
 def test_create_rc_with_non_existent_bay_uuid(self):
     rc_dict = apiutils.rc_post_data(bay_uuid=utils.generate_uuid())
     response = self.post_json('/rcs', rc_dict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(400, response.status_int)
     self.assertTrue(response.json['error_message'])
Пример #14
0
 def test_create_rc_no_bay_uuid(self):
     rc_dict = apiutils.rc_post_data()
     del rc_dict['bay_uuid']
     response = self.post_json('/rcs', rc_dict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(400, response.status_int)
Пример #15
0
 def test_rc_init(self):
     rc_dict = apiutils.rc_post_data(bay_uuid=None)
     del rc_dict['images']
     rc = api_rc.ReplicationController(**rc_dict)
     self.assertEqual(wtypes.Unset, rc.images)
Пример #16
0
 def test_policy_disallow_create(self):
     pdict = apiutils.rc_post_data()
     self._common_policy_check(
         'rc:create', self.post_json, '/rcs', pdict)
Пример #17
0
 def test_policy_disallow_create(self):
     pdict = apiutils.rc_post_data()
     self._common_policy_check('rc:create', self.post_json, '/rcs', pdict)