Skip to content

Commit d702e00

Browse files
authored
Fix flaky programs test (#3092)
1 parent 80a6813 commit d702e00

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

courses/views/v2/views_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ def test_get_programs(
6666

6767
# Fetch programs after running the fixture so they're in the right order
6868
programs = Program.objects.order_by("title").prefetch_related("departments").all()
69+
program_ids = programs.values_list("title", flat=True).all()
6970

7071
num_queries = num_queries_from_programs(programs, "v2")
7172
with django_assert_max_num_queries(num_queries) as context:
7273
resp = user_drf_client.get(reverse("v2:programs_api-list"))
7374
duplicate_queries_check(context)
7475
programs_data = resp.json()["results"]
7576
assert len(programs_data) == Pagination.page_size
76-
for program, program_data in zip(programs, programs_data):
77+
# Assert that things are in the correct order by checking the IDs
78+
assert [result["title"] for result in programs_data] == list(program_ids)
79+
80+
for program_data in programs_data:
81+
program = programs.get(pk=program_data["id"])
7782
# Clear cached property to ensure consistent data between API and serializer
7883
if hasattr(program, "_courses_with_requirements_data"):
7984
delattr(program, "_courses_with_requirements_data")

0 commit comments

Comments
 (0)