mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-18 15:00:46 +08:00

* Update tests structure. * Unit tests use the test database * Add function for creating database engine and session.
22 lines
685 B
Python
22 lines
685 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from starlette.testclient import TestClient
|
|
|
|
from backend.app.core.conf import settings
|
|
|
|
|
|
def test_login(client: TestClient) -> None:
|
|
data = {
|
|
'username': 'test',
|
|
'password': 'test',
|
|
}
|
|
response = client.post(f'{settings.API_V1_STR}/auth/login', json=data)
|
|
assert response.status_code == 200
|
|
assert response.json()['data']['access_token_type'] == 'Bearer'
|
|
|
|
|
|
def test_logout(client: TestClient, token_headers: dict[str, str]) -> None:
|
|
response = client.post(f'{settings.API_V1_STR}/auth/logout', headers=token_headers)
|
|
assert response.status_code == 200
|
|
assert response.json()['code'] == 200
|