30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
|
from typing import Union
|
||
|
|
||
|
from flask.testing import FlaskClient
|
||
|
|
||
|
from ..app.dependencies import db
|
||
|
|
||
|
|
||
|
def assert_model_changes(model: db.Model, expected_data: dict) -> None:
|
||
|
for key, val in expected_data.items():
|
||
|
assert getattr(model, key) == val
|
||
|
|
||
|
|
||
|
def _test_case_client_without_response(test_client: FlaskClient, url: str, data: Union[dict, None], status_code: int,
|
||
|
method: str = 'post') -> dict:
|
||
|
method_func = getattr(test_client, method)
|
||
|
if data is not None:
|
||
|
response = method_func(url, json=data)
|
||
|
else:
|
||
|
response = method_func(url)
|
||
|
|
||
|
assert response.status_code == status_code
|
||
|
return response.json
|
||
|
|
||
|
|
||
|
def _test_case_client(test_client: FlaskClient, url: str, data: Union[dict, None], message: str, status_code: int,
|
||
|
key: str = 'message', method: str = 'post') -> None:
|
||
|
response_data = _test_case_client_without_response(test_client, url, data, status_code, method)
|
||
|
assert key in response_data.keys()
|
||
|
assert response_data.get(key) == message
|