2022-12-31 01:09:22 -06:00
|
|
|
from httpx import Response
|
2022-01-16 15:24:24 -09:00
|
|
|
|
|
|
|
|
2022-12-31 01:09:22 -06:00
|
|
|
def assert_ignore_keys(dict1: dict, dict2: dict, ignore_keys: list | None = None) -> None:
|
2021-09-05 22:05:29 -08:00
|
|
|
"""
|
2024-06-30 01:25:04 +10:00
|
|
|
Iterates through a list of keys and checks if they are in the the provided ignore_keys list,
|
2021-09-05 22:05:29 -08:00
|
|
|
if they are not in the ignore_keys list, it checks the value of the key in the provided against
|
|
|
|
the value provided in dict2. If the value of the key in dict1 is not equal to the value of the
|
|
|
|
key in dict2, The assertion fails. Useful for testing id / group_id agnostic data
|
|
|
|
|
2021-11-25 14:17:02 -09:00
|
|
|
Note: ignore_keys defaults to ['id', 'group_id', 'groupId']
|
2021-09-05 22:05:29 -08:00
|
|
|
"""
|
|
|
|
if ignore_keys is None:
|
2021-11-25 14:17:02 -09:00
|
|
|
ignore_keys = ["id", "group_id", "groupId"]
|
2021-09-05 22:05:29 -08:00
|
|
|
|
|
|
|
for key, value in dict1.items():
|
|
|
|
if key in ignore_keys:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
assert value == dict2[key]
|
2022-01-16 15:24:24 -09:00
|
|
|
|
|
|
|
|
2024-06-30 01:25:04 +10:00
|
|
|
def assert_deserialize(response: Response, expected_status_code=200) -> dict:
|
2022-01-16 15:24:24 -09:00
|
|
|
assert response.status_code == expected_status_code
|
|
|
|
return response.json()
|