From 301b5337af617e32091c033dc96380f3658854c6 Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Fri, 29 Dec 2023 13:21:36 +0000 Subject: [PATCH] Revert "Fix test failures for django main" This reverts commit ded80d333e1cc7c8e37c91d075f9728d493aa65c. --- tests/test_admin.py | 106 ++++++++++------------------------- tests/test_datastructures.py | 27 +++------ tests/test_models.py | 32 +++-------- 3 files changed, 48 insertions(+), 117 deletions(-) diff --git a/tests/test_admin.py b/tests/test_admin.py index 1ff3fbe7..14a4ba9e 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -268,21 +268,12 @@ def test_only_fetches_latest_content_records(self): with self.login_user_context(self.get_superuser()): response = self.client.get(self.get_admin_url(PollContent, "changelist")) - try: - self.assertQuerySetEqual( - response.context["cl"].queryset, - [poll_content1.pk, poll_content2.pk, poll_content3.pk], - transform=lambda x: x.pk, - ordered=False, - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - response.context["cl"].queryset, - [poll_content1.pk, poll_content2.pk, poll_content3.pk], - transform=lambda x: x.pk, - ordered=False, - ) + self.assertQuerysetEqual( + response.context["cl"].queryset, + [poll_content1.pk, poll_content2.pk, poll_content3.pk], + transform=lambda x: x.pk, + ordered=False, + ) def test_records_filtering_is_generic(self): """Check there's nothing specific to polls hardcoded in @@ -300,21 +291,12 @@ def test_records_filtering_is_generic(self): with self.login_user_context(self.get_superuser()): response = self.client.get(self.get_admin_url(BlogContent, "changelist")) - try: - self.assertQuerySetEqual( - response.context["cl"].queryset, - [blog_content1.pk, blog_content2.pk], - transform=lambda x: x.pk, - ordered=False, - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - response.context["cl"].queryset, - [blog_content1.pk, blog_content2.pk], - transform=lambda x: x.pk, - ordered=False, - ) + self.assertQuerysetEqual( + response.context["cl"].queryset, + [blog_content1.pk, blog_content2.pk], + transform=lambda x: x.pk, + ordered=False, + ) def test_default_changelist_view_language_on_polls_with_language_content(self): """A multilingual model shows the correct values when @@ -2142,22 +2124,12 @@ def test_compare_view_has_version_data_in_context_when_no_get_param(self): self.assertNotIn("v2", context) self.assertNotIn("v2_preview_url", context) self.assertIn("version_list", context) - try: - self.assertQuerySetEqual( - context["version_list"], - [versions[0].pk, versions[1].pk], - transform=lambda o: o.pk, - ordered=False, - ) - - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - context["version_list"], - [versions[0].pk, versions[1].pk], - transform=lambda o: o.pk, - ordered=False, - ) + self.assertQuerysetEqual( + context["version_list"], + [versions[0].pk, versions[1].pk], + transform=lambda o: o.pk, + ordered=False, + ) def test_compare_view_has_version_data_in_context_when_version2_in_get_param(self): """When the url for the compare view does have the compare_to @@ -2212,21 +2184,12 @@ def test_compare_view_has_version_data_in_context_when_version2_in_get_param(sel self.disable_toolbar_params, ) self.assertIn("version_list", context) - try: - self.assertQuerySetEqual( - context["version_list"], - [versions[0].pk, versions[1].pk, versions[2].pk], - transform=lambda o: o.pk, - ordered=False, - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - context["version_list"], - [versions[0].pk, versions[1].pk, versions[2].pk], - transform=lambda o: o.pk, - ordered=False, - ) + self.assertQuerysetEqual( + context["version_list"], + [versions[0].pk, versions[1].pk, versions[2].pk], + transform=lambda o: o.pk, + ordered=False, + ) @patch("django.contrib.messages.add_message") def test_edit_compare_view_handles_nonexistent_v1(self, mocked_messages): @@ -2347,21 +2310,12 @@ def test_grouper_filtering(self): self.assertEqual(response.status_code, 200) self.assertIn("cl", response.context) - try: - self.assertQuerySetEqual( - response.context["cl"].queryset, - [pv.pk], - transform=lambda x: x.pk, - ordered=False, - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - response.context["cl"].queryset, - [pv.pk], - transform=lambda x: x.pk, - ordered=False, - ) + self.assertQuerysetEqual( + response.context["cl"].queryset, + [pv.pk], + transform=lambda x: x.pk, + ordered=False, + ) def test_view_language_on_poll_with_no_language_content(self): """A multi lingual model shows an empty version list when no diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index 6fc4794c..cdea40c9 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -31,21 +31,12 @@ def test_distinct_groupers(self): grouper_field_name="poll", copy_function=default_copy, ) - try: - self.assertQuerySetEqual( - versionable.distinct_groupers(), - [latest_poll1_version.content.pk, latest_poll2_version.content.pk], - transform=lambda x: x.pk, - ordered=False, - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - versionable.distinct_groupers(), - [latest_poll1_version.content.pk, latest_poll2_version.content.pk], - transform=lambda x: x.pk, - ordered=False, - ) + self.assertQuerysetEqual( + versionable.distinct_groupers(), + [latest_poll1_version.content.pk, latest_poll2_version.content.pk], + transform=lambda x: x.pk, + ordered=False, + ) def test_queryset_filter_for_distinct_groupers(self): poll1_archived_version = PollVersionFactory( @@ -68,7 +59,7 @@ def test_queryset_filter_for_distinct_groupers(self): qs_published_filter = {"versions__state__in": [PUBLISHED]} # Should be one published version - self.assertQuerySetEqual( + self.assertQuerysetEqual( versionable.distinct_groupers(**qs_published_filter), [poll1_published_version.content.pk], transform=lambda x: x.pk, @@ -77,7 +68,7 @@ def test_queryset_filter_for_distinct_groupers(self): qs_archive_filter = {"versions__state__in": [ARCHIVED]} # Should be two archived versions - self.assertQuerySetEqual( + self.assertQuerysetEqual( versionable.distinct_groupers(**qs_archive_filter), [poll1_archived_version.content.pk, poll2_archived_version.content.pk], transform=lambda x: x.pk, @@ -98,7 +89,7 @@ def test_for_grouper(self): copy_function=default_copy, ) - self.assertQuerySetEqual( + self.assertQuerysetEqual( versionable.for_grouper(self.initial_version.content.poll), [self.initial_version.content.pk, poll1_version2.content.pk], transform=lambda x: x.pk, diff --git a/tests/test_models.py b/tests/test_models.py index 5b074af4..98ac5b3e 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -261,22 +261,12 @@ def test_filter_by_grouper(self): versions_for_grouper = Version.objects.filter_by_grouper(poll) - try: - self.assertQuerySetEqual( - versions_for_grouper, - [versions[0].pk, versions[1].pk], - transform=lambda o: o.pk, - ordered=False, - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual( - versions_for_grouper, - [versions[0].pk, versions[1].pk], - transform=lambda o: o.pk, - ordered=False, - ) - + self.assertQuerysetEqual( + versions_for_grouper, + [versions[0].pk, versions[1].pk], + transform=lambda o: o.pk, + ordered=False, + ) def test_filter_by_grouper_doesnt_include_other_content_types(self): """Regression test for a bug in which filtering by content_type @@ -288,13 +278,9 @@ def test_filter_by_grouper_doesnt_include_other_content_types(self): versions_for_grouper = Version.objects.filter_by_grouper(pv.content.poll) # Only poll version included - try: - self.assertQuerySetEqual( - versions_for_grouper, [pv.pk], transform=lambda o: o.pk, ordered=False - ) - except AttributeError: - # django 3.2 doesn't have assertQuerySetEqual - self.assertQuerysetEqual(versions_for_grouper, [pv.pk], transform=lambda o: o.pk, ordered=False) + self.assertQuerysetEqual( + versions_for_grouper, [pv.pk], transform=lambda o: o.pk, ordered=False + ) class ModelsTestCase(CMSTestCase):