Skip to content

Commit

Permalink
Fix test failures for django main
Browse files Browse the repository at this point in the history
  • Loading branch information
marksweb committed Dec 29, 2023
1 parent 2f5e414 commit ded80d3
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 48 deletions.
106 changes: 76 additions & 30 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,21 @@ 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"))

self.assertQuerysetEqual(
response.context["cl"].queryset,
[poll_content1.pk, poll_content2.pk, poll_content3.pk],
transform=lambda x: x.pk,
ordered=False,
)
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,
)

def test_records_filtering_is_generic(self):
"""Check there's nothing specific to polls hardcoded in
Expand All @@ -291,12 +300,21 @@ 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"))

self.assertQuerysetEqual(
response.context["cl"].queryset,
[blog_content1.pk, blog_content2.pk],
transform=lambda x: x.pk,
ordered=False,
)
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,
)

def test_default_changelist_view_language_on_polls_with_language_content(self):
"""A multilingual model shows the correct values when
Expand Down Expand Up @@ -2124,12 +2142,22 @@ 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)
self.assertQuerysetEqual(
context["version_list"],
[versions[0].pk, versions[1].pk],
transform=lambda o: o.pk,
ordered=False,
)
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,
)

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
Expand Down Expand Up @@ -2184,12 +2212,21 @@ def test_compare_view_has_version_data_in_context_when_version2_in_get_param(sel
self.disable_toolbar_params,
)
self.assertIn("version_list", context)
self.assertQuerysetEqual(
context["version_list"],
[versions[0].pk, versions[1].pk, versions[2].pk],
transform=lambda o: o.pk,
ordered=False,
)
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,
)

@patch("django.contrib.messages.add_message")
def test_edit_compare_view_handles_nonexistent_v1(self, mocked_messages):
Expand Down Expand Up @@ -2310,12 +2347,21 @@ def test_grouper_filtering(self):

self.assertEqual(response.status_code, 200)
self.assertIn("cl", response.context)
self.assertQuerysetEqual(
response.context["cl"].queryset,
[pv.pk],
transform=lambda x: x.pk,
ordered=False,
)
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,
)

def test_view_language_on_poll_with_no_language_content(self):
"""A multi lingual model shows an empty version list when no
Expand Down
27 changes: 18 additions & 9 deletions tests/test_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ def test_distinct_groupers(self):
grouper_field_name="poll",
copy_function=default_copy,
)
self.assertQuerysetEqual(
versionable.distinct_groupers(),
[latest_poll1_version.content.pk, latest_poll2_version.content.pk],
transform=lambda x: x.pk,
ordered=False,
)
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,
)

def test_queryset_filter_for_distinct_groupers(self):
poll1_archived_version = PollVersionFactory(
Expand All @@ -59,7 +68,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,
Expand All @@ -68,7 +77,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,
Expand All @@ -89,7 +98,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,
Expand Down
32 changes: 23 additions & 9 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,22 @@ def test_filter_by_grouper(self):

versions_for_grouper = Version.objects.filter_by_grouper(poll)

self.assertQuerysetEqual(
versions_for_grouper,
[versions[0].pk, versions[1].pk],
transform=lambda o: o.pk,
ordered=False,
)
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,
)


def test_filter_by_grouper_doesnt_include_other_content_types(self):
"""Regression test for a bug in which filtering by content_type
Expand All @@ -278,9 +288,13 @@ 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
self.assertQuerysetEqual(
versions_for_grouper, [pv.pk], transform=lambda o: o.pk, ordered=False
)
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)


class ModelsTestCase(CMSTestCase):
Expand Down

0 comments on commit ded80d3

Please sign in to comment.