From 68065c94ef61bf44147c35a7159c24eac800f6e3 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 30 Jun 2022 11:35:02 +0200 Subject: [PATCH] Explicitely set transform=repr in assertQuerysetEquals --- gestioncof/tests/test_views.py | 41 +++++++++++++++++++++++++--------- kfet/auth/tests.py | 1 + kfet/tests/test_tests_utils.py | 1 + kfet/tests/test_views.py | 23 ++++++++++++++----- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/gestioncof/tests/test_views.py b/gestioncof/tests/test_views.py index d4955732..6f788180 100644 --- a/gestioncof/tests/test_views.py +++ b/gestioncof/tests/test_views.py @@ -194,7 +194,9 @@ class RegistrationViewTests(ViewTestCaseMixin, TestCase): ) er = e.eventregistration_set.get(user=self.users["user"]) - self.assertQuerysetEqual(er.options.all(), map(repr, [oc1, oc3]), ordered=False) + self.assertQuerysetEqual( + er.options.all(), map(repr, [oc1, oc3]), transform=repr, ordered=False + ) self.assertCountEqual( er.comments.values_list("content", flat=True), ["comment 1"] ) @@ -299,10 +301,10 @@ class RegistrationAutocompleteViewTests(MockLDAPMixin, ViewTestCaseMixin, TestCa raise ValueError("Unexpected section name: {}".format(section.name)) self.assertQuerysetEqual( - others, map(str, expected_others), ordered=False, transform=str + others, map(str, expected_others), transform=str, ordered=False ) self.assertQuerysetEqual( - members, map(str, expected_members), ordered=False, transform=str + members, map(str, expected_members), transform=str, ordered=False ) self.assertSetEqual( set(clippers), set(map(LDAPSearch().result_verbose_name, expected_clippers)) @@ -646,7 +648,10 @@ class ClubListViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(r.status_code, 200) self.assertQuerysetEqual( - r.context["owned_clubs"], map(repr, [self.c1, self.c2]), ordered=False + r.context["owned_clubs"], + map(repr, [self.c1, self.c2]), + transform=repr, + ordered=False, ) @@ -948,7 +953,10 @@ class EventViewTests(ViewTestCaseMixin, TestCase): er = self.e.eventregistration_set.get(user=self.users["user"]) self.assertQuerysetEqual( - er.options.all(), map(repr, [self.oc1, self.oc3, self.oc4]), ordered=False + er.options.all(), + map(repr, [self.oc1, self.oc3, self.oc4]), + transform=repr, + ordered=False, ) # TODO: Make the view care about comments. # self.assertQuerysetEqual( @@ -973,7 +981,9 @@ class EventViewTests(ViewTestCaseMixin, TestCase): self.assertIn(self.post_expected_message, get_messages(r.wsgi_request)) er.refresh_from_db() - self.assertQuerysetEqual(er.options.all(), map(repr, [self.oc3]), ordered=False) + self.assertQuerysetEqual( + er.options.all(), map(repr, [self.oc3]), transform=repr, ordered=False + ) # TODO: Make the view care about comments. # self.assertQuerysetEqual( # er.comments.all(), map(repr, []), @@ -1027,7 +1037,10 @@ class EventStatusViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(r.status_code, 200) self.assertQuerysetEqual( - r.context["user_choices"], map(repr, expected), ordered=False + r.context["user_choices"], + map(repr, expected), + transform=repr, + ordered=False, ) def test_filter_none(self): @@ -1094,7 +1107,10 @@ class SurveyViewTests(ViewTestCaseMixin, TestCase): a = self.s.surveyanswer_set.get(user=self.users["user"]) self.assertQuerysetEqual( - a.answers.all(), map(repr, [self.qa1, self.qa3, self.qa4]), ordered=False + a.answers.all(), + map(repr, [self.qa1, self.qa3, self.qa4]), + transform=repr, + ordered=False, ) def test_post_edit(self): @@ -1113,7 +1129,9 @@ class SurveyViewTests(ViewTestCaseMixin, TestCase): self.assertIn(self.post_expected_message, get_messages(r.wsgi_request)) a.refresh_from_db() - self.assertQuerysetEqual(a.answers.all(), map(repr, [self.qa3]), ordered=False) + self.assertQuerysetEqual( + a.answers.all(), map(repr, [self.qa3]), transform=repr, ordered=False + ) def test_post_delete(self): a = self.s.surveyanswer_set.create(user=self.users["user"]) @@ -1194,7 +1212,10 @@ class SurveyStatusViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(r.status_code, 200) self.assertQuerysetEqual( - r.context["user_answers"], map(repr, expected), ordered=False + r.context["user_answers"], + map(repr, expected), + transform=repr, + ordered=False, ) def test_filter_none(self): diff --git a/kfet/auth/tests.py b/kfet/auth/tests.py index a7a0b5ad..ade0d11a 100644 --- a/kfet/auth/tests.py +++ b/kfet/auth/tests.py @@ -40,6 +40,7 @@ class UserGroupFormTests(TestCase): self.assertQuerysetEqual( groups_field.queryset, [repr(g.group_ptr) for g in self.kfet_groups], + transform=repr, ordered=False, ) diff --git a/kfet/tests/test_tests_utils.py b/kfet/tests/test_tests_utils.py index 49661e23..2c42ff79 100644 --- a/kfet/tests/test_tests_utils.py +++ b/kfet/tests/test_tests_utils.py @@ -94,6 +94,7 @@ class PermHelpersTest(TestCaseMixin, TestCase): self.assertQuerysetEqual( user.user_permissions.all(), map(repr, [self.perm1, self.perm2, self.perm_team]), + transform=repr, ordered=False, ) diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py index d7df91ad..c6d8a5a7 100644 --- a/kfet/tests/test_views.py +++ b/kfet/tests/test_views.py @@ -520,6 +520,7 @@ class AccountGroupCreateViewTests(ViewTestCaseMixin, TestCase): self.assertQuerysetEqual( group.permissions.all(), map(repr, [self.perms["kfet.is_team"], self.perms["kfet.manage_perms"]]), + transform=repr, ordered=False, ) @@ -573,6 +574,7 @@ class AccountGroupUpdateViewTests(ViewTestCaseMixin, TestCase): self.assertQuerysetEqual( self.group.permissions.all(), map(repr, [self.perms["kfet.is_team"], self.perms["kfet.manage_perms"]]), + transform=repr, ordered=False, ) @@ -600,6 +602,7 @@ class AccountNegativeListViewTests(ViewTestCaseMixin, TestCase): self.assertQuerysetEqual( r.context["negatives"], map(repr, [self.accounts["user"].negative]), + transform=repr, ordered=False, ) @@ -877,6 +880,7 @@ class CheckoutListViewTests(ViewTestCaseMixin, TestCase): self.assertQuerysetEqual( r.context["checkouts"], map(repr, [self.checkout1, self.checkout2]), + transform=repr, ordered=False, ) @@ -1067,6 +1071,7 @@ class CheckoutStatementListViewTests(ViewTestCaseMixin, TestCase): self.assertQuerysetEqual( r.context["checkoutstatements"], map(repr, expected_statements), + transform=repr, ordered=False, ) @@ -1293,7 +1298,9 @@ class ArticleCategoryListViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(r.status_code, 200) self.assertQuerysetEqual( - r.context["categories"], map(repr, [self.category1, self.category2]) + r.context["categories"], + map(repr, [self.category1, self.category2]), + transform=repr, ) @@ -1368,7 +1375,9 @@ class ArticleListViewTests(ViewTestCaseMixin, TestCase): r = self.client.get(self.url) self.assertEqual(r.status_code, 200) self.assertQuerysetEqual( - r.context["articles"], map(repr, [self.article1, self.article2]) + r.context["articles"], + map(repr, [self.article1, self.article2]), + transform=repr, ) @@ -4435,7 +4444,9 @@ class InventoryListViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(r.status_code, 200) inventories = r.context["inventories"] - self.assertQuerysetEqual(inventories, map(repr, [self.inventory])) + self.assertQuerysetEqual( + inventories, map(repr, [self.inventory]), transform=repr + ) class InventoryCreateViewTests(ViewTestCaseMixin, TestCase): @@ -4622,7 +4633,7 @@ class OrderListViewTests(ViewTestCaseMixin, TestCase): self.assertEqual(r.status_code, 200) orders = r.context["orders"] - self.assertQuerysetEqual(orders, map(repr, [self.order])) + self.assertQuerysetEqual(orders, map(repr, [self.order]), transform=repr) class OrderReadViewTests(ViewTestCaseMixin, TestCase): @@ -4837,7 +4848,9 @@ class OrderToInventoryViewTests(ViewTestCaseMixin, TestCase): inventory, {"by": self.accounts["team1"], "at": self.now, "order": self.order}, ) - self.assertQuerysetEqual(inventory.articles.all(), map(repr, [self.article])) + self.assertQuerysetEqual( + inventory.articles.all(), map(repr, [self.article]), transform=repr + ) compte = InventoryArticle.objects.get(article=self.article)