Fix order of arguments in assertEqual
Some tests incorrectly used the order assertEqual(observed, expected). The correct order expected by testtools is assertEqual(expected, observed). Change-Id: Idbb127147df5acc03287b6a7c1f8d24a37fd663e Closes-Bug: #1259292
This commit is contained in:
parent
9e26f79292
commit
3fdac0da7d
|
@ -34,20 +34,20 @@ class TestACL(api.APITest):
|
||||||
|
|
||||||
def test_non_authenticated(self):
|
def test_non_authenticated(self):
|
||||||
response = self.get_json(self.path, expect_errors=True)
|
response = self.get_json(self.path, expect_errors=True)
|
||||||
self.assertEqual(response.status_int, 401)
|
self.assertEqual(401, response.status_int)
|
||||||
|
|
||||||
def test_authenticated(self):
|
def test_authenticated(self):
|
||||||
response = self.get_json(self.path,
|
response = self.get_json(self.path,
|
||||||
headers={'X-Auth-Token': self.ADMIN_TOKEN})
|
headers={'X-Auth-Token': self.ADMIN_TOKEN})
|
||||||
|
|
||||||
self.assertEqual(response, [])
|
self.assertEqual([], response)
|
||||||
|
|
||||||
def test_non_admin(self):
|
def test_non_admin(self):
|
||||||
response = self.get_json(self.path,
|
response = self.get_json(self.path,
|
||||||
headers={'X-Auth-Token': self.MEMBER_TOKEN},
|
headers={'X-Auth-Token': self.MEMBER_TOKEN},
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
|
|
||||||
self.assertEqual(response.status_int, 403)
|
self.assertEqual(403, response.status_int)
|
||||||
|
|
||||||
def test_non_admin_with_admin_header(self):
|
def test_non_admin_with_admin_header(self):
|
||||||
response = self.get_json(self.path,
|
response = self.get_json(self.path,
|
||||||
|
@ -55,4 +55,4 @@ class TestACL(api.APITest):
|
||||||
'X-Roles': 'admin'},
|
'X-Roles': 'admin'},
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
|
|
||||||
self.assertEqual(response.status_int, 403)
|
self.assertEqual(403, response.status_int)
|
||||||
|
|
|
@ -47,5 +47,5 @@ class TestRoot(api.APITest):
|
||||||
response = self.get_json('/bad/path',
|
response = self.get_json('/bad/path',
|
||||||
expect_errors=True,
|
expect_errors=True,
|
||||||
path_prefix='')
|
path_prefix='')
|
||||||
self.assertEqual(response.status_int, 404)
|
self.assertEqual(404, response.status_int)
|
||||||
self.assertEqual(response.content_type, "text/plain")
|
self.assertEqual("text/plain", response.content_type)
|
||||||
|
|
|
@ -142,33 +142,33 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
start_date,
|
start_date,
|
||||||
end_date,
|
end_date,
|
||||||
duration)
|
duration)
|
||||||
self.assertEqual(len(free_periods), 3)
|
self.assertEqual(3, len(free_periods))
|
||||||
self.assertEqual(free_periods[0][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2028-01-01 08:00',
|
||||||
'2028-01-01 08:00')
|
free_periods[0][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[0][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 09:00',
|
||||||
'2030-01-01 09:00')
|
free_periods[0][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[1][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 10:30',
|
||||||
'2030-01-01 10:30')
|
free_periods[1][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[1][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 13:00',
|
||||||
'2030-01-01 13:00')
|
free_periods[1][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[2][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 14:00',
|
||||||
'2030-01-01 14:00')
|
free_periods[2][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[2][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2099-01-01 00:00',
|
||||||
'2099-01-01 00:00')
|
free_periods[2][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
duration = datetime.timedelta(hours=3)
|
duration = datetime.timedelta(hours=3)
|
||||||
free_periods = db_utils.get_free_periods('r1',
|
free_periods = db_utils.get_free_periods('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date,
|
end_date,
|
||||||
duration)
|
duration)
|
||||||
self.assertEqual(len(free_periods), 2)
|
self.assertEqual(2, len(free_periods))
|
||||||
self.assertEqual(free_periods[0][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2028-01-01 08:00',
|
||||||
'2028-01-01 08:00')
|
free_periods[0][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[0][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 09:00',
|
||||||
'2030-01-01 09:00')
|
free_periods[0][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[1][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 14:00',
|
||||||
'2030-01-01 14:00')
|
free_periods[1][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(free_periods[1][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2099-01-01 00:00',
|
||||||
'2099-01-01 00:00')
|
free_periods[1][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
|
|
||||||
def test_get_reserved_periods(self):
|
def test_get_reserved_periods(self):
|
||||||
"""Find the reserved periods."""
|
"""Find the reserved periods."""
|
||||||
|
@ -182,25 +182,25 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
start_date,
|
start_date,
|
||||||
end_date,
|
end_date,
|
||||||
duration)
|
duration)
|
||||||
self.assertEqual(len(reserved_periods), 2)
|
self.assertEqual(2, len(reserved_periods))
|
||||||
self.assertEqual(reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 09:00',
|
||||||
'2030-01-01 09:00')
|
reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 10:30',
|
||||||
'2030-01-01 10:30')
|
reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(reserved_periods[1][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 13:00',
|
||||||
'2030-01-01 13:00')
|
reserved_periods[1][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(reserved_periods[1][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 14:00',
|
||||||
'2030-01-01 14:00')
|
reserved_periods[1][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
duration = datetime.timedelta(hours=3)
|
duration = datetime.timedelta(hours=3)
|
||||||
reserved_periods = db_utils.get_reserved_periods('r1',
|
reserved_periods = db_utils.get_reserved_periods('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date,
|
end_date,
|
||||||
duration)
|
duration)
|
||||||
self.assertEqual(len(reserved_periods), 1)
|
self.assertEqual(1, len(reserved_periods))
|
||||||
self.assertEqual(reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 09:00',
|
||||||
'2030-01-01 09:00')
|
reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'))
|
||||||
self.assertEqual(reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'),
|
self.assertEqual('2030-01-01 14:00',
|
||||||
'2030-01-01 14:00')
|
reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'))
|
||||||
|
|
||||||
def test_availability_time(self):
|
def test_availability_time(self):
|
||||||
"""Find the total availability time."""
|
"""Find the total availability time."""
|
||||||
|
@ -212,7 +212,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
availability_time = db_utils.availability_time('r1',
|
availability_time = db_utils.availability_time('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date)
|
end_date)
|
||||||
self.assertEqual(availability_time.seconds, 0 * 60)
|
self.assertEqual(0 * 60, availability_time.seconds)
|
||||||
start_date = datetime.datetime.strptime('2030-01-01 09:15',
|
start_date = datetime.datetime.strptime('2030-01-01 09:15',
|
||||||
'%Y-%m-%d %H:%M')
|
'%Y-%m-%d %H:%M')
|
||||||
end_date = datetime.datetime.strptime('2030-01-01 13:45',
|
end_date = datetime.datetime.strptime('2030-01-01 13:45',
|
||||||
|
@ -220,7 +220,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
availability_time = db_utils.availability_time('r1',
|
availability_time = db_utils.availability_time('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date)
|
end_date)
|
||||||
self.assertEqual(availability_time.seconds, 150 * 60)
|
self.assertEqual(150 * 60, availability_time.seconds)
|
||||||
start_date = datetime.datetime.strptime('2030-01-01 08:00',
|
start_date = datetime.datetime.strptime('2030-01-01 08:00',
|
||||||
'%Y-%m-%d %H:%M')
|
'%Y-%m-%d %H:%M')
|
||||||
end_date = datetime.datetime.strptime('2030-01-01 15:00',
|
end_date = datetime.datetime.strptime('2030-01-01 15:00',
|
||||||
|
@ -228,7 +228,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
availability_time = db_utils.availability_time('r1',
|
availability_time = db_utils.availability_time('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date)
|
end_date)
|
||||||
self.assertEqual(availability_time.seconds, 270 * 60)
|
self.assertEqual(270 * 60, availability_time.seconds)
|
||||||
|
|
||||||
def test_reservation_time(self):
|
def test_reservation_time(self):
|
||||||
"""Find the total reserved time."""
|
"""Find the total reserved time."""
|
||||||
|
@ -240,7 +240,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
reservation_time = db_utils.reservation_time('r1',
|
reservation_time = db_utils.reservation_time('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date)
|
end_date)
|
||||||
self.assertEqual(reservation_time.seconds, 60 * 60)
|
self.assertEqual(60 * 60, reservation_time.seconds)
|
||||||
start_date = datetime.datetime.strptime('2030-01-01 09:15',
|
start_date = datetime.datetime.strptime('2030-01-01 09:15',
|
||||||
'%Y-%m-%d %H:%M')
|
'%Y-%m-%d %H:%M')
|
||||||
end_date = datetime.datetime.strptime('2030-01-01 13:45',
|
end_date = datetime.datetime.strptime('2030-01-01 13:45',
|
||||||
|
@ -248,7 +248,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
reservation_time = db_utils.reservation_time('r1',
|
reservation_time = db_utils.reservation_time('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date)
|
end_date)
|
||||||
self.assertEqual(reservation_time.seconds, 120 * 60)
|
self.assertEqual(120 * 60, reservation_time.seconds)
|
||||||
start_date = datetime.datetime.strptime('2030-01-01 08:00',
|
start_date = datetime.datetime.strptime('2030-01-01 08:00',
|
||||||
'%Y-%m-%d %H:%M')
|
'%Y-%m-%d %H:%M')
|
||||||
end_date = datetime.datetime.strptime('2030-01-01 15:00',
|
end_date = datetime.datetime.strptime('2030-01-01 15:00',
|
||||||
|
@ -256,7 +256,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
reservation_time = db_utils.reservation_time('r1',
|
reservation_time = db_utils.reservation_time('r1',
|
||||||
start_date,
|
start_date,
|
||||||
end_date)
|
end_date)
|
||||||
self.assertEqual(reservation_time.seconds, 150 * 60)
|
self.assertEqual(150 * 60, reservation_time.seconds)
|
||||||
|
|
||||||
def test_reservation_ratio(self):
|
def test_reservation_ratio(self):
|
||||||
"""Find the reservation ratio."""
|
"""Find the reservation ratio."""
|
||||||
|
@ -290,8 +290,8 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
|
||||||
end_date = datetime.datetime.strptime('2030-01-01 14:30',
|
end_date = datetime.datetime.strptime('2030-01-01 14:30',
|
||||||
'%Y-%m-%d %H:%M')
|
'%Y-%m-%d %H:%M')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
db_utils.number_of_reservations('r1', start_date, end_date),
|
2,
|
||||||
2)
|
db_utils.number_of_reservations('r1', start_date, end_date))
|
||||||
|
|
||||||
def test_longest_lease(self):
|
def test_longest_lease(self):
|
||||||
"""Find the longest lease."""
|
"""Find the longest lease."""
|
||||||
|
|
|
@ -593,7 +593,7 @@ class TestVirtualInstancePlugin(tests.TestCase):
|
||||||
'removed': set(['host-id1', 'host-id2', 'host-id3'])}
|
'removed': set(['host-id1', 'host-id2', 'host-id3'])}
|
||||||
ret = plugin.pickup_hosts(reservation['id'], values)
|
ret = plugin.pickup_hosts(reservation['id'], values)
|
||||||
self.assertEqual(expect['added'], ret['added'])
|
self.assertEqual(expect['added'], ret['added'])
|
||||||
self.assertEqual(len(ret['removed']), 2)
|
self.assertEqual(2, len(ret['removed']))
|
||||||
self.assertTrue(all([h in expect['removed'] for h in ret['removed']]))
|
self.assertTrue(all([h in expect['removed'] for h in ret['removed']]))
|
||||||
query_params = {
|
query_params = {
|
||||||
'cpus': 1, 'memory': 1024, 'disk': 10,
|
'cpus': 1, 'memory': 1024, 'disk': 10,
|
||||||
|
|
|
@ -186,13 +186,13 @@ class PhysicalHostPluginTestCase(tests.TestCase):
|
||||||
self.db_host_get.assert_called_once_with('1')
|
self.db_host_get.assert_called_once_with('1')
|
||||||
expected = self.fake_host.copy()
|
expected = self.fake_host.copy()
|
||||||
expected.update({'foo': 'bar', 'buzz': 'word'})
|
expected.update({'foo': 'bar', 'buzz': 'word'})
|
||||||
self.assertEqual(host, expected)
|
self.assertEqual(expected, host)
|
||||||
|
|
||||||
def test_get_host_without_extracapabilities(self):
|
def test_get_host_without_extracapabilities(self):
|
||||||
self.get_extra_capabilities.return_value = {}
|
self.get_extra_capabilities.return_value = {}
|
||||||
host = self.fake_phys_plugin.get_computehost(self.fake_host_id)
|
host = self.fake_phys_plugin.get_computehost(self.fake_host_id)
|
||||||
self.db_host_get.assert_called_once_with('1')
|
self.db_host_get.assert_called_once_with('1')
|
||||||
self.assertEqual(host, self.fake_host)
|
self.assertEqual(self.fake_host, host)
|
||||||
|
|
||||||
@testtools.skip('incorrect decorator')
|
@testtools.skip('incorrect decorator')
|
||||||
def test_list_hosts(self):
|
def test_list_hosts(self):
|
||||||
|
@ -204,7 +204,7 @@ class PhysicalHostPluginTestCase(tests.TestCase):
|
||||||
self.get_extra_capabilities.return_value = {}
|
self.get_extra_capabilities.return_value = {}
|
||||||
host = self.fake_phys_plugin.create_computehost(self.fake_host)
|
host = self.fake_phys_plugin.create_computehost(self.fake_host)
|
||||||
self.db_host_create.assert_called_once_with(self.fake_host)
|
self.db_host_create.assert_called_once_with(self.fake_host)
|
||||||
self.assertEqual(host, self.fake_host)
|
self.assertEqual(self.fake_host, host)
|
||||||
|
|
||||||
def test_create_host_with_extra_capabilities(self):
|
def test_create_host_with_extra_capabilities(self):
|
||||||
fake_host = self.fake_host.copy()
|
fake_host = self.fake_host.copy()
|
||||||
|
@ -220,7 +220,7 @@ class PhysicalHostPluginTestCase(tests.TestCase):
|
||||||
host = self.fake_phys_plugin.create_computehost(fake_request)
|
host = self.fake_phys_plugin.create_computehost(fake_request)
|
||||||
self.db_host_create.assert_called_once_with(self.fake_host)
|
self.db_host_create.assert_called_once_with(self.fake_host)
|
||||||
self.db_host_extra_capability_create.assert_called_once_with(fake_capa)
|
self.db_host_extra_capability_create.assert_called_once_with(fake_capa)
|
||||||
self.assertEqual(host, fake_host)
|
self.assertEqual(fake_host, host)
|
||||||
|
|
||||||
def test_create_host_with_capabilities_too_long(self):
|
def test_create_host_with_capabilities_too_long(self):
|
||||||
fake_host = self.fake_host.copy()
|
fake_host = self.fake_host.copy()
|
||||||
|
|
|
@ -25,15 +25,15 @@ class TestContextCreate(tests.TestCase):
|
||||||
|
|
||||||
def test_kwargs(self):
|
def test_kwargs(self):
|
||||||
ctx = TestContext(first=1, second=2)
|
ctx = TestContext(first=1, second=2)
|
||||||
self.assertEqual(ctx.to_dict(), {"first": 1, "second": 2})
|
self.assertEqual({"first": 1, "second": 2}, ctx.to_dict())
|
||||||
|
|
||||||
def test_dict(self):
|
def test_dict(self):
|
||||||
ctx = TestContext({"first": 1, "second": 2})
|
ctx = TestContext({"first": 1, "second": 2})
|
||||||
self.assertEqual(ctx.to_dict(), {"first": 1, "second": 2})
|
self.assertEqual({"first": 1, "second": 2}, ctx.to_dict())
|
||||||
|
|
||||||
def test_mix(self):
|
def test_mix(self):
|
||||||
ctx = TestContext({"first": 1}, second=2)
|
ctx = TestContext({"first": 1}, second=2)
|
||||||
self.assertEqual(ctx.to_dict(), {"first": 1, "second": 2})
|
self.assertEqual({"first": 1, "second": 2}, ctx.to_dict())
|
||||||
|
|
||||||
def test_fail(self):
|
def test_fail(self):
|
||||||
ctx = TestContext({'first': 1, "forth": 4}, fifth=5)
|
ctx = TestContext({'first': 1, "forth": 4}, fifth=5)
|
||||||
|
@ -48,7 +48,7 @@ class TestBaseContext(tests.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestBaseContext, self).tearDown()
|
super(TestBaseContext, self).tearDown()
|
||||||
self.assertEqual(self.context.first, 1)
|
self.assertEqual(1, self.context.first)
|
||||||
|
|
||||||
def test_get_default(self):
|
def test_get_default(self):
|
||||||
self.assertIsNone(self.context.third)
|
self.assertIsNone(self.context.third)
|
||||||
|
@ -95,11 +95,11 @@ class TestBlazarContext(tests.TestCase):
|
||||||
|
|
||||||
def test_elevated_empty(self):
|
def test_elevated_empty(self):
|
||||||
ctx = context.BlazarContext.elevated()
|
ctx = context.BlazarContext.elevated()
|
||||||
self.assertEqual(ctx.is_admin, True)
|
self.assertTrue(ctx.is_admin)
|
||||||
|
|
||||||
def test_elevated(self):
|
def test_elevated(self):
|
||||||
with context.BlazarContext(user_id="user", project_id="project"):
|
with context.BlazarContext(user_id="user", project_id="project"):
|
||||||
ctx = context.BlazarContext.elevated()
|
ctx = context.BlazarContext.elevated()
|
||||||
self.assertEqual(ctx.user_id, "user")
|
self.assertEqual(ctx.user_id, "user")
|
||||||
self.assertEqual(ctx.project_id, "project")
|
self.assertEqual(ctx.project_id, "project")
|
||||||
self.assertEqual(ctx.is_admin, True)
|
self.assertTrue(ctx.is_admin)
|
||||||
|
|
|
@ -25,44 +25,44 @@ class BlazarExceptionTestCase(tests.TestCase):
|
||||||
msg_fmt = "default message"
|
msg_fmt = "default message"
|
||||||
|
|
||||||
exc = FakeBlazarException()
|
exc = FakeBlazarException()
|
||||||
self.assertEqual(six.text_type(exc), 'default message')
|
self.assertEqual('default message', six.text_type(exc))
|
||||||
|
|
||||||
def test_error_msg(self):
|
def test_error_msg(self):
|
||||||
self.assertEqual(six.text_type(exceptions.BlazarException('test')),
|
self.assertEqual('test',
|
||||||
'test')
|
six.text_type(exceptions.BlazarException('test')))
|
||||||
|
|
||||||
def test_default_error_msg_with_kwargs(self):
|
def test_default_error_msg_with_kwargs(self):
|
||||||
class FakeBlazarException(exceptions.BlazarException):
|
class FakeBlazarException(exceptions.BlazarException):
|
||||||
msg_fmt = "default message: %(code)s"
|
msg_fmt = "default message: %(code)s"
|
||||||
|
|
||||||
exc = FakeBlazarException(code=500)
|
exc = FakeBlazarException(code=500)
|
||||||
self.assertEqual(six.text_type(exc), 'default message: 500')
|
self.assertEqual('default message: 500', six.text_type(exc))
|
||||||
self.assertEqual(str(exc), 'default message: 500')
|
self.assertEqual('default message: 500', str(exc))
|
||||||
|
|
||||||
def test_error_msg_exception_with_kwargs(self):
|
def test_error_msg_exception_with_kwargs(self):
|
||||||
class FakeBlazarException(exceptions.BlazarException):
|
class FakeBlazarException(exceptions.BlazarException):
|
||||||
msg_fmt = "default message: %(mispelled_code)s"
|
msg_fmt = "default message: %(mispelled_code)s"
|
||||||
|
|
||||||
exc = FakeBlazarException(code=500, mispelled_code='blah')
|
exc = FakeBlazarException(code=500, mispelled_code='blah')
|
||||||
self.assertEqual(six.text_type(exc), 'default message: blah')
|
self.assertEqual('default message: blah', six.text_type(exc))
|
||||||
self.assertEqual(str(exc), 'default message: blah')
|
self.assertEqual('default message: blah', str(exc))
|
||||||
|
|
||||||
def test_default_error_code(self):
|
def test_default_error_code(self):
|
||||||
class FakeBlazarException(exceptions.BlazarException):
|
class FakeBlazarException(exceptions.BlazarException):
|
||||||
code = 404
|
code = 404
|
||||||
|
|
||||||
exc = FakeBlazarException()
|
exc = FakeBlazarException()
|
||||||
self.assertEqual(exc.kwargs['code'], 404)
|
self.assertEqual(404, exc.kwargs['code'])
|
||||||
|
|
||||||
def test_error_code_from_kwarg(self):
|
def test_error_code_from_kwarg(self):
|
||||||
class FakeBlazarException(exceptions.BlazarException):
|
class FakeBlazarException(exceptions.BlazarException):
|
||||||
code = 500
|
code = 500
|
||||||
|
|
||||||
exc = FakeBlazarException(code=404)
|
exc = FakeBlazarException(code=404)
|
||||||
self.assertEqual(exc.kwargs['code'], 404)
|
self.assertEqual(404, exc.kwargs['code'])
|
||||||
|
|
||||||
def test_policynotauthorized_exception(self):
|
def test_policynotauthorized_exception(self):
|
||||||
exc = exceptions.PolicyNotAuthorized(action='foo')
|
exc = exceptions.PolicyNotAuthorized(action='foo')
|
||||||
self.assertEqual(six.text_type(exc),
|
self.assertEqual("Policy doesn't allow foo to be performed",
|
||||||
"Policy doesn't allow foo to be performed")
|
six.text_type(exc))
|
||||||
self.assertEqual(exc.kwargs['code'], 403)
|
self.assertEqual(403, exc.kwargs['code'])
|
||||||
|
|
Loading…
Reference in New Issue