Skip to content

Commit

Permalink
fix(analytics/tests): do not assume sorted output
Browse files Browse the repository at this point in the history
The analytics table here doesn't do ordering in SQL, so we should
not assume sorted output.
  • Loading branch information
winged committed Jan 25, 2024
1 parent 031b9cd commit 136f1ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
26 changes: 13 additions & 13 deletions caluma/caluma_analytics/tests/__snapshots__/test_simple_table.ambr
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# serializer version: 1
# name: test_run_analytics_direct[cases]
list([
dict({
'baz': None,
'created_at': FakeDatetime(2022, 2, 1, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'foo': None,
'from_the_doc': None,
'quarter': 1,
'statuuuuuus': 'running',
'sub_question_sumsumsum': None,
}),
dict({
'baz': 'qux',
'created_at': FakeDatetime(2022, 2, 1, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
Expand All @@ -12,7 +21,7 @@
}),
dict({
'baz': None,
'created_at': FakeDatetime(2022, 2, 1, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'created_at': FakeDatetime(2022, 2, 2, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'foo': None,
'from_the_doc': None,
'quarter': 1,
Expand All @@ -30,7 +39,7 @@
}),
dict({
'baz': None,
'created_at': FakeDatetime(2022, 2, 2, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'created_at': FakeDatetime(2022, 2, 3, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'foo': None,
'from_the_doc': None,
'quarter': 1,
Expand All @@ -48,7 +57,7 @@
}),
dict({
'baz': None,
'created_at': FakeDatetime(2022, 2, 3, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'created_at': FakeDatetime(2022, 2, 4, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'foo': None,
'from_the_doc': None,
'quarter': 1,
Expand All @@ -66,7 +75,7 @@
}),
dict({
'baz': None,
'created_at': FakeDatetime(2022, 2, 4, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'created_at': FakeDatetime(2022, 2, 5, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'foo': None,
'from_the_doc': None,
'quarter': 1,
Expand All @@ -82,15 +91,6 @@
'statuuuuuus': 'suspended',
'sub_question_sumsumsum': '7881',
}),
dict({
'baz': None,
'created_at': FakeDatetime(2022, 2, 5, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='UTC')),
'foo': None,
'from_the_doc': None,
'quarter': 1,
'statuuuuuus': 'running',
'sub_question_sumsumsum': None,
}),
])
# ---
# name: test_run_analytics_gql[case__meta0-False-cases]
Expand Down
11 changes: 9 additions & 2 deletions caluma/caluma_analytics/tests/test_simple_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ def test_run_analytics_direct(db, snapshot, example_analytics, analytics_cases):
"""

table = SimpleTable(example_analytics)

result = table.get_records()

# one row for each 5 analytics_cases and one for each subcase
assert len(result) == 10

snapshot.assert_match(result)
# analytics here is not explicitly sorted, so we
# don't validate row output ordering
snapshot.assert_match(
# The sort needs two values, as each "factory" case comes with
# a work item and associated subcase, which need
# to be sorted in consistently
sorted(result, key=lambda r: str(r["created_at"]) + str(r["foo"]))
)


@pytest.mark.parametrize("analytics_table__starting_object", ["cases"])
Expand Down

0 comments on commit 136f1ae

Please sign in to comment.