Skip to content

Commit b122a8c

Browse files
committed
Add a shim for QuerySetEqual to support both Django 3.2 and Django 5.1
1 parent 04cdf99 commit b122a8c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

project/tests/test_view_requests.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ def test_order_by(self):
2626

2727

2828
class TestContext(TestCase):
29+
def assertQuerySetEqual(self, *args, **kwargs):
30+
"""
31+
A shim for QuerySetEqual to enable support for multiple versions of Django
32+
TODO: delete this after support for Django 3.2 is dropped
33+
Reference: https://docs.djangoproject.com/en/5.0/topics/testing/tools/#django.test.TransactionTestCase.assertQuerySetEqual
34+
"""
35+
if hasattr(super(), 'assertQuerySetEqual'):
36+
# Django > 3.2
37+
super().assertQuerySetEqual(*args, **kwargs)
38+
else:
39+
# Django < 5.1
40+
super().assertQuerysetEqual(*args, **kwargs)
41+
2942
def test_default(self):
3043
request = Mock(spec_set=['GET', 'session'])
3144
request.session = {}
@@ -38,7 +51,7 @@ def test_default(self):
3851
'options_order_by': RequestsView().options_order_by,
3952
'options_order_dir': RequestsView().options_order_dir,
4053
}, context))
41-
self.assertQuerysetEqual(context['options_paths'], RequestsView()._get_paths())
54+
self.assertQuerySetEqual(context['options_paths'], RequestsView()._get_paths())
4255
self.assertNotIn('path', context)
4356
self.assertIn('results', context)
4457

@@ -60,7 +73,7 @@ def test_get(self):
6073
'options_order_by': RequestsView().options_order_by,
6174
'options_order_dir': RequestsView().options_order_dir,
6275
}, context))
63-
self.assertQuerysetEqual(context['options_paths'], RequestsView()._get_paths())
76+
self.assertQuerySetEqual(context['options_paths'], RequestsView()._get_paths())
6477
self.assertIn('results', context)
6578

6679
def test_post(self):
@@ -74,7 +87,7 @@ def test_post(self):
7487
'overalltime': {'typ': 'TimeSpentOnQueriesFilter', 'value': 100, 'str': 'DB Time >= 100'}
7588
},
7689
}, context))
77-
self.assertQuerysetEqual(context['options_paths'], RequestsView()._get_paths())
90+
self.assertQuerySetEqual(context['options_paths'], RequestsView()._get_paths())
7891
self.assertIn('results', context)
7992

8093
def test_view_without_session_and_auth_middlewares(self):

0 commit comments

Comments
 (0)