Skip to content

Commit

Permalink
feat: assertResponseItems now detects duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoalmeidaee committed Oct 17, 2024
1 parent 520ab55 commit 9ece7d2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drf_kit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import re
from collections import Counter
from collections.abc import Callable, Iterable
from contextlib import contextmanager
from io import StringIO
Expand Down Expand Up @@ -75,8 +76,10 @@ def _extract_id(i: int | str | Model | dict):
return i

expected_ids = {_extract_id(i=item) for item in expected_items}
received_ids = {s[pk_field] for s in response.json()[response_key]}
self.assertEqual(expected_ids, received_ids)
received_ids = Counter(s[pk_field] for s in response.json()[response_key])
duplicate_ids = {k for k, v in received_ids.items() if v > 1}
self.assertEqual(set(), duplicate_ids, msg=f"Duplicate ids found in response: {duplicate_ids}")
self.assertEqual(expected_ids, set(received_ids.keys()))

def assertResponseList(self, expected_items: Iterable[dict], response, response_key: str = "results"):
self.assertResponse(
Expand Down

0 comments on commit 9ece7d2

Please sign in to comment.