def test_policy_disallow_create(self): bdict = apiutils.node_post_data(name='node_example_A') self._common_policy_check("node:create", self.post_json, '/nodes', bdict, expect_errors=True)
def test_create_node_doesnt_contain_id(self): with mock.patch.object(self.dbapi, 'create_node', wraps=self.dbapi.create_node) as cn_mock: node_dict = apiutils.node_post_data(image_id='Ubuntu') response = self.post_json('/nodes', node_dict) self.assertEqual(node_dict['image_id'], response.json['image_id']) cn_mock.assert_called_once_with(mock.ANY) # Check that 'id' is not in first arg of positional args self.assertNotIn('id', cn_mock.call_args[0][0])
def test_create_node_generate_uuid(self): node_dict = apiutils.node_post_data() del node_dict['uuid'] response = self.post_json('/nodes', node_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) self.assertEqual(node_dict['image_id'], response.json['image_id']) self.assertTrue(utils.is_uuid_like(response.json['uuid']))
def test_create_node_generate_uuid(self): node_dict = apiutils.node_post_data() del node_dict['uuid'] response = self.post_json('/nodes', node_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) self.assertEqual(node_dict['image_id'], response.json['image_id']) self.assertTrue(utils.is_uuid_like(response.json['uuid']))
def test_create_node_set_project_id_and_user_id(self): with mock.patch.object(self.dbapi, 'create_node', wraps=self.dbapi.create_node) as cc_mock: node_dict = apiutils.node_post_data() self.post_json('/nodes', node_dict) cc_mock.assert_called_once_with(mock.ANY) self.assertEqual(self.context.project_id, cc_mock.call_args[0][0]['project_id']) self.assertEqual(self.context.user_id, cc_mock.call_args[0][0]['user_id'])
def test_create_node(self, mock_utcnow): node_dict = apiutils.node_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json('/nodes', node_dict) self.assertEqual('application/json', response.content_type) self.assertEqual(201, response.status_int) # Check location header self.assertIsNotNone(response.location) expected_location = '/v1/nodes/%s' % node_dict['uuid'] self.assertEqual(expected_location, urlparse.urlparse(response.location).path) self.assertEqual(node_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_policy_disallow_create(self): bdict = apiutils.node_post_data(name='node_example_A') self._common_policy_check( "node:create", self.post_json, '/nodes', bdict)
def test_node_init(self): node_dict = apiutils.node_post_data() del node_dict['image_id'] node = api_node.Node(**node_dict) self.assertEqual(wtypes.Unset, node.image_id)