diff --git a/example/settings.py b/example/settings.py index 5a8a5b4df..1b8216b71 100644 --- a/example/settings.py +++ b/example/settings.py @@ -57,6 +57,8 @@ } ] +USE_TZ = True + WSGI_APPLICATION = "example.wsgi.application" diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index 19ba63919..4dd1d3fcc 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -121,7 +121,13 @@ def test_param_conversion(self): .filter(group_count__lt=10) .filter(group_count__gt=1) ) - list(User.objects.filter(date_joined=datetime.datetime(2017, 12, 22, 16, 7, 1))) + list( + User.objects.filter( + date_joined=datetime.datetime( + 2017, 12, 22, 16, 7, 1, tzinfo=datetime.timezone.utc + ) + ) + ) response = self.panel.process_request(self.request) self.panel.generate_stats(self.request, response) @@ -129,18 +135,27 @@ def test_param_conversion(self): # ensure query was logged self.assertEqual(len(self.panel._queries), 3) - # Django 4.1 started passing true/false back for boolean - # comparisons in MySQL. - if not (django.VERSION >= (4, 1) and connection.vendor == "mysql"): - self.assertEqual( - tuple(q[1]["params"] for q in self.panel._queries), - ('["Foo"]', "[10, 1]", '["2017-12-22 16:07:01"]'), - ) + if connection.vendor == "mysql" and django.VERSION >= (4, 1): + # Django 4.1 started passing true/false back for boolean + # comparisons in MySQL. + expected_bools = '["Foo", true, false]' else: - self.assertEqual( - tuple(q[1]["params"] for q in self.panel._queries), - ('["Foo", true, false]', "[10, 1]", '["2017-12-22 16:07:01"]'), - ) + expected_bools = '["Foo"]' + + if connection.vendor == "postgresql": + # PostgreSQL always includes timezone + expected_datetime = '["2017-12-22 16:07:01+00:00"]' + else: + expected_datetime = '["2017-12-22 16:07:01"]' + + self.assertEqual( + tuple(q[1]["params"] for q in self.panel._queries), + ( + expected_bools, + "[10, 1]", + expected_datetime, + ), + ) @unittest.skipUnless( connection.vendor == "postgresql", "Test valid only on PostgreSQL" diff --git a/tests/settings.py b/tests/settings.py index c09506087..d24108247 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -69,6 +69,8 @@ }, ] +USE_TZ = True + STATIC_ROOT = os.path.join(BASE_DIR, "tests", "static") STATIC_URL = "/static/" diff --git a/tests/test_forms.py b/tests/test_forms.py index 6da504233..da144e108 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -1,14 +1,14 @@ -from datetime import datetime +from datetime import datetime, timezone from django import forms from django.test import TestCase from debug_toolbar.forms import SignedDataForm -SIGNATURE = "v02QBcJplEET6QXHNWejnRcmSENWlw6_RjxLTR7QG9g" +SIGNATURE = "-WiogJKyy4E8Om00CrFSy0T6XHObwBa6Zb46u-vmeYE" -DATA = {"value": "foo", "date": datetime(2020, 1, 1)} -SIGNED_DATA = f'{{"date": "2020-01-01 00:00:00", "value": "foo"}}:{SIGNATURE}' +DATA = {"value": "foo", "date": datetime(2020, 1, 1, tzinfo=timezone.utc)} +SIGNED_DATA = f'{{"date": "2020-01-01 00:00:00+00:00", "value": "foo"}}:{SIGNATURE}' class FooForm(forms.Form): @@ -32,7 +32,7 @@ def test_verified_data(self): form.verified_data(), { "value": "foo", - "date": "2020-01-01 00:00:00", + "date": "2020-01-01 00:00:00+00:00", }, ) # Take it back to the foo form to validate the datetime is serialized