-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathasyncio_fixture.py
56 lines (48 loc) · 1.54 KB
/
asyncio_fixture.py
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
from datetime import datetime, timedelta
from httpx import AsyncClient
import pytest
from app.database.models import Base
from app.main import app
from app.routers import telegram
from app.routers.event import create_event
from tests.client_fixture import get_test_placeholder_user
from tests.conftest import get_test_db, test_engine
@pytest.fixture
async def telegram_client():
Base.metadata.create_all(bind=test_engine)
app.dependency_overrides[telegram.get_db] = get_test_db
async with AsyncClient(app=app, base_url="http://test") as ac:
yield ac
app.dependency_overrides = {}
Base.metadata.drop_all(bind=test_engine)
today_date = datetime.today().replace(hour=0, minute=0, second=0)
@pytest.fixture
def fake_user_events(session):
Base.metadata.create_all(bind=test_engine)
user = get_test_placeholder_user()
session.add(user)
session.commit()
create_event(
db=session,
title='Cool today event',
start=today_date,
end=today_date + timedelta(days=2),
all_day=False,
content='test event',
owner_id=user.id,
location="Here",
is_google_event=False,
)
create_event(
db=session,
title='Cool (somewhen in two days) event',
start=today_date + timedelta(days=1),
end=today_date + timedelta(days=3),
all_day=False,
content='this week test event',
owner_id=user.id,
location="Here",
is_google_event=False,
)
yield user
Base.metadata.drop_all(bind=test_engine)