Specify transform=repr in assertQuerysetEqual()

Previously "repr" was automatically applied to "qs" argument of
assertQuerysetEqual() and most horizon unittest behaviors assume it.
It was deprecated in Django 3.2 and removed in Django 4.1. We need to
specify transform=repr explicitly to use the existing behavior.

[1] https://docs.djangoproject.com/en/3.2/topics/testing/tools/#django.test.TransactionTestCase.assertQuerysetEqual

Closes-Bug: #2038474
Change-Id: Ie7c7e9a1efc492889639e25509c8e614268c1d26
This commit is contained in:
Thomas Goirand 2023-10-04 11:44:00 +02:00 committed by Akihiro Motoki
parent 40e416b8fc
commit 8770753fcc
12 changed files with 120 additions and 66 deletions

View File

@ -432,7 +432,8 @@ class DataTableTests(test.TestCase):
'<Column: value>',
'<Column: optional>',
'<Column: status>',
'<MyColumn: actions>'])
'<MyColumn: actions>'],
transform=repr)
# Actions (these also test ordering)
self.assertQuerysetEqual(list(self.table.base_actions.values()),
['<MyBatchAction: batch>',
@ -440,18 +441,21 @@ class DataTableTests(test.TestCase):
'<MyAction: delete>',
'<MyFilterAction: filter>',
'<MyLinkAction: login>',
'<MyToggleAction: toggle>'])
'<MyToggleAction: toggle>'],
transform=repr)
self.assertQuerysetEqual(self.table.get_table_actions(),
['<MyFilterAction: filter>',
'<MyAction: delete>',
'<MyBatchAction: batch>',
'<MyBatchActionWithHelpText: batch_help>'])
'<MyBatchActionWithHelpText: batch_help>'],
transform=repr)
self.assertQuerysetEqual(self.table.get_row_actions(TEST_DATA[0]),
['<MyAction: delete>',
'<MyLinkAction: login>',
'<MyBatchAction: batch>',
'<MyToggleAction: toggle>',
'<MyBatchActionWithHelpText: batch_help>'])
'<MyBatchActionWithHelpText: batch_help>'],
transform=repr)
# Auto-generated columns
multi_select = self.table.columns['multi_select']
self.assertEqual("multi_select", multi_select.auto)
@ -472,7 +476,9 @@ class DataTableTests(test.TestCase):
self.assertEqual(TEST_DATA, self.table.data)
# The column "restricted" is not rendered because of policy
expected_columns = ['<Column: name>']
self.assertQuerysetEqual(self.table.get_columns(), expected_columns)
self.assertQuerysetEqual(self.table.get_columns(),
expected_columns,
transform=repr)
@override_settings(POLICY_CHECK_FUNCTION=lambda *args: True)
def test_table_column_policy_allowed(self):
@ -480,7 +486,8 @@ class DataTableTests(test.TestCase):
self.assertEqual(TEST_DATA, self.table.data)
# Policy check returns True so the column "restricted" is rendered
expected_columns = ['<Column: name>', '<Column: restricted>']
self.assertQuerysetEqual(self.table.get_columns(), expected_columns)
self.assertQuerysetEqual(self.table.get_columns(), expected_columns,
transform=repr)
def test_table_force_no_multiselect(self):
class TempTable(MyTable):
@ -492,7 +499,8 @@ class DataTableTests(test.TestCase):
self.table = TempTable(self.request, TEST_DATA)
self.assertQuerysetEqual(self.table.get_columns(),
['<Column: id>',
'<Column: actions>'])
'<Column: actions>'],
transform=repr)
def test_table_force_no_actions_column(self):
class TempTable(MyTable):
@ -504,7 +512,8 @@ class DataTableTests(test.TestCase):
self.table = TempTable(self.request, TEST_DATA)
self.assertQuerysetEqual(self.table.get_columns(),
['<Column: multi_select>',
'<Column: id>'])
'<Column: id>'],
transform=repr)
def test_table_natural_no_inline_editing(self):
class TempTable(MyTable):
@ -530,7 +539,8 @@ class DataTableTests(test.TestCase):
self.table = TempTable(self.request, TEST_DATA)
self.assertQuerysetEqual(self.table.get_columns(),
['<Column: multi_select>',
'<Column: id>'])
'<Column: id>'],
transform=repr)
def test_table_natural_no_multiselect(self):
class TempTable(MyTable):
@ -540,7 +550,8 @@ class DataTableTests(test.TestCase):
self.table = TempTable(self.request, TEST_DATA)
self.assertQuerysetEqual(self.table.get_columns(),
['<Column: id>',
'<Column: actions>'])
'<Column: actions>'],
transform=repr)
def test_table_column_inheritance(self):
class TempTable(MyTable):
@ -561,25 +572,30 @@ class DataTableTests(test.TestCase):
'<Column: optional>',
'<Column: excluded>',
'<Column: extra>',
'<Column: actions>'])
'<Column: actions>'],
transform=repr)
def test_table_construction(self):
self.table = MyTable(self.request, TEST_DATA)
# Verify we retrieve the right columns for headers
columns = self.table.get_columns()
self.assertQuerysetEqual(columns, ['<MyColumn: multi_select>',
'<Column: id>',
'<Column: name>',
'<Column: value>',
'<Column: optional>',
'<Column: status>',
'<MyColumn: actions>'])
self.assertQuerysetEqual(columns,
['<MyColumn: multi_select>',
'<Column: id>',
'<Column: name>',
'<Column: value>',
'<Column: optional>',
'<Column: status>',
'<MyColumn: actions>'],
transform=repr)
# Verify we retrieve the right rows from our data
rows = self.table.get_rows()
self.assertQuerysetEqual(rows, ['<MyRow: my_table__row__1>',
'<MyRow: my_table__row__2>',
'<MyRow: my_table__row__3>',
'<MyRow: my_table__row__4>'])
self.assertQuerysetEqual(rows,
['<MyRow: my_table__row__1>',
'<MyRow: my_table__row__2>',
'<MyRow: my_table__row__3>',
'<MyRow: my_table__row__4>'],
transform=repr)
# Verify each row contains the right cells
self.assertQuerysetEqual(rows[0].get_cells(),
['<Cell: multi_select, my_table__row__1>',
@ -588,7 +604,8 @@ class DataTableTests(test.TestCase):
'<Cell: value, my_table__row__1>',
'<Cell: optional, my_table__row__1>',
'<Cell: status, my_table__row__1>',
'<Cell: actions, my_table__row__1>'])
'<Cell: actions, my_table__row__1>'],
transform=repr)
def test_table_column(self):
self.table = MyTable(self.request, TEST_DATA)
@ -814,7 +831,8 @@ class DataTableTests(test.TestCase):
req = self.factory.post('/my_url/', {action_string: '2'})
self.table = TempTable(req, TEST_DATA)
self.assertQuerysetEqual(self.table.get_table_actions(),
['<NameFilterAction: filter>'])
['<NameFilterAction: filter>'],
transform=repr)
handled = self.table.maybe_handle()
self.assertIsNone(handled)
self.assertQuerysetEqual(self.table.filtered_data,
@ -985,7 +1003,8 @@ class DataTableTests(test.TestCase):
['<MyFilterAction: filter>',
'<MyAction: delete>',
'<MyBatchAction: batch>',
'<MyBatchActionWithHelpText: batch_help>'])
'<MyBatchActionWithHelpText: batch_help>'],
transform=repr)
# Zero objects in table
# BatchAction not available
@ -993,7 +1012,8 @@ class DataTableTests(test.TestCase):
self.table = MyTable(req, None)
self.assertQuerysetEqual(self.table.get_table_actions(),
['<MyFilterAction: filter>',
'<MyAction: delete>'])
'<MyAction: delete>'],
transform=repr)
# Filtering
action_string = "my_table__filter__q"
@ -1209,7 +1229,8 @@ class DataTableTests(test.TestCase):
'<Cell: name, my_table__row__1>',
'<Cell: value, my_table__row__1>',
'<Cell: status, my_table__row__1>',
])
],
transform=repr)
# can_be_selected = False
self.assertEqual("", row.get_cells()[0].data)
# can_be_selected = True

View File

@ -142,10 +142,12 @@ class TabTests(test.TestCase):
# "tab_disallowed" should NOT be in this list.
# "tab_with_policy" should be present, since our policy check
# always passes
self.assertQuerysetEqual(tabs, ['<TabOne: tab_one>',
'<TabDelayed: tab_delayed>',
'<TabDisabled: tab_disabled>',
'<TabWithPolicy: tab_with_policy>'])
self.assertQuerysetEqual(tabs,
['<TabOne: tab_one>',
'<TabDelayed: tab_delayed>',
'<TabDisabled: tab_disabled>',
'<TabWithPolicy: tab_with_policy>'],
transform=repr)
# Test get_id
self.assertEqual("tab_group", tg.get_id())
# get_default_classes
@ -169,9 +171,11 @@ class TabTests(test.TestCase):
# "tab_disallowed" should NOT be in this list, it's not allowed
# "tab_with_policy" should also not be present as its
# policy check failed
self.assertQuerysetEqual(tabs, ['<TabOne: tab_one>',
'<TabDelayed: tab_delayed>',
'<TabDisabled: tab_disabled>'])
self.assertQuerysetEqual(tabs,
['<TabOne: tab_one>',
'<TabDelayed: tab_delayed>',
'<TabDisabled: tab_disabled>'],
transform=repr)
@test.update_settings(
HORIZON_CONFIG={'extra_tabs': {
@ -187,9 +191,11 @@ class TabTests(test.TestCase):
tabs = tg.get_tabs()
# "tab_disallowed" should NOT be in this list.
# Other tabs must be ordered in the priorities in HORIZON_CONFIG.
self.assertQuerysetEqual(tabs, ['<TabOne: tab_one>',
'<TabDisabled: tab_disabled>',
'<TabDelayed: tab_delayed>'])
self.assertQuerysetEqual(tabs,
['<TabOne: tab_one>',
'<TabDisabled: tab_disabled>',
'<TabDelayed: tab_delayed>'],
transform=repr)
def test_tab_group_active_tab(self):
tg = Group(self.request)

View File

@ -154,7 +154,8 @@ class HorizonTests(BaseHorizonTests):
self.assertQuerysetEqual(horizon.get_dashboards(),
['<Dashboard: cats>',
'<Dashboard: dogs>',
'<Dashboard: mydash>'])
'<Dashboard: mydash>'],
transform=repr)
# Removal
self.assertEqual(3, len(base.Horizon._registry))
@ -177,7 +178,8 @@ class HorizonTests(BaseHorizonTests):
['<Dashboard: cats>',
'<Dashboard: dogs>',
'<Dashboard: mydash>',
'<Dashboard: mydash2>'])
'<Dashboard: mydash2>'],
transform=repr)
# Removal
self.assertEqual(4, len(base.Horizon._registry))
@ -203,7 +205,8 @@ class HorizonTests(BaseHorizonTests):
self.assertEqual(base.Horizon, cats._registered_with)
self.assertQuerysetEqual(cats.get_panels(),
['<Panel: kittens>',
'<Panel: tigers>'])
'<Panel: tigers>'],
transform=repr)
self.assertEqual("/cats/", cats.get_absolute_url())
self.assertEqual("Cats", cats.name)
@ -211,11 +214,13 @@ class HorizonTests(BaseHorizonTests):
# as a panel group.
cats.register(MyPanel)
self.assertQuerysetEqual(list(cats.get_panel_groups()['other']),
['<Panel: myslug>'])
['<Panel: myslug>'],
transform=repr)
# Test that panels defined as a tuple still return a PanelGroup
dogs = horizon.get_dashboard("dogs")
self.assertQuerysetEqual(list(dogs.get_panel_groups().values()),
['<PanelGroup: default>'])
['<PanelGroup: default>'],
transform=repr)
# Test registering a module with a dashboard that defines panels
# as a tuple.
@ -223,7 +228,8 @@ class HorizonTests(BaseHorizonTests):
dogs.register(MyPanel)
self.assertQuerysetEqual(dogs.get_panels(),
['<Panel: puppies>',
'<Panel: myslug>'])
'<Panel: myslug>'],
transform=repr)
cats.unregister(MyPanel)
dogs.unregister(MyPanel)
@ -424,7 +430,8 @@ class CustomPanelTests(BaseHorizonTests):
cats = horizon.get_dashboard("cats")
self.assertEqual("WildCats", cats.name)
self.assertQuerysetEqual(cats.get_panels(),
['<Panel: kittens>'])
['<Panel: kittens>'],
transform=repr)
with self.assertRaises(base.NotRegistered):
horizon.get_dashboard("dogs")
@ -545,12 +552,14 @@ class RbacHorizonTests(test.TestCase):
cats = horizon.get_dashboard("cats")
self.assertEqual(cats._registered_with, base.Horizon)
self.assertQuerysetEqual(cats.get_panels(),
['<Panel: rbac_panel_no>'])
['<Panel: rbac_panel_no>'],
transform=repr)
self.assertFalse(cats.can_access(context))
dogs = horizon.get_dashboard("dogs")
self.assertEqual(dogs._registered_with, base.Horizon)
self.assertQuerysetEqual(dogs.get_panels(),
['<Panel: rbac_panel_yes>'])
['<Panel: rbac_panel_yes>'],
transform=repr)
self.assertTrue(dogs.can_access(context))

View File

@ -203,7 +203,8 @@ class WorkflowsTests(test.TestCase):
self.assertQuerysetEqual(flow.steps,
['<StepOne: action_one>',
'<StepThree: action_three>',
'<StepTwo: action_two>'])
'<StepTwo: action_two>'],
transform=repr)
self.assertEqual(set(['project_id']), flow.depends_on)
@test.update_settings(HORIZON_CONFIG={'extra_steps': {
@ -221,8 +222,8 @@ class WorkflowsTests(test.TestCase):
['<StepOne: action_one>',
'<StepThree: action_three>',
'<StepTwo: action_two>',
'<StepFour: action_four>',
])
'<StepFour: action_four>'],
transform=repr)
def test_step_construction(self):
step_one = StepOne(WorkflowForTesting(self.request))
@ -327,14 +328,16 @@ class WorkflowsTests(test.TestCase):
flow = WorkflowForTesting(req)
self.assertQuerysetEqual(flow.steps,
['<StepOne: action_one>',
'<StepTwo: action_two>'])
'<StepTwo: action_two>'],
transform=repr)
WorkflowForTesting.register(StepThree)
flow = WorkflowForTesting(req)
self.assertQuerysetEqual(flow.steps,
['<StepOne: action_one>',
'<StepThree: action_three>',
'<StepTwo: action_two>'])
'<StepTwo: action_two>'],
transform=repr)
def test_workflow_unregister_unexisting_workflow(self):
with self.assertRaises(base.NotRegistered):
@ -360,7 +363,8 @@ class WorkflowsTests(test.TestCase):
("horizon.test",))
self.assertQuerysetEqual(flow.steps,
['<StepOne: action_one>',
'<StepTwo: action_two>'])
'<StepTwo: action_two>'],
transform=repr)
self.set_permissions(['test'])
self.request.user = self.user
@ -368,7 +372,8 @@ class WorkflowsTests(test.TestCase):
self.assertQuerysetEqual(flow.steps,
['<StepOne: action_one>',
'<AdminStep: admin_action>',
'<StepTwo: action_two>'])
'<StepTwo: action_two>'],
transform=repr)
def test_has_allowed(self):
WorkflowForTesting.register(DisabledStep)
@ -377,7 +382,8 @@ class WorkflowsTests(test.TestCase):
# even though DisabledStep is registered.
self.assertQuerysetEqual(flow.steps,
['<StepOne: action_one>',
'<StepTwo: action_two>'])
'<StepTwo: action_two>'],
transform=repr)
def test_step_is_hidden_on_policy(self):
self.policy_patcher.stop()

View File

@ -52,7 +52,8 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
self.assertQuerysetEqual(
workflow.steps,
['<SetAggregateInfoStep: set_aggregate_info>',
'<AddHostsToAggregateStep: add_host_to_aggregate>'])
'<AddHostsToAggregateStep: add_host_to_aggregate>'],
transform=repr)
self.mock_service_list.assert_called_once_with(
test.IsHttpRequest(),
binary='nova-compute')

View File

@ -101,6 +101,7 @@ class ServicesViewTests(test.BaseAdminViewTests):
quotas_tab = res.context['tab_group'].get_tab(slug)
self.assertQuerysetEqual(quotas_tab._tables[slug].data,
expected_data,
transform=repr,
ordered=False)

View File

@ -254,7 +254,8 @@ class CreateFlavorWorkflowTests(BaseFlavorWorkflowTests):
self.assertQuerysetEqual(
workflow.steps,
['<CreateFlavorInfo: createflavorinfoaction>',
'<CreateFlavorAccess: flavor_access>'])
'<CreateFlavorAccess: flavor_access>'],
transform=repr)
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
@test.create_mocks({api.keystone: ('tenant_list',),
@ -471,7 +472,8 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
self.assertQuerysetEqual(
workflow.steps,
['<UpdateFlavorAccess: flavor_access>'])
['<UpdateFlavorAccess: flavor_access>'],
transform=repr)
step = workflow.get_step("flavor_access")
field_name = step.get_member_field_name('member')

View File

@ -76,7 +76,8 @@ class SystemInfoViewTests(test.BaseAdminViewTests):
network_agents_tab = res.context['tab_group'].get_tab('network_agents')
self.assertQuerysetEqual(
network_agents_tab._tables['network_agents'].data,
[agent.__repr__() for agent in self.agents.list()]
[agent.__repr__() for agent in self.agents.list()],
transform=repr
)
def test_cinder_index(self):
@ -85,5 +86,6 @@ class SystemInfoViewTests(test.BaseAdminViewTests):
get_tab('cinder_services')
self.assertQuerysetEqual(
cinder_services_tab._tables['cinder_services'].data,
[service.__repr__() for service in self.cinder_services.list()]
[service.__repr__() for service in self.cinder_services.list()],
transform=repr
)

View File

@ -202,7 +202,8 @@ class CreateDomainWorkflowTests(test.BaseAdminViewTests):
workflows.CreateDomain.name)
self.assertQuerysetEqual(workflow.steps,
['<CreateDomainInfo: create_domain>', ])
['<CreateDomainInfo: create_domain>'],
transform=repr)
@test.create_mocks({api.keystone: ('domain_create', )})
def test_add_domain_post(self):
@ -300,7 +301,8 @@ class UpdateDomainWorkflowTests(test.BaseAdminViewTests):
workflow.steps,
['<UpdateDomainInfo: update_domain>',
'<UpdateDomainUsers: update_user_members>',
'<UpdateDomainGroups: update_group_members>'])
'<UpdateDomainGroups: update_group_members>'],
transform=repr)
self.mock_domain_get.assert_called_once_with(test.IsHttpRequest(), '1')
self.assert_mock_multiple_calls_with_same_arguments(

View File

@ -209,7 +209,8 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
workflow.steps,
['<CreateProjectInfo: createprojectinfoaction>',
'<UpdateProjectMembers: update_members>',
'<UpdateProjectGroups: update_group_members>'])
'<UpdateProjectGroups: update_group_members>'],
transform=repr)
self.mock_get_default_domain.assert_called_once_with(
test.IsHttpRequest())
@ -581,7 +582,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
workflow.steps,
['<UpdateProjectInfo: update_info>',
'<UpdateProjectMembers: update_members>',
'<UpdateProjectGroups: update_group_members>'])
'<UpdateProjectGroups: update_group_members>'],
transform=repr)
self.mock_tenant_get.assert_called_once_with(
test.IsHttpRequest(), self.tenant.id, admin=True)
@ -1009,7 +1011,8 @@ class UpdateQuotasWorkflowTests(test.BaseAdminViewTests):
self.assertQuerysetEqual(
workflow.steps,
['<UpdateComputeQuota: update_compute_quotas>',
'<UpdateVolumeQuota: update_volume_quotas>'])
'<UpdateVolumeQuota: update_volume_quotas>'],
transform=repr)
self.mock_get_disabled_quotas.assert_called_once_with(
test.IsHttpRequest())

View File

@ -2214,7 +2214,8 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin):
'Disk Partition')
self.assertQuerysetEqual(workflow.steps,
['<SetFlavorChoice: flavor_choice>',
'<SetAdvanced: setadvancedaction>'])
'<SetAdvanced: setadvancedaction>'],
transform=repr)
option = '<option value="%s">%s</option>'
def is_original_flavor(server, flavor, nova_api_lt_2_47):

View File

@ -387,7 +387,7 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
expected_objs = ['<CreateNetworkInfo: createnetworkinfoaction>',
'<CreateSubnetInfo: createsubnetinfoaction>',
'<CreateSubnetDetail: createsubnetdetailaction>']
self.assertQuerysetEqual(workflow.steps, expected_objs)
self.assertQuerysetEqual(workflow.steps, expected_objs, transform=repr)
self._check_is_extension_supported({'network_availability_zone': 1,
'subnet_allocation': 1})
self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest())