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
changes/50/485050/5
Kiran_totad 5 years ago committed by Pierre Riteau
parent 9e26f79292
commit 3fdac0da7d
  1. 8
      blazar/tests/api/test_acl.py
  2. 4
      blazar/tests/api/test_root.py
  3. 88
      blazar/tests/db/sqlalchemy/test_utils.py
  4. 2
      blazar/tests/plugins/instances/test_instance_plugin.py
  5. 8
      blazar/tests/plugins/oshosts/test_physical_host_plugin.py
  6. 12
      blazar/tests/test_context.py
  7. 24
      blazar/tests/test_exceptions.py

@ -34,20 +34,20 @@ class TestACL(api.APITest):
def test_non_authenticated(self):
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):
response = self.get_json(self.path,
headers={'X-Auth-Token': self.ADMIN_TOKEN})
self.assertEqual(response, [])
self.assertEqual([], response)
def test_non_admin(self):
response = self.get_json(self.path,
headers={'X-Auth-Token': self.MEMBER_TOKEN},
expect_errors=True)
self.assertEqual(response.status_int, 403)
self.assertEqual(403, response.status_int)
def test_non_admin_with_admin_header(self):
response = self.get_json(self.path,
@ -55,4 +55,4 @@ class TestACL(api.APITest):
'X-Roles': 'admin'},
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',
expect_errors=True,
path_prefix='')
self.assertEqual(response.status_int, 404)
self.assertEqual(response.content_type, "text/plain")
self.assertEqual(404, response.status_int)
self.assertEqual("text/plain", response.content_type)

@ -142,33 +142,33 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
start_date,
end_date,
duration)
self.assertEqual(len(free_periods), 3)
self.assertEqual(free_periods[0][0].strftime('%Y-%m-%d %H:%M'),
'2028-01-01 08:00')
self.assertEqual(free_periods[0][1].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 09:00')
self.assertEqual(free_periods[1][0].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 10:30')
self.assertEqual(free_periods[1][1].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 13:00')
self.assertEqual(free_periods[2][0].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 14:00')
self.assertEqual(free_periods[2][1].strftime('%Y-%m-%d %H:%M'),
'2099-01-01 00:00')
self.assertEqual(3, len(free_periods))
self.assertEqual('2028-01-01 08:00',
free_periods[0][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 09:00',
free_periods[0][1].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 10:30',
free_periods[1][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 13:00',
free_periods[1][1].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 14:00',
free_periods[2][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2099-01-01 00:00',
free_periods[2][1].strftime('%Y-%m-%d %H:%M'))
duration = datetime.timedelta(hours=3)
free_periods = db_utils.get_free_periods('r1',
start_date,
end_date,
duration)
self.assertEqual(len(free_periods), 2)
self.assertEqual(free_periods[0][0].strftime('%Y-%m-%d %H:%M'),
'2028-01-01 08:00')
self.assertEqual(free_periods[0][1].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 09:00')
self.assertEqual(free_periods[1][0].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 14:00')
self.assertEqual(free_periods[1][1].strftime('%Y-%m-%d %H:%M'),
'2099-01-01 00:00')
self.assertEqual(2, len(free_periods))
self.assertEqual('2028-01-01 08:00',
free_periods[0][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 09:00',
free_periods[0][1].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 14:00',
free_periods[1][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2099-01-01 00:00',
free_periods[1][1].strftime('%Y-%m-%d %H:%M'))
def test_get_reserved_periods(self):
"""Find the reserved periods."""
@ -182,25 +182,25 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
start_date,
end_date,
duration)
self.assertEqual(len(reserved_periods), 2)
self.assertEqual(reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 09:00')
self.assertEqual(reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 10:30')
self.assertEqual(reserved_periods[1][0].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 13:00')
self.assertEqual(reserved_periods[1][1].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 14:00')
self.assertEqual(2, len(reserved_periods))
self.assertEqual('2030-01-01 09:00',
reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 10:30',
reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 13:00',
reserved_periods[1][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 14:00',
reserved_periods[1][1].strftime('%Y-%m-%d %H:%M'))
duration = datetime.timedelta(hours=3)
reserved_periods = db_utils.get_reserved_periods('r1',
start_date,
end_date,
duration)
self.assertEqual(len(reserved_periods), 1)
self.assertEqual(reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 09:00')
self.assertEqual(reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'),
'2030-01-01 14:00')
self.assertEqual(1, len(reserved_periods))
self.assertEqual('2030-01-01 09:00',
reserved_periods[0][0].strftime('%Y-%m-%d %H:%M'))
self.assertEqual('2030-01-01 14:00',
reserved_periods[0][1].strftime('%Y-%m-%d %H:%M'))
def test_availability_time(self):
"""Find the total availability time."""
@ -212,7 +212,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
availability_time = db_utils.availability_time('r1',
start_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',
'%Y-%m-%d %H:%M')
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',
start_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',
'%Y-%m-%d %H:%M')
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',
start_date,
end_date)
self.assertEqual(availability_time.seconds, 270 * 60)
self.assertEqual(270 * 60, availability_time.seconds)
def test_reservation_time(self):
"""Find the total reserved time."""
@ -240,7 +240,7 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
reservation_time = db_utils.reservation_time('r1',
start_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',
'%Y-%m-%d %H:%M')
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',
start_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',
'%Y-%m-%d %H:%M')
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',
start_date,
end_date)
self.assertEqual(reservation_time.seconds, 150 * 60)
self.assertEqual(150 * 60, reservation_time.seconds)
def test_reservation_ratio(self):
"""Find the reservation ratio."""
@ -290,8 +290,8 @@ class SQLAlchemyDBUtilsTestCase(tests.DBTestCase):
end_date = datetime.datetime.strptime('2030-01-01 14:30',
'%Y-%m-%d %H:%M')
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):
"""Find the longest lease."""

@ -593,7 +593,7 @@ class TestVirtualInstancePlugin(tests.TestCase):
'removed': set(['host-id1', 'host-id2', 'host-id3'])}
ret = plugin.pickup_hosts(reservation['id'], values)
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']]))
query_params = {
'cpus': 1, 'memory': 1024, 'disk': 10,

@ -186,13 +186,13 @@ class PhysicalHostPluginTestCase(tests.TestCase):
self.db_host_get.assert_called_once_with('1')
expected = self.fake_host.copy()
expected.update({'foo': 'bar', 'buzz': 'word'})
self.assertEqual(host, expected)
self.assertEqual(expected, host)
def test_get_host_without_extracapabilities(self):
self.get_extra_capabilities.return_value = {}
host = self.fake_phys_plugin.get_computehost(self.fake_host_id)
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')
def test_list_hosts(self):
@ -204,7 +204,7 @@ class PhysicalHostPluginTestCase(tests.TestCase):
self.get_extra_capabilities.return_value = {}
host = self.fake_phys_plugin.create_computehost(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):
fake_host = self.fake_host.copy()
@ -220,7 +220,7 @@ class PhysicalHostPluginTestCase(tests.TestCase):
host = self.fake_phys_plugin.create_computehost(fake_request)
self.db_host_create.assert_called_once_with(self.fake_host)
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):
fake_host = self.fake_host.copy()

@ -25,15 +25,15 @@ class TestContextCreate(tests.TestCase):
def test_kwargs(self):
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):
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):
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):
ctx = TestContext({'first': 1, "forth": 4}, fifth=5)
@ -48,7 +48,7 @@ class TestBaseContext(tests.TestCase):
def tearDown(self):
super(TestBaseContext, self).tearDown()
self.assertEqual(self.context.first, 1)
self.assertEqual(1, self.context.first)
def test_get_default(self):
self.assertIsNone(self.context.third)
@ -95,11 +95,11 @@ class TestBlazarContext(tests.TestCase):
def test_elevated_empty(self):
ctx = context.BlazarContext.elevated()
self.assertEqual(ctx.is_admin, True)
self.assertTrue(ctx.is_admin)
def test_elevated(self):
with context.BlazarContext(user_id="user", project_id="project"):
ctx = context.BlazarContext.elevated()
self.assertEqual(ctx.user_id, "user")
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"
exc = FakeBlazarException()
self.assertEqual(six.text_type(exc), 'default message')
self.assertEqual('default message', six.text_type(exc))
def test_error_msg(self):
self.assertEqual(six.text_type(exceptions.BlazarException('test')),
'test')
self.assertEqual('test',
six.text_type(exceptions.BlazarException('test')))
def test_default_error_msg_with_kwargs(self):
class FakeBlazarException(exceptions.BlazarException):
msg_fmt = "default message: %(code)s"
exc = FakeBlazarException(code=500)
self.assertEqual(six.text_type(exc), 'default message: 500')
self.assertEqual(str(exc), 'default message: 500')
self.assertEqual('default message: 500', six.text_type(exc))
self.assertEqual('default message: 500', str(exc))
def test_error_msg_exception_with_kwargs(self):
class FakeBlazarException(exceptions.BlazarException):
msg_fmt = "default message: %(mispelled_code)s"
exc = FakeBlazarException(code=500, mispelled_code='blah')
self.assertEqual(six.text_type(exc), 'default message: blah')
self.assertEqual(str(exc), 'default message: blah')
self.assertEqual('default message: blah', six.text_type(exc))
self.assertEqual('default message: blah', str(exc))
def test_default_error_code(self):
class FakeBlazarException(exceptions.BlazarException):
code = 404
exc = FakeBlazarException()
self.assertEqual(exc.kwargs['code'], 404)
self.assertEqual(404, exc.kwargs['code'])
def test_error_code_from_kwarg(self):
class FakeBlazarException(exceptions.BlazarException):
code = 500
exc = FakeBlazarException(code=404)
self.assertEqual(exc.kwargs['code'], 404)
self.assertEqual(404, exc.kwargs['code'])
def test_policynotauthorized_exception(self):
exc = exceptions.PolicyNotAuthorized(action='foo')
self.assertEqual(six.text_type(exc),
"Policy doesn't allow foo to be performed")
self.assertEqual(exc.kwargs['code'], 403)
self.assertEqual("Policy doesn't allow foo to be performed",
six.text_type(exc))
self.assertEqual(403, exc.kwargs['code'])

Loading…
Cancel
Save