def test_create_chassis_valid_extra(self): cdict = apiutils.chassis_post_data(extra={'str': 'foo', 'int': 123, 'float': 0.1, 'bool': True, 'list': [1, 2], 'none': None, 'dict': {'cat': 'meow'}}) self.post_json('/chassis', cdict) result = self.get_json('/chassis/%s' % cdict['uuid']) self.assertEqual(cdict['extra'], result['extra'])
def test_create_chassis_generate_uuid(self): cdict = apiutils.chassis_post_data() del cdict['uuid'] self.post_json('/chassis', cdict) result = self.get_json('/chassis') self.assertEqual(cdict['description'], result['chassis'][0]['description']) self.assertTrue(uuidutils.is_uuid_like(result['chassis'][0]['uuid']))
def test_create_chassis_invalid_description(self): descr = 1334 valid_error_message = 'Value should be string' cdict = apiutils.chassis_post_data(description=descr) response = self.post_json('/chassis', cdict, expect_errors=True) self.assertEqual(http_client.BAD_REQUEST, response.status_int) self.assertEqual('application/json', response.content_type) self.assertIn(valid_error_message, response.json['error_message'])
def test_create_chassis_toolong_description(self): descr = 'a' * 256 valid_error_message = ('Value should have a maximum character ' 'requirement of 255') cdict = apiutils.chassis_post_data(description=descr) response = self.post_json('/chassis', cdict, expect_errors=True) self.assertEqual(http_client.BAD_REQUEST, response.status_int) self.assertEqual('application/json', response.content_type) self.assertIn(valid_error_message, response.json['error_message'])
def test_create_chassis_doesnt_contain_id(self): with mock.patch.object(self.dbapi, 'create_chassis', wraps=self.dbapi.create_chassis) as cc_mock: cdict = apiutils.chassis_post_data(extra={'foo': 123}) self.post_json('/chassis', cdict) result = self.get_json('/chassis/%s' % cdict['uuid']) self.assertEqual(cdict['extra'], result['extra']) 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_chassis_generate_uuid(self, mock_warning, mock_exception): cdict = apiutils.chassis_post_data() del cdict['uuid'] self.post_json('/chassis', cdict) result = self.get_json('/chassis') self.assertEqual(cdict['description'], result['chassis'][0]['description']) self.assertTrue(uuidutils.is_uuid_like(result['chassis'][0]['uuid'])) self.assertFalse(mock_warning.called) self.assertFalse(mock_exception.called)
def test_create_chassis_error(self, mock_save, mock_notify): mock_save.side_effect = Exception() cdict = apiutils.chassis_post_data() self.post_json('/chassis', cdict, expect_errors=True) mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'create', obj_fields.NotificationLevel.INFO, obj_fields.NotificationStatus.START), mock.call(mock.ANY, mock.ANY, 'create', obj_fields.NotificationLevel.ERROR, obj_fields.NotificationStatus.ERROR)])
def test_create_chassis_valid_extra(self): cdict = apiutils.chassis_post_data( extra={ 'str': 'foo', 'int': 123, 'float': 0.1, 'bool': True, 'list': [1, 2], 'none': None, 'dict': { 'cat': 'meow' } }) self.post_json('/chassis', cdict) result = self.get_json('/chassis/%s' % cdict['uuid']) self.assertEqual(cdict['extra'], result['extra'])
def test_create_chassis(self, mock_utcnow): cdict = apiutils.chassis_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json('/chassis', cdict) self.assertEqual(http_client.CREATED, response.status_int) result = self.get_json('/chassis/%s' % cdict['uuid']) self.assertEqual(cdict['uuid'], result['uuid']) self.assertFalse(result['updated_at']) return_created_at = timeutils.parse_isotime( result['created_at']).replace(tzinfo=None) self.assertEqual(test_time, return_created_at) # Check location header self.assertIsNotNone(response.location) expected_location = '/v1/chassis/%s' % cdict['uuid'] self.assertEqual(urlparse.urlparse(response.location).path, expected_location)
def test_create_chassis(self, mock_utcnow, mock_notify): cdict = apiutils.chassis_post_data() test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time response = self.post_json('/chassis', cdict) self.assertEqual(http_client.CREATED, response.status_int) result = self.get_json('/chassis/%s' % cdict['uuid']) self.assertEqual(cdict['uuid'], result['uuid']) self.assertFalse(result['updated_at']) return_created_at = timeutils.parse_isotime( result['created_at']).replace(tzinfo=None) self.assertEqual(test_time, return_created_at) # Check location header self.assertIsNotNone(response.location) expected_location = '/v1/chassis/%s' % cdict['uuid'] self.assertEqual(urlparse.urlparse(response.location).path, expected_location) mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'create', obj_fields.NotificationLevel.INFO, obj_fields.NotificationStatus.START), mock.call(mock.ANY, mock.ANY, 'create', obj_fields.NotificationLevel.INFO, obj_fields.NotificationStatus.END)])
def test_create_chassis_unicode_description(self): descr = u'\u0430\u043c\u043e' cdict = apiutils.chassis_post_data(description=descr) self.post_json('/chassis', cdict) result = self.get_json('/chassis/%s' % cdict['uuid']) self.assertEqual(descr, result['description'])
def test_chassis_init(self): chassis_dict = apiutils.chassis_post_data() del chassis_dict['description'] chassis = api_chassis.Chassis(**chassis_dict) self.assertEqual(wtypes.Unset, chassis.description)