Skip to content

Commit dae8c1e

Browse files
amin-basirijayvynl
authored andcommitted
feat(aggragation-function): add anyLast function
- add unittest
1 parent 6eed3af commit dae8c1e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/aggregates/tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
uniqExact,
99
uniqHLL12,
1010
uniqTheta,
11+
anyLast
1112
)
1213

1314
from .models import WatchSeries
@@ -28,6 +29,14 @@ class AggregatesTestCase(TestCase):
2829
{"show": "Game of Thrones", "episode": "S1E2", "uid_count": 1},
2930
]
3031

32+
expected_result_any_last = [
33+
{'uid': 'alice', 'user_last_watched_show': 'Game of Thrones'},
34+
{'uid': 'bob', 'user_last_watched_show': 'Bridgerton'},
35+
{'uid': 'carol', 'user_last_watched_show': 'Bridgerton'},
36+
{'uid': 'dan', 'user_last_watched_show': 'Bridgerton'},
37+
{'uid': 'erin', 'user_last_watched_show': 'Game of Thrones'},
38+
]
39+
3140
@classmethod
3241
def setUpTestData(cls):
3342
data_list = [
@@ -227,3 +236,15 @@ def test_uniqhll12(self):
227236

228237
def test_uniqtheta(self):
229238
self._test(uniqTheta)
239+
240+
def test_anylast(self):
241+
result = (
242+
WatchSeries.objects.values("uid")
243+
.annotate(user_last_watched_show=anyLast("show"))
244+
.order_by("uid")
245+
)
246+
247+
self.assertQuerysetEqual(
248+
result, self.expected_result_any_last, transform=dict
249+
)
250+

0 commit comments

Comments
 (0)