Fix order of arguments in assertEqual

Some tests used incorrect order assertEqual(observed, expected).

The correct order expected by testtools is
assertEqual(expected, observed).

Change-Id: Iabf6e55146412b57b6a6544f312f9510f762566a
Partial-Bug: #1259292
changes/62/77562/11
ChenZheng 9 years ago committed by jackychen
parent f4d33f5795
commit c7d5371b47
  1. 62
      horizon/test/tests/base.py
  2. 8
      horizon/test/tests/forms.py
  3. 8
      horizon/test/tests/messages.py
  4. 8
      horizon/test/tests/middleware.py
  5. 268
      horizon/test/tests/tables.py
  6. 50
      horizon/test/tests/tabs.py
  7. 8
      horizon/test/tests/templatetags.py
  8. 34
      horizon/test/tests/utils.py
  9. 24
      horizon/test/tests/workflows.py
  10. 40
      openstack_dashboard/test/api_tests/base_tests.py
  11. 61
      openstack_dashboard/test/api_tests/ceilometer_tests.py
  12. 18
      openstack_dashboard/test/api_tests/cinder_tests.py
  13. 24
      openstack_dashboard/test/api_tests/fwaas_tests.py
  14. 2
      openstack_dashboard/test/api_tests/heat_tests.py
  15. 34
      openstack_dashboard/test/api_tests/keystone_tests.py
  16. 62
      openstack_dashboard/test/api_tests/network_tests.py
  17. 4
      openstack_dashboard/test/api_tests/neutron_tests.py
  18. 6
      openstack_dashboard/test/api_tests/nova_tests.py
  19. 12
      openstack_dashboard/test/api_tests/swift_tests.py
  20. 4
      openstack_dashboard/test/tests/policy.py
  21. 8
      openstack_dashboard/test/tests/quotas.py
  22. 2
      openstack_dashboard/test/tests/selenium_tests.py

@ -134,9 +134,9 @@ class HorizonTests(BaseHorizonTests):
``settings.INSTALLED_APPS`` are loaded from the start.
"""
# Registration
self.assertEqual(len(base.Horizon._registry), 2)
self.assertEqual(2, len(base.Horizon._registry))
horizon.register(MyDash)
self.assertEqual(len(base.Horizon._registry), 3)
self.assertEqual(3, len(base.Horizon._registry))
with self.assertRaises(ValueError):
horizon.register(MyPanel)
with self.assertRaises(ValueError):
@ -155,29 +155,29 @@ class HorizonTests(BaseHorizonTests):
'<Dashboard: mydash>'])
# Removal
self.assertEqual(len(base.Horizon._registry), 3)
self.assertEqual(3, len(base.Horizon._registry))
horizon.unregister(MyDash)
self.assertEqual(len(base.Horizon._registry), 2)
self.assertEqual(2, len(base.Horizon._registry))
with self.assertRaises(base.NotRegistered):
horizon.get_dashboard(MyDash)
def test_site(self):
self.assertEqual(unicode(base.Horizon), "Horizon")
self.assertEqual(repr(base.Horizon), "<Site: horizon>")
self.assertEqual("Horizon", unicode(base.Horizon))
self.assertEqual("<Site: horizon>", repr(base.Horizon))
dash = base.Horizon.get_dashboard('cats')
self.assertEqual(base.Horizon.get_default_dashboard(), dash)
self.assertEqual(dash, base.Horizon.get_default_dashboard())
test_user = User()
self.assertEqual(base.Horizon.get_user_home(test_user),
dash.get_absolute_url())
self.assertEqual(dash.get_absolute_url(),
base.Horizon.get_user_home(test_user))
def test_dashboard(self):
cats = horizon.get_dashboard("cats")
self.assertEqual(cats._registered_with, base.Horizon)
self.assertEqual(base.Horizon, cats._registered_with)
self.assertQuerysetEqual(cats.get_panels(),
['<Panel: kittens>',
'<Panel: tigers>'])
self.assertEqual(cats.get_absolute_url(), "/cats/")
self.assertEqual(cats.name, "Cats")
self.assertEqual("/cats/", cats.get_absolute_url())
self.assertEqual("Cats", cats.name)
# Test registering a module with a dashboard that defines panels
# as a panel group.
@ -201,8 +201,8 @@ class HorizonTests(BaseHorizonTests):
def test_panels(self):
cats = horizon.get_dashboard("cats")
tigers = cats.get_panel("tigers")
self.assertEqual(tigers._registered_with, cats)
self.assertEqual(tigers.get_absolute_url(), "/cats/tigers/")
self.assertEqual(cats, tigers._registered_with)
self.assertEqual("/cats/tigers/", tigers.get_absolute_url())
def test_panel_without_slug_fails(self):
class InvalidPanel(horizon.Panel):
@ -223,7 +223,7 @@ class HorizonTests(BaseHorizonTests):
with self.assertRaises(urlresolvers.NoReverseMatch):
tigers.get_absolute_url()
tigers.index_url_name = "index"
self.assertEqual(tigers.get_absolute_url(), "/cats/tigers/")
self.assertEqual("/cats/tigers/", tigers.get_absolute_url())
def test_lazy_urls(self):
urlpatterns = horizon.urls[0]
@ -259,9 +259,9 @@ class HorizonTests(BaseHorizonTests):
# Simulate ajax call
resp = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
# Response should be HTTP 401 with redirect header
self.assertEqual(resp.status_code, 401)
self.assertEqual(resp["X-Horizon-Location"],
redirect_url)
self.assertEqual(401, resp.status_code)
self.assertEqual(redirect_url,
resp["X-Horizon-Location"])
def test_required_permissions(self):
dash = horizon.get_dashboard("cats")
@ -271,16 +271,16 @@ class HorizonTests(BaseHorizonTests):
self.assertQuerysetEqual(self.user.get_all_permissions(), [])
resp = self.client.get(panel.get_absolute_url())
self.assertEqual(resp.status_code, 302)
self.assertEqual(302, resp.status_code)
resp = self.client.get(panel.get_absolute_url(),
follow=False,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 401)
self.assertEqual(401, resp.status_code)
# Test insufficient permissions for logged-in user
resp = self.client.get(panel.get_absolute_url(), follow=True)
self.assertEqual(resp.status_code, 200)
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, "auth/login.html")
self.assertContains(resp, "Login as different user", 1, 200)
@ -288,13 +288,13 @@ class HorizonTests(BaseHorizonTests):
self.set_permissions(permissions=['test'])
resp = self.client.get(panel.get_absolute_url())
self.assertEqual(resp.status_code, 200)
self.assertEqual(200, resp.status_code)
# Test modal form
resp = self.client.get(panel.get_absolute_url(),
follow=False,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 200)
self.assertEqual(200, resp.status_code)
def test_ssl_redirect_by_proxy(self):
dogs = horizon.get_dashboard("dogs")
@ -312,9 +312,9 @@ class HorizonTests(BaseHorizonTests):
'https')
resp = self.client.get(url, HTTP_X_FORWARDED_PROTOCOL="https")
self.assertEqual(resp.status_code, 302)
self.assertEqual(resp['location'],
'https://testserver:80%s' % redirect_url)
self.assertEqual(302, resp.status_code)
self.assertEqual('https://testserver:80%s' % redirect_url,
resp['location'])
# Restore settings
settings.SECURE_PROXY_SSL_HEADER = None
@ -390,7 +390,7 @@ class CustomPanelTests(BaseHorizonTests):
def test_customize_dashboard(self):
cats = horizon.get_dashboard("cats")
self.assertEqual(cats.name, "WildCats")
self.assertEqual("WildCats", cats.name)
self.assertQuerysetEqual(cats.get_panels(),
['<Panel: kittens>'])
with self.assertRaises(base.NotRegistered):
@ -428,16 +428,16 @@ class CustomPermissionsTests(BaseHorizonTests):
self.assertQuerysetEqual(self.user.get_all_permissions(), [])
resp = self.client.get(panel.get_absolute_url())
self.assertEqual(resp.status_code, 302)
self.assertEqual(302, resp.status_code)
resp = self.client.get(panel.get_absolute_url(),
follow=False,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(resp.status_code, 401)
self.assertEqual(401, resp.status_code)
# Test customized permissions for logged-in user
resp = self.client.get(panel.get_absolute_url(), follow=True)
self.assertEqual(resp.status_code, 200)
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, "auth/login.html")
self.assertContains(resp, "Login as different user", 1, 200)
@ -445,7 +445,7 @@ class CustomPermissionsTests(BaseHorizonTests):
self.set_permissions(permissions=['test'])
resp = self.client.get(panel.get_absolute_url())
self.assertEqual(resp.status_code, 200)
self.assertEqual(200, resp.status_code)
# Test modal form
resp = self.client.get(panel.get_absolute_url(),

@ -50,18 +50,18 @@ class FormMixinTests(test.TestCase):
context = view.get_context_data()
if add_field:
self.assertEqual(context['add_to_field'], "keepme")
self.assertEqual("keepme", context['add_to_field'])
else:
self.assertNotIn('add_to_field', context)
def test_template_name_change_based_on_ajax_request(self):
view = self._prepare_view(forms.views.ModalFormView,
dict(HTTP_X_REQUESTED_WITH='XMLHttpRequest'))
self.assertEqual(view.get_template_names(),
'_' + view.template_name)
self.assertEqual('_' + view.template_name,
view.get_template_names())
view = self._prepare_view(forms.views.ModalFormView, {})
self.assertEqual(view.get_template_names(), view.template_name)
self.assertEqual(view.template_name, view.get_template_names())
class TestForm(forms.SelfHandlingForm):

@ -35,8 +35,8 @@ class MessageTests(test.TestCase):
self.assertItemsEqual(req.horizon['async_messages'], [expected])
res = http.HttpResponse()
res = middleware.HorizonMiddleware().process_response(req, res)
self.assertEqual(res['X-Horizon-Messages'],
json.dumps([expected]))
self.assertEqual(json.dumps([expected]),
res['X-Horizon-Messages'])
def test_safe_message(self):
req = self.request
@ -49,5 +49,5 @@ class MessageTests(test.TestCase):
self.assertItemsEqual(req.horizon['async_messages'], [expected])
res = http.HttpResponse()
res = middleware.HorizonMiddleware().process_response(req, res)
self.assertEqual(res['X-Horizon-Messages'],
json.dumps([expected]))
self.assertEqual(json.dumps([expected]),
res['X-Horizon-Messages'])

@ -46,8 +46,8 @@ class MiddlewareTests(test.TestCase):
request.session['last_activity'] = int(time.time()) - (timeout + 10)
mw = middleware.HorizonMiddleware()
resp = mw.process_request(request)
self.assertEqual(resp.status_code, 302)
self.assertEqual(resp.get('Location'), response_url)
self.assertEqual(302, resp.status_code)
self.assertEqual(response_url, resp.get('Location'))
def test_process_response_redirect_on_ajax_request(self):
url = settings.LOGIN_URL
@ -63,5 +63,5 @@ class MiddlewareTests(test.TestCase):
response.client = self.client
resp = mw.process_response(request, response)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp['X-Horizon-Location'], url)
self.assertEqual(200, resp.status_code)
self.assertEqual(url, resp['X-Horizon-Location'])

@ -310,13 +310,13 @@ class DataTableTests(test.TestCase):
"""Tests everything that happens when the table is instantiated."""
self.table = MyTable(self.request, TEST_DATA)
# Properties defined on the table
self.assertEqual(self.table.data, TEST_DATA)
self.assertEqual(self.table.name, "my_table")
self.assertEqual(TEST_DATA, self.table.data)
self.assertEqual("my_table", self.table.name)
# Verify calculated options that weren't specified explicitly
self.assertTrue(self.table._meta.actions_column)
self.assertTrue(self.table._meta.multi_select)
# Test for verbose_name
self.assertEqual(unicode(self.table), u"My Table")
self.assertEqual(u"My Table", unicode(self.table))
# Column ordering and exclusion.
# This should include auto-columns for multi_select and actions,
# but should not contain the excluded column.
@ -348,18 +348,18 @@ class DataTableTests(test.TestCase):
'<MyToggleAction: toggle>'])
# Auto-generated columns
multi_select = self.table.columns['multi_select']
self.assertEqual(multi_select.auto, "multi_select")
self.assertEqual(multi_select.get_final_attrs().get('class', ""),
"multi_select_column")
self.assertEqual("multi_select", multi_select.auto)
self.assertEqual("multi_select_column",
multi_select.get_final_attrs().get('class', ""))
actions = self.table.columns['actions']
self.assertEqual(actions.auto, "actions")
self.assertEqual(actions.get_final_attrs().get('class', ""),
"actions_column")
self.assertEqual("actions", actions.auto)
self.assertEqual("actions_column",
actions.get_final_attrs().get('class', ""))
# In-line edit action on column.
name_column = self.table.columns['name']
self.assertEqual(name_column.update_action, MyUpdateAction)
self.assertEqual(name_column.form_field.__class__, forms.CharField)
self.assertEqual(name_column.form_field_attributes, {'class': 'test'})
self.assertEqual(MyUpdateAction, name_column.update_action)
self.assertEqual(forms.CharField, name_column.form_field.__class__)
self.assertEqual({'class': 'test'}, name_column.form_field_attributes)
def test_table_force_no_multiselect(self):
class TempTable(MyTable):
@ -399,7 +399,7 @@ class DataTableTests(test.TestCase):
name_column = self.table.columns['name']
self.assertIsNone(name_column.update_action)
self.assertIsNone(name_column.form_field)
self.assertEqual(name_column.form_field_attributes, {})
self.assertEqual({}, name_column.form_field_attributes)
def test_table_natural_no_actions_column(self):
class TempTable(MyTable):
@ -476,20 +476,20 @@ class DataTableTests(test.TestCase):
name_col = self.table.columns['name']
value_col = self.table.columns['value']
# transform
self.assertEqual(row.cells['id'].data, '1') # Standard attr access
self.assertEqual(row.cells['name'].data, 'custom object_1') # Callable
self.assertEqual('1', row.cells['id'].data) # Standard attr access
self.assertEqual('custom object_1', row.cells['name'].data) # Callable
# name and verbose_name
self.assertEqual(unicode(id_col), "Id")
self.assertEqual(unicode(name_col), "Verbose Name")
self.assertEqual("Id", unicode(id_col))
self.assertEqual("Verbose Name", unicode(name_col))
# sortable
self.assertEqual(id_col.sortable, False)
self.assertEqual(False, id_col.sortable)
self.assertNotIn("sortable", id_col.get_final_attrs().get('class', ""))
self.assertEqual(name_col.sortable, True)
self.assertEqual(True, name_col.sortable)
self.assertIn("sortable", name_col.get_final_attrs().get('class', ""))
# hidden
self.assertEqual(id_col.hidden, True)
self.assertEqual(True, id_col.hidden)
self.assertIn("hide", id_col.get_final_attrs().get('class', ""))
self.assertEqual(name_col.hidden, False)
self.assertEqual(False, name_col.hidden)
self.assertNotIn("hide", name_col.get_final_attrs().get('class', ""))
# link, link_classes, link_attrs, and get_link_url
self.assertIn('href="http://example.com/"', row.cells['value'].value)
@ -498,26 +498,26 @@ class DataTableTests(test.TestCase):
self.assertIn('data-tip="click for dialog"', row.cells['value'].value)
self.assertIn('href="/auth/login/"', row.cells['status'].value)
# empty_value
self.assertEqual(row3.cells['optional'].value, "N/A")
self.assertEqual("N/A", row3.cells['optional'].value)
# classes
self.assertEqual(value_col.get_final_attrs().get('class', ""),
"green blue sortable anchor normal_column")
self.assertEqual("green blue sortable anchor normal_column",
value_col.get_final_attrs().get('class', ""))
# status
cell_status = row.cells['status'].status
self.assertEqual(cell_status, True)
self.assertEqual(row.cells['status'].get_status_class(cell_status),
'status_up')
self.assertEqual(True, cell_status)
self.assertEqual('status_up',
row.cells['status'].get_status_class(cell_status))
# status_choices
id_col.status = True
id_col.status_choices = (('1', False), ('2', True), ('3', None))
cell_status = row.cells['id'].status
self.assertEqual(cell_status, False)
self.assertEqual(row.cells['id'].get_status_class(cell_status),
'status_down')
self.assertEqual(False, cell_status)
self.assertEqual('status_down',
row.cells['id'].get_status_class(cell_status))
cell_status = row3.cells['id'].status
self.assertIsNone(cell_status)
self.assertEqual(row.cells['id'].get_status_class(cell_status),
'status_unknown')
self.assertEqual('status_unknown',
row.cells['id'].get_status_class(cell_status))
# Ensure data is not cached on the column across table instances
self.table = MyTable(self.request, TEST_DATA_2)
@ -527,25 +527,25 @@ class DataTableTests(test.TestCase):
def test_table_row(self):
self.table = MyTable(self.request, TEST_DATA)
row = self.table.get_rows()[0]
self.assertEqual(row.table, self.table)
self.assertEqual(row.datum, TEST_DATA[0])
self.assertEqual(row.id, 'my_table__row__1')
self.assertEqual(self.table, row.table)
self.assertEqual(TEST_DATA[0], row.datum)
self.assertEqual('my_table__row__1', row.id)
# Verify row status works even if status isn't set on the column
self.assertEqual(row.status, True)
self.assertEqual(row.status_class, 'status_up')
self.assertEqual(True, row.status)
self.assertEqual('status_up', row.status_class)
# Check the cells as well
cell_status = row.cells['status'].status
self.assertEqual(cell_status, True)
self.assertEqual(row.cells['status'].get_status_class(cell_status),
'status_up')
self.assertEqual(True, cell_status)
self.assertEqual('status_up',
row.cells['status'].get_status_class(cell_status))
def test_table_column_truncation(self):
self.table = MyTable(self.request, TEST_DATA_5)
row = self.table.get_rows()[0]
self.assertEqual(len(row.cells['value'].data), 35)
self.assertEqual(row.cells['value'].data,
u'A Value That is longer than 35 c...')
self.assertEqual(35, len(row.cells['value'].data))
self.assertEqual(u'A Value That is longer than 35 c...',
row.cells['value'].data)
def test_table_rendering(self):
self.table = MyTable(self.request, TEST_DATA)
@ -614,10 +614,10 @@ class DataTableTests(test.TestCase):
# Check if in-line edit is available in the cell,
# but is not in inline_edit_mod.
self.assertEqual(name_cell.inline_edit_available,
True)
self.assertEqual(name_cell.inline_edit_mod,
False)
self.assertEqual(True,
name_cell.inline_edit_available)
self.assertEqual(False,
name_cell.inline_edit_mod)
# Check if is cell is rendered correctly.
name_cell_rendered = name_cell.render()
@ -642,10 +642,10 @@ class DataTableTests(test.TestCase):
# Check if in-line edit is available in the cell,
# but is not in inline_edit_mod.
self.assertEqual(name_cell.inline_edit_available,
True)
self.assertEqual(name_cell.inline_edit_mod,
False)
self.assertEqual(True,
name_cell.inline_edit_available)
self.assertEqual(False,
name_cell.inline_edit_mod)
# Check if is cell is rendered correctly.
name_cell_rendered = name_cell.render()
@ -674,12 +674,12 @@ class DataTableTests(test.TestCase):
# Check if in-line edit is available in the cell,
# and is in inline_edit_mod, also column auto must be
# set as form_field.
self.assertEqual(name_cell.inline_edit_available,
True)
self.assertEqual(name_cell.inline_edit_mod,
True)
self.assertEqual(name_col.auto,
'form_field')
self.assertEqual(True,
name_cell.inline_edit_available)
self.assertEqual(True,
name_cell.inline_edit_mod)
self.assertEqual('form_field',
name_col.auto)
# Check if is cell is rendered correctly.
name_cell_rendered = name_cell.render()
@ -778,91 +778,91 @@ class DataTableTests(test.TestCase):
action_string = "my_table__delete__1"
req = self.factory.post('/my_url/', {'action': action_string})
self.table = MyTable(req, TEST_DATA)
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'delete', '1'))
self.assertEqual(('my_table', 'delete', '1'),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertEqual(handled.status_code, 302)
self.assertEqual(handled["location"], "http://example.com/?ids=1")
self.assertEqual(302, handled.status_code)
self.assertEqual("http://example.com/?ids=1", handled["location"])
# Batch action (without toggle) conjugation behavior
req = self.factory.get('/my_url/')
self.table = MyTable(req, TEST_DATA_3)
toggle_action = self.table.get_row_actions(TEST_DATA_3[0])[2]
self.assertEqual(unicode(toggle_action.verbose_name), "Batch Item")
self.assertEqual("Batch Item", unicode(toggle_action.verbose_name))
# Single object toggle action
# GET page - 'up' to 'down'
req = self.factory.get('/my_url/')
self.table = MyTable(req, TEST_DATA_3)
self.assertEqual(len(self.table.get_row_actions(TEST_DATA_3[0])), 4)
self.assertEqual(4, len(self.table.get_row_actions(TEST_DATA_3[0])))
toggle_action = self.table.get_row_actions(TEST_DATA_3[0])[3]
self.assertEqual(unicode(toggle_action.verbose_name), "Down Item")
self.assertEqual("Down Item", unicode(toggle_action.verbose_name))
# Toggle from status 'up' to 'down'
# POST page
action_string = "my_table__toggle__1"
req = self.factory.post('/my_url/', {'action': action_string})
self.table = MyTable(req, TEST_DATA)
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'toggle', '1'))
self.assertEqual(('my_table', 'toggle', '1'),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertEqual(handled.status_code, 302)
self.assertEqual(handled["location"], "/my_url/")
self.assertEqual(list(req._messages)[0].message,
u"Downed Item: object_1")
self.assertEqual(302, handled.status_code)
self.assertEqual("/my_url/", handled["location"])
self.assertEqual(u"Downed Item: object_1",
list(req._messages)[0].message)
# Toggle from status 'down' to 'up'
# GET page - 'down' to 'up'
req = self.factory.get('/my_url/')
self.table = MyTable(req, TEST_DATA_2)
self.assertEqual(len(self.table.get_row_actions(TEST_DATA_2[0])), 3)
self.assertEqual(3, len(self.table.get_row_actions(TEST_DATA_2[0])))
toggle_action = self.table.get_row_actions(TEST_DATA_2[0])[2]
self.assertEqual(unicode(toggle_action.verbose_name), "Up Item")
self.assertEqual("Up Item", unicode(toggle_action.verbose_name))
# POST page
action_string = "my_table__toggle__2"
req = self.factory.post('/my_url/', {'action': action_string})
self.table = MyTable(req, TEST_DATA)
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'toggle', '2'))
self.assertEqual(('my_table', 'toggle', '2'),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertEqual(handled.status_code, 302)
self.assertEqual(handled["location"], "/my_url/")
self.assertEqual(list(req._messages)[0].message,
u"Upped Item: object_2")
self.assertEqual(302, handled.status_code)
self.assertEqual("/my_url/", handled["location"])
self.assertEqual(u"Upped Item: object_2",
list(req._messages)[0].message)
# Multiple object action
action_string = "my_table__delete"
req = self.factory.post('/my_url/', {'action': action_string,
'object_ids': [1, 2]})
self.table = MyTable(req, TEST_DATA)
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'delete', None))
self.assertEqual(('my_table', 'delete', None),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertEqual(handled.status_code, 302)
self.assertEqual(handled["location"], "http://example.com/?ids=1,2")
self.assertEqual(302, handled.status_code)
self.assertEqual("http://example.com/?ids=1,2", handled["location"])
# Action with nothing selected
req = self.factory.post('/my_url/', {'action': action_string})
self.table = MyTable(req, TEST_DATA)
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'delete', None))
self.assertEqual(('my_table', 'delete', None),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertIsNone(handled)
self.assertEqual(list(req._messages)[0].message,
"Please select a row before taking that action.")
self.assertEqual("Please select a row before taking that action.",
list(req._messages)[0].message)
# Action with specific id and multiple ids favors single id
action_string = "my_table__delete__3"
req = self.factory.post('/my_url/', {'action': action_string,
'object_ids': [1, 2]})
self.table = MyTable(req, TEST_DATA)
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'delete', '3'))
self.assertEqual(('my_table', 'delete', '3'),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertEqual(handled.status_code, 302)
self.assertEqual(handled["location"],
"http://example.com/?ids=3")
self.assertEqual(302, handled.status_code)
self.assertEqual("http://example.com/?ids=3",
handled["location"])
# At least one object in table
# BatchAction is available
@ -907,7 +907,7 @@ class DataTableTests(test.TestCase):
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.table = MyTable(req)
resp = self.table.maybe_preempt()
self.assertEqual(resp.status_code, 200)
self.assertEqual(200, resp.status_code)
# Make sure the data returned differs from the original
self.assertContains(resp, "my_table__row__1")
self.assertContains(resp, "status_down")
@ -924,12 +924,12 @@ class DataTableTests(test.TestCase):
# Verbose names
table_actions = self.table.get_table_actions()
self.assertEqual(unicode(table_actions[0].verbose_name), "Filter")
self.assertEqual(unicode(table_actions[1].verbose_name), "Delete Me")
self.assertEqual("Filter", unicode(table_actions[0].verbose_name))
self.assertEqual("Delete Me", unicode(table_actions[1].verbose_name))
row_actions = self.table.get_row_actions(TEST_DATA[0])
self.assertEqual(unicode(row_actions[0].verbose_name), "Delete Me")
self.assertEqual(unicode(row_actions[1].verbose_name), "Log In")
self.assertEqual("Delete Me", unicode(row_actions[0].verbose_name))
self.assertEqual("Log In", unicode(row_actions[1].verbose_name))
def test_server_filtering(self):
filter_value_param = "my_table__filter__q"
@ -976,7 +976,7 @@ class DataTableTests(test.TestCase):
self.table = MyTable(req, TEST_DATA_2)
handled = self.table.maybe_preempt()
# Checking the response header.
self.assertEqual(handled.status_code, 200)
self.assertEqual(200, handled.status_code)
# Checking the response content.
resp = handled
self.assertContains(resp, '<td', 1)
@ -1000,7 +1000,7 @@ class DataTableTests(test.TestCase):
self.table = MyTableNotAllowedInlineEdit(req, TEST_DATA_2)
handled = self.table.maybe_preempt()
# Checking the response header.
self.assertEqual(handled.status_code, 401)
self.assertEqual(401, handled.status_code)
def test_inline_edit_update_action_get_inline_edit_mod(self):
# Get request in inline_edit_mode should return td with form field.
@ -1011,7 +1011,7 @@ class DataTableTests(test.TestCase):
self.table = MyTable(req, TEST_DATA_2)
handled = self.table.maybe_preempt()
# Checking the response header.
self.assertEqual(handled.status_code, 200)
self.assertEqual(200, handled.status_code)
# Checking the response content.
resp = handled
self.assertContains(resp,
@ -1042,7 +1042,7 @@ class DataTableTests(test.TestCase):
self.table = MyTable(req, TEST_DATA_2)
# checking the response header
handled = self.table.maybe_preempt()
self.assertEqual(handled.status_code, 200)
self.assertEqual(200, handled.status_code)
def test_inline_edit_update_action_post_not_allowed(self):
# Post request should invoke the cell update table action.
@ -1052,7 +1052,7 @@ class DataTableTests(test.TestCase):
self.table = MyTableNotAllowedInlineEdit(req, TEST_DATA_2)
# checking the response header
handled = self.table.maybe_preempt()
self.assertEqual(handled.status_code, 401)
self.assertEqual(401, handled.status_code)
def test_inline_edit_update_action_post_validation_error(self):
# Name column has required validation, sending blank
@ -1063,9 +1063,9 @@ class DataTableTests(test.TestCase):
self.table = MyTable(req, TEST_DATA_2)
handled = self.table.maybe_preempt()
# Checking the response header.
self.assertEqual(handled.status_code, 400)
self.assertEqual(handled._headers['content-type'],
('Content-Type', 'application/json'))
self.assertEqual(400, handled.status_code)
self.assertEqual(('Content-Type', 'application/json'),
handled._headers['content-type'])
# Checking the response content.
resp = handled
self.assertContains(resp,
@ -1145,13 +1145,13 @@ class DataTableTests(test.TestCase):
self.table.get_object_display(IsA(FakeObject)).AndReturn(None)
self.mox.ReplayAll()
self.assertEqual(self.table.parse_action(action_string),
('my_table', 'toggle', '1'))
self.assertEqual(('my_table', 'toggle', '1'),
self.table.parse_action(action_string))
handled = self.table.maybe_handle()
self.assertEqual(handled.status_code, 302)
self.assertEqual(handled["location"], "/my_url/")
self.assertEqual(list(req._messages)[0].message,
u"Downed Item: N/A")
self.assertEqual(302, handled.status_code)
self.assertEqual("/my_url/", handled["location"])
self.assertEqual(u"Downed Item: N/A",
list(req._messages)[0].message)
def test_table_column_can_be_selected(self):
self.table = MyTableSelectable(self.request, TEST_DATA_6)
@ -1164,16 +1164,16 @@ class DataTableTests(test.TestCase):
name_col = self.table.columns['name']
value_col = self.table.columns['value']
# transform
self.assertEqual(row.cells['id'].data, '1') # Standard attr access
self.assertEqual(row.cells['name'].data, 'custom object_1') # Callable
self.assertEqual('1', row.cells['id'].data) # Standard attr access
self.assertEqual('custom object_1', row.cells['name'].data) # Callable
# name and verbose_name
self.assertEqual(unicode(id_col), "Id")
self.assertEqual(unicode(name_col), "Verbose Name")
self.assertEqual("Id", unicode(id_col))
self.assertEqual("Verbose Name", unicode(name_col))
self.assertIn("sortable", name_col.get_final_attrs().get('class', ""))
# hidden
self.assertEqual(id_col.hidden, True)
self.assertEqual(True, id_col.hidden)
self.assertIn("hide", id_col.get_final_attrs().get('class', ""))
self.assertEqual(name_col.hidden, False)
self.assertEqual(False, name_col.hidden)
self.assertNotIn("hide", name_col.get_final_attrs().get('class', ""))
# link, link_classes, link_attrs and get_link_url
self.assertIn('href="http://example.com/"', row.cells['value'].value)
@ -1182,8 +1182,8 @@ class DataTableTests(test.TestCase):
self.assertIn('data-tip="click for dialog"', row.cells['value'].value)
self.assertIn('href="/auth/login/"', row.cells['status'].value)
# classes
self.assertEqual(value_col.get_final_attrs().get('class', ""),
"green blue sortable anchor normal_column")
self.assertEqual("green blue sortable anchor normal_column",
value_col.get_final_attrs().get('class', ""))
self.assertQuerysetEqual(row.get_cells(),
['<Cell: multi_select, my_table__row__1>',
@ -1198,15 +1198,15 @@ class DataTableTests(test.TestCase):
self.assertIn('checkbox', row1.get_cells()[0].data)
# status
cell_status = row.cells['status'].status
self.assertEqual(row.cells['status'].get_status_class(cell_status),
'status_down')
self.assertEqual('status_down',
row.cells['status'].get_status_class(cell_status))
# status_choices
id_col.status = True
id_col.status_choices = (('1', False), ('2', True))
cell_status = row.cells['id'].status
self.assertEqual(cell_status, False)
self.assertEqual(row.cells['id'].get_status_class(cell_status),
'status_down')
self.assertEqual(False, cell_status)
self.assertEqual('status_down',
row.cells['id'].get_status_class(cell_status))
# Ensure data is not cached on the column across table instances
self.table = MyTable(self.request, TEST_DATA_6)
row = self.table.get_rows()[0]
@ -1275,8 +1275,8 @@ class DataTableViewTests(test.TestCase):
def test_data_table_view(self):
view = self._prepare_view(SingleTableView)
context = view.get_context_data()
self.assertEqual(context['table'].__class__,
SingleTableView.table_class)
self.assertEqual(SingleTableView.table_class,
context['table'].__class__)
def test_data_table_view_not_authorized(self):
view = self._prepare_view(SingleTableViewWithPermissions)
@ -1288,22 +1288,22 @@ class DataTableViewTests(test.TestCase):
self.set_permissions(permissions=['test'])
context = view.get_context_data()
self.assertIn('table', context)
self.assertEqual(context['table'].__class__,
SingleTableViewWithPermissions.table_class)
self.assertEqual(SingleTableViewWithPermissions.table_class,
context['table'].__class__)
def test_multi_table_view_not_authorized(self):
view = self._prepare_view(MultiTableView)
context = view.get_context_data()
self.assertEqual(context['my_table_table'].__class__, MyTable)
self.assertEqual(MyTable, context['my_table_table'].__class__)
self.assertNotIn('table_with_permissions_table', context)
def test_multi_table_view_authorized(self):
view = self._prepare_view(MultiTableView)
self.set_permissions(permissions=['test'])
context = view.get_context_data()
self.assertEqual(context['my_table_table'].__class__, MyTable)
self.assertEqual(context['table_with_permissions_table'].__class__,
TableWithPermissions)
self.assertEqual(MyTable, context['my_table_table'].__class__)
self.assertEqual(TableWithPermissions,
context['table_with_permissions_table'].__class__)
def test_api_filter_table_view(self):
filter_value_param = "my_table__filter__q"
@ -1349,8 +1349,8 @@ class FormsetTableTests(test.TestCase):
table = Table(self.request)
table.data = TEST_DATA_4
formset = table.get_formset()
self.assertEqual(len(formset), 2)
self.assertEqual(2, len(formset))
form = formset[0]
form_data = form.initial
self.assertEqual(form_data['name'], 'object_1')
self.assertEqual(form_data['value'], 2)
self.assertEqual('object_1', form_data['name'])
self.assertEqual(2, form_data['value'])

@ -112,12 +112,12 @@ class TabTests(test.TestCase):
'<TabDelayed: tab_delayed>',
'<TabDisabled: tab_disabled>'])
# Test get_id
self.assertEqual(tg.get_id(), "tab_group")
self.assertEqual("tab_group", tg.get_id())
# get_default_classes
self.assertEqual(tg.get_default_classes(),
horizon_tabs.base.CSS_TAB_GROUP_CLASSES)
self.assertEqual(horizon_tabs.base.CSS_TAB_GROUP_CLASSES,
tg.get_default_classes())
# Test get_tab
self.assertEqual(tg.get_tab("tab_one").slug, "tab_one")
self.assertEqual("tab_one", tg.get_tab("tab_one").slug)
# Test selected is None w/o GET input
self.assertIsNone(tg.selected)
@ -129,33 +129,33 @@ class TabTests(test.TestCase):
tg = Group(self.request)
# active tab w/o selected
self.assertEqual(tg.active, tg.get_tabs()[0])
self.assertEqual(tg.get_tabs()[0], tg.active)
# active tab w/ selected
self.request.GET['tab'] = "tab_group__tab_delayed"
tg = Group(self.request)
self.assertEqual(tg.active, tg.get_tab('tab_delayed'))
self.assertEqual(tg.get_tab('tab_delayed'), tg.active)
# active tab w/ invalid selected
self.request.GET['tab'] = "tab_group__tab_invalid"
tg = Group(self.request)
self.assertEqual(tg.active, tg.get_tabs()[0])
self.assertEqual(tg.get_tabs()[0], tg.active)
# active tab w/ disallowed selected
self.request.GET['tab'] = "tab_group__tab_disallowed"
tg = Group(self.request)
self.assertEqual(tg.active, tg.get_tabs()[0])
self.assertEqual(tg.get_tabs()[0], tg.active)
# active tab w/ disabled selected
self.request.GET['tab'] = "tab_group__tab_disabled"
tg = Group(self.request)
self.assertEqual(tg.active, tg.get_tabs()[0])
self.assertEqual(tg.get_tabs()[0], tg.active)
# active tab w/ non-empty garbage selected
# Note: this entry does not contain the '__' SEPARATOR string.
self.request.GET['tab'] = "<!--"
tg = Group(self.request)
self.assertEqual(tg.active, tg.get_tabs()[0])
self.assertEqual(tg.get_tabs()[0], tg.active)
def test_tab_basics(self):
tg = Group(self.request)
@ -168,13 +168,13 @@ class TabTests(test.TestCase):
self.assertIsNone(tab_disallowed)
# get_id
self.assertEqual(tab_one.get_id(), "tab_group__tab_one")
self.assertEqual("tab_group__tab_one", tab_one.get_id())
# get_default_classes
self.assertEqual(tab_one.get_default_classes(),
horizon_tabs.base.CSS_ACTIVE_TAB_CLASSES)
self.assertEqual(tab_disabled.get_default_classes(),
horizon_tabs.base.CSS_DISABLED_TAB_CLASSES)
self.assertEqual(horizon_tabs.base.CSS_ACTIVE_TAB_CLASSES,
tab_one.get_default_classes())
self.assertEqual(horizon_tabs.base.CSS_DISABLED_TAB_CLASSES,
tab_disabled.get_default_classes())
# load, allowed, enabled
self.assertTrue(tab_one.load)
@ -216,28 +216,28 @@ class TabTests(test.TestCase):
# tab
output = tab_one.render()
self.assertEqual(output.strip(), tab_one.name)
self.assertEqual(tab_one.name, output.strip())
# disabled tab
output = tab_disabled.render()
self.assertEqual(output.strip(), "")
self.assertEqual("", output.strip())
# preload false
output = tab_delayed.render()
self.assertEqual(output.strip(), "")
self.assertEqual("", output.strip())
# preload false w/ active
self.request.GET['tab'] = tab_delayed.get_id()
tg = Group(self.request)
tab_delayed = tg.get_tab("tab_delayed")
output = tab_delayed.render()
self.assertEqual(output.strip(), tab_delayed.name)
self.assertEqual(tab_delayed.name, output.strip())
def test_table_tabs(self):
tab_group = TableTabGroup(self.request)
tabs = tab_group.get_tabs()
# Only one tab, as expected.
self.assertEqual(len(tabs), 1)
self.assertEqual(1, len(tabs))
tab = tabs[0]
# Make sure it's the tab we think it is.
self.assertIsInstance(tab, horizon_tabs.TableTab)
@ -255,9 +255,9 @@ class TabTests(test.TestCase):
'<FakeObject: object_3>'])
context = tab.get_context_data(self.request)
# Make sure our table is loaded into the context correctly
self.assertEqual(context['my_table_table'], table)
self.assertEqual(table, context['my_table_table'])
# Since we only had one table we should get the shortcut name too.
self.assertEqual(context['table'], table)
self.assertEqual(table, context['table'])
def test_tabbed_table_view(self):
view = TabWithTableView.as_view()
@ -273,7 +273,7 @@ class TabTests(test.TestCase):
req = self.factory.get('/', params,
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
res = view(req)
self.assertEqual(res.status_code, 200)
self.assertEqual(200, res.status_code)
# Make sure we got back a row but not a table or body
self.assertContains(res, "<tr", 1)
self.assertContains(res, "<table", 0)
@ -283,8 +283,8 @@ class TabTests(test.TestCase):
action_string = "my_table__toggle__2"
req = self.factory.post('/', {'action': action_string})
res = view(req)
self.assertEqual(res.status_code, 302)
self.assertEqual(res["location"], "/")
self.assertEqual(302, res.status_code)
self.assertEqual("/", res["location"])
# Ensure that lookup errors are raised as such instead of converted
# to TemplateSyntaxErrors.

@ -63,7 +63,7 @@ class TemplateTagTests(test.TestCase):
rendered_str = self.render_template(tag_require='sizeformat',
template_text=text)
self.assertEqual(rendered_str, expected)
self.assertEqual(expected, rendered_str)
def test_size_format_filters_with_string(self):
size_str = ('"test"|diskgbformat', '"limit"|mb_float_format',
@ -76,7 +76,7 @@ class TemplateTagTests(test.TestCase):
rendered_str = self.render_template(tag_require='sizeformat',
template_text=text)
self.assertEqual(rendered_str, expected)
self.assertEqual(expected, rendered_str)
def test_truncate_filter(self):
ctx_string = {'val1': 'he',
@ -90,7 +90,7 @@ class TemplateTagTests(test.TestCase):
rendered_str = self.render_template(tag_require='truncate_filter',
template_text=text,
context={'test': ctx_string})
self.assertEqual(rendered_str, expected)
self.assertEqual(expected, rendered_str)
def test_quota_filter(self):
ctx_string = {'val1': 100,
@ -105,4 +105,4 @@ class TemplateTagTests(test.TestCase):
rendered_str = self.render_template(tag_require='horizon',
template_text=text,
context={'test': ctx_string})
self.assertEqual(rendered_str, expected)
self.assertEqual(expected, rendered_str)

@ -234,7 +234,7 @@ class ValidatorsTests(test.TestCase):
class SecretKeyTests(test.TestCase):
def test_generate_secret_key(self):
key = secret_key.generate_key(32)
self.assertEqual(len(key), 32)
self.assertEqual(32, len(key))
self.assertNotEqual(key, secret_key.generate_key(32))
def test_generate_or_read_key_from_file(self):
@ -242,10 +242,10 @@ class SecretKeyTests(test.TestCase):
key = secret_key.generate_or_read_from_file(key_file)
# Consecutive reads should come from the already existing file:
self.assertEqual(key, secret_key.generate_or_read_from_file(key_file))
self.assertEqual(secret_key.generate_or_read_from_file(key_file), key)
# Key file only be read/writable by user:
self.assertEqual(oct(os.stat(key_file).st_mode & 0o777), "0600")
self.assertEqual("0600", oct(os.stat(key_file).st_mode & 0o777))
os.chmod(key_file, 0o777)
self.assertRaises(secret_key.FilePermissionError,
secret_key.generate_or_read_from_file, key_file)
@ -255,32 +255,32 @@ class SecretKeyTests(test.TestCase):
class FiltersTests(test.TestCase):
def test_replace_underscore_filter(self):
res = filters.replace_underscores("__under_score__")
self.assertEqual(res, " under score ")
self.assertEqual(" under score ", res)
def test_parse_isotime_filter(self):
c = django.template.Context({'time': ''})
t = django.template.Template('{{time|parse_isotime}}')
output = u""
self.assertEqual(t.render(c), output)
self.assertEqual(output, t.render(c))
c = django.template.Context({'time': 'error'})
t = django.template.Template('{{time|parse_isotime}}')
output = u""
self.assertEqual(t.render(c), output)
self.assertEqual(output, t.render(c))
c = django.template.Context({'time': 'error'})
t = django.template.Template('{{time|parse_isotime:"test"}}')
output = u"test"
self.assertEqual(t.render(c), output)
self.assertEqual(output, t.render(c))
c = django.template.Context({'time': '2007-03-04T21:08:12'})
t = django.template.Template('{{time|parse_isotime:"test"}}')
output = u"March 4, 2007, 3:08 p.m."
self.assertEqual(t.render(c), output)
self.assertEqual(output, t.render(c))
adate = '2007-01-25T12:00:00Z'
result = filters.parse_isotime(adate)
@ -294,41 +294,41 @@ class TimeSinceNeverFilterTests(test.TestCase):
def test_timesince_or_never_returns_default_for_empty_string(self):
c = django.template.Context({'time': ''})
t = django.template.Template('{{time|timesince_or_never}}')
self.assertEqual(t.render(c), self.default)
self.assertEqual(self.default, t.render(c))
def test_timesince_or_never_returns_default_for_none(self):
c = django.template.Context({'time': None})
t = django.template.Template('{{time|timesince_or_never}}')
self.assertEqual(t.render(c), self.default)
self.assertEqual(self.default, t.render(c))
def test_timesince_or_never_returns_default_for_gibberish(self):
c = django.template.Context({'time': django.template.Context()})
t = django.template.Template('{{time|timesince_or_never}}')
self.assertEqual(t.render(c), self.default)
self.assertEqual(self.default, t.render(c))
def test_timesince_or_never_returns_with_custom_default(self):
custom = "Hello world"
c = django.template.Context({'date': ''})
t = django.template.Template('{{date|timesince_or_never:"%s"}}'
% custom)
self.assertEqual(t.render(c), custom)
self.assertEqual(custom, t.render(c))
def test_timesince_or_never_returns_with_custom_empty_string_default(self):
c = django.template.Context({'date': ''})
t = django.template.Template('{{date|timesince_or_never:""}}')
self.assertEqual(t.render(c), "")
self.assertEqual("", t.render(c))
def test_timesince_or_never_returns_same_output_as_django_date(self):
d = datetime.date(year=2014, month=3, day=7)
c = django.template.Context({'date': d})
t = django.template.Template('{{date|timesince_or_never}}')
self.assertEqual(t.render(c), defaultfilters.timesince(d))
self.assertEqual(defaultfilters.timesince(d), t.render(c))
def test_timesince_or_never_returns_same_output_as_django_datetime(self):
now = datetime.datetime.now()
c = django.template.Context({'date': now})
t = django.template.Template('{{date|timesince_or_never}}')
self.assertEqual(t.render(c), defaultfilters.timesince(now))
self.assertEqual(defaultfilters.timesince(now), t.render(c))
class MemoizedTests(test.TestCase):
@ -346,12 +346,12 @@ class MemoizedTests(test.TestCase):
for x in range(0, 5):
non_cached_calls(1)
self.assertEqual(len(values_list), 5)
self.assertEqual(5, len(values_list))
values_list = []
for x in range(0, 5):
cache_calls(1)
self.assertEqual(len(values_list), 1)
self.assertEqual(1, len(values_list))
class GetPageSizeTests(test.TestCase):

@ -147,21 +147,21 @@ class WorkflowsTests(test.TestCase):
['<TestStepOne: test_action_one>',
'<TestExtraStep: test_action_three>',
'<TestStepTwo: test_action_two>'])
self.assertEqual(flow.depends_on, set(['project_id']))
self.assertEqual(