-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathclient_fixture.py
More file actions
89 lines (59 loc) · 2.36 KB
/
client_fixture.py
File metadata and controls
89 lines (59 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from typing import Iterator
from fastapi.testclient import TestClient
import pytest
from app import main
from app.database.models import Base, User
from app.routers import agenda, event, invitation, profile
from app.routers.salary import routes as salary
from tests.conftest import get_test_db, test_engine
from . import security_testing_routes
main.app.include_router(security_testing_routes.router)
def get_test_placeholder_user() -> Iterator[User]:
return User(
username='fake_user',
email='fake@mail.fake',
password='123456fake',
full_name='FakeName',
language_id=1,
telegram_id='666666'
)
@pytest.fixture(scope="session")
def client() -> Iterator[TestClient]:
return TestClient(main.app)
def create_test_client(get_db_function) -> Iterator[TestClient]:
Base.metadata.create_all(bind=test_engine)
main.app.dependency_overrides[get_db_function] = get_test_db
with TestClient(main.app) as client:
yield client
main.app.dependency_overrides = {}
Base.metadata.drop_all(bind=test_engine)
@pytest.fixture(scope="session")
def agenda_test_client() -> Iterator[TestClient]:
yield from create_test_client(agenda.get_db)
@pytest.fixture(scope="session")
def event_test_client() -> Iterator[TestClient]:
yield from create_test_client(event.get_db)
@pytest.fixture(scope="session")
def home_test_client() -> Iterator[TestClient]:
yield from create_test_client(main.get_db)
@pytest.fixture(scope="session")
def invitation_test_client() -> Iterator[TestClient]:
yield from create_test_client(invitation.get_db)
@pytest.fixture(scope="session")
def profile_test_client() -> Iterator[TestClient]:
Base.metadata.create_all(bind=test_engine)
main.app.dependency_overrides[profile.get_db] = get_test_db
main.app.dependency_overrides[
profile.get_placeholder_user] = get_test_placeholder_user
with TestClient(main.app) as client:
yield client
main.app.dependency_overrides = {}
Base.metadata.drop_all(bind=test_engine)
@pytest.fixture(scope="session")
def settings_test_client() -> Iterator[TestClient]:
yield from create_test_client(profile.get_db)
def security_test_client():
yield from create_test_client(event.get_db)
@pytest.fixture(scope="session")
def salary_test_client() -> Iterator[TestClient]:
yield from create_test_client(salary.get_db)