コード例 #1
0
 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'])
コード例 #2
0
ファイル: test_chassis.py プロジェクト: bharathshetty4/ironic
 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']))
コード例 #3
0
 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'])
コード例 #4
0
ファイル: test_chassis.py プロジェクト: zdj6373/ironic
 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'])
コード例 #5
0
 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'])
コード例 #6
0
 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])
コード例 #7
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)
コード例 #8
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)
コード例 #9
0
 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)])
コード例 #10
0
 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])
コード例 #11
0
 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)])
コード例 #12
0
ファイル: test_chassis.py プロジェクト: namnx228/ironic
 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'])
コード例 #13
0
ファイル: test_chassis.py プロジェクト: xsc27/ironic
    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)
コード例 #14
0
    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)])
コード例 #15
0
    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)])
コード例 #16
0
 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'])
コード例 #17
0
 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'])
コード例 #18
0
 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)
コード例 #19
0
 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)