From e72b9e9e28c4c4f49dec6e852915d0f5b9954432 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Fri, 16 Aug 2024 21:59:20 -0700 Subject: [PATCH] Add a shim for QuerySetEqual to support both Django 3.2 and Django 5.1 --- project/tests/test_view_requests.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/project/tests/test_view_requests.py b/project/tests/test_view_requests.py index 620a7966..55eb9efb 100644 --- a/project/tests/test_view_requests.py +++ b/project/tests/test_view_requests.py @@ -26,6 +26,19 @@ def test_order_by(self): class TestContext(TestCase): + def assertQuerySetEqual(*args, **kwargs): + """ + A shim for QuerySetEqual to enable support for multiple versions of Django + TODO: delete this after support for Django 3.2 is dropped + Reference: https://docs.djangoproject.com/en/5.0/topics/testing/tools/#django.test.TransactionTestCase.assertQuerySetEqual + """ + if hasattr(super(), 'assertQuerySetEqual'): + # Django > 3.2 + super().assertQuerySetEqual(*args, **kwargs) + else: + # Django < 5.1 + super().assertQuerysetEqual(*args, **kwargs) + def test_default(self): request = Mock(spec_set=['GET', 'session']) request.session = {} @@ -38,7 +51,7 @@ def test_default(self): 'options_order_by': RequestsView().options_order_by, 'options_order_dir': RequestsView().options_order_dir, }, context)) - self.assertQuerysetEqual(context['options_paths'], RequestsView()._get_paths()) + self.assertQuerySetEqual(context['options_paths'], RequestsView()._get_paths()) self.assertNotIn('path', context) self.assertIn('results', context) @@ -60,7 +73,7 @@ def test_get(self): 'options_order_by': RequestsView().options_order_by, 'options_order_dir': RequestsView().options_order_dir, }, context)) - self.assertQuerysetEqual(context['options_paths'], RequestsView()._get_paths()) + self.assertQuerySetEqual(context['options_paths'], RequestsView()._get_paths()) self.assertIn('results', context) def test_post(self): @@ -74,7 +87,7 @@ def test_post(self): 'overalltime': {'typ': 'TimeSpentOnQueriesFilter', 'value': 100, 'str': 'DB Time >= 100'} }, }, context)) - self.assertQuerysetEqual(context['options_paths'], RequestsView()._get_paths()) + self.assertQuerySetEqual(context['options_paths'], RequestsView()._get_paths()) self.assertIn('results', context) def test_view_without_session_and_auth_middlewares(self):