Coverage for src/tests/api/conftest.py: 100%
17 statements
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2024-01-01 00:00 +0000
1"""Module that defines fixtures for the api tests."""
3import pytest
5from fastapi import FastAPI
6from fastapi.testclient import TestClient
7from kwai_api.app import create_api
8from kwai_bc_identity.users.user_account import UserAccountEntity
9from kwai_core.settings import get_settings
12@pytest.fixture(scope="module")
13def client() -> TestClient:
14 """Get an HTTP client."""
15 app = FastAPI(title="kwai API -- TEST")
16 app.mount("/api", create_api(get_settings()))
17 return TestClient(app)
20@pytest.fixture(scope="module")
21def secure_client(client: TestClient, user_account: UserAccountEntity) -> TestClient:
22 """Return a test client that is logged-in."""
23 response = client.post(
24 "/api/v1/auth/login",
25 data={"username": str(user_account.user.email), "password": "Nage-waza/1882"},
26 )
27 client.cookies.set("access_token", response.cookies["access_token"])
28 client.cookies.set("refresh_token", response.cookies["refresh_token"])
30 return client