Skip to content

Commit

Permalink
test: fix test failures caused by enable DatabaseFeatures.supports_ag…
Browse files Browse the repository at this point in the history
…gregate_filter_clause
  • Loading branch information
jayvynl committed Dec 23, 2023
1 parent 91a0025 commit 2e116a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/aggregation/test_filter_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_related_aggregates_m2m_and_fk(self):
def test_plain_annotate(self):
agg = Sum("book__pages", filter=Q(book__rating__gt=3))
qs = Author.objects.annotate(pages=agg).order_by("pk")
self.assertSequenceEqual([a.pages for a in qs], [447, None, 1047])
self.assertSequenceEqual([a.pages for a in qs], [447, 0, 1047])

def test_filtered_aggregate_on_annotate(self):
pages_annotate = Sum("book__pages", filter=Q(book__rating__gt=3))
Expand Down
9 changes: 4 additions & 5 deletions tests/aggregation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ def test_aggregation_default_using_datetime_from_python(self):
expr = Min(
"store__original_opening",
filter=~Q(store__name="Amazon.com"),
# Never take effect
default=Cast(datetime.datetime(1970, 1, 1), DateTimeField()),
)
queryset = Book.objects.annotate(oldest_store_opening=expr).order_by("isbn")
Expand All @@ -1557,7 +1558,7 @@ def test_aggregation_default_using_datetime_from_python(self):
},
{
"isbn": "067232959",
"oldest_store_opening": datetime.datetime(1970, 1, 1),
"oldest_store_opening": datetime.datetime.fromtimestamp(0),
},
{
"isbn": "155860191",
Expand All @@ -1581,10 +1582,10 @@ def test_aggregation_default_using_datetime_from_python(self):
)

def test_aggregation_default_using_datetime_from_database(self):
now = timezone.now()
expr = Min(
"store__original_opening",
filter=~Q(store__name="Amazon.com"),
# Never take effect
default=TruncHour(NowUTC(), output_field=DateTimeField()),
)
queryset = Book.objects.annotate(oldest_store_opening=expr).order_by("isbn")
Expand All @@ -1605,9 +1606,7 @@ def test_aggregation_default_using_datetime_from_database(self):
},
{
"isbn": "067232959",
"oldest_store_opening": now.replace(
minute=0, second=0, microsecond=0, tzinfo=None
),
"oldest_store_opening": datetime.datetime.fromtimestamp(0),
},
{
"isbn": "155860191",
Expand Down
3 changes: 2 additions & 1 deletion tests/clickhouse_table_engine/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.test import TestCase

from clickhouse_backend import models
from clickhouse_backend.utils.timezone import get_timezone

from .models import EngineWithSettings, Event

Expand All @@ -16,7 +17,7 @@ def test_table(self):
engine_full = cursor.fetchone()[0]
self.assertEqual(
engine_full.partition(" SETTINGS ")[0],
"MergeTree PARTITION BY toYYYYMMDD(timestamp) PRIMARY KEY timestamp ORDER BY (timestamp, id)",
f"MergeTree PARTITION BY toYYYYMMDD(timestamp, '{get_timezone()}') PRIMARY KEY timestamp ORDER BY (timestamp, id)",
)

def test_mergetree_init_exception(self):
Expand Down

0 comments on commit 2e116a4

Please sign in to comment.