2022-07-15 23:06:40 +02:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
import pytest
|
2022-07-27 21:10:43 +02:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
2022-07-15 23:06:40 +02:00
|
|
|
|
2022-07-19 23:35:41 +02:00
|
|
|
from database.crud import users
|
2022-08-29 20:24:42 +02:00
|
|
|
from database.schemas import (
|
2022-07-25 21:20:09 +02:00
|
|
|
Bank,
|
2024-03-01 14:18:58 +01:00
|
|
|
BankSavings,
|
2022-07-25 21:20:09 +02:00
|
|
|
UforaAnnouncement,
|
|
|
|
UforaCourse,
|
|
|
|
UforaCourseAlias,
|
|
|
|
User,
|
|
|
|
)
|
2022-07-19 23:35:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def test_user_id() -> int:
|
|
|
|
"""User id used when creating the debug user
|
|
|
|
|
|
|
|
Fixture is useful when comparing, fetching data, ...
|
|
|
|
"""
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-07-27 21:10:43 +02:00
|
|
|
async def user(postgres: AsyncSession, test_user_id: int) -> User:
|
2022-07-19 23:35:41 +02:00
|
|
|
"""Fixture to create a user"""
|
2022-08-29 20:49:29 +02:00
|
|
|
_user = await users.get_or_add_user(postgres, test_user_id)
|
2022-07-25 19:12:27 +02:00
|
|
|
await postgres.refresh(_user)
|
2022-07-19 23:35:41 +02:00
|
|
|
return _user
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-07-27 21:10:43 +02:00
|
|
|
async def bank(postgres: AsyncSession, user: User) -> Bank:
|
2022-07-19 23:35:41 +02:00
|
|
|
"""Fixture to fetch the test user's bank"""
|
|
|
|
_bank = user.bank
|
2022-07-25 19:12:27 +02:00
|
|
|
await postgres.refresh(_bank)
|
2022-07-19 23:35:41 +02:00
|
|
|
return _bank
|
2022-07-15 23:06:40 +02:00
|
|
|
|
|
|
|
|
2024-03-01 14:18:58 +01:00
|
|
|
@pytest.fixture
|
|
|
|
async def savings(postgres: AsyncSession, user: User) -> BankSavings:
|
|
|
|
"""Fixture to fetch the test user's savings account"""
|
|
|
|
_savings = user.savings
|
|
|
|
await postgres.refresh(_savings)
|
|
|
|
return _savings
|
|
|
|
|
|
|
|
|
2022-07-15 23:06:40 +02:00
|
|
|
@pytest.fixture
|
2022-07-27 21:10:43 +02:00
|
|
|
async def ufora_course(postgres: AsyncSession) -> UforaCourse:
|
2022-07-15 23:06:40 +02:00
|
|
|
"""Fixture to create a course"""
|
|
|
|
course = UforaCourse(name="test", code="code", year=1, log_announcements=True)
|
2022-07-25 19:12:27 +02:00
|
|
|
postgres.add(course)
|
|
|
|
await postgres.commit()
|
2022-07-15 23:06:40 +02:00
|
|
|
return course
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-07-27 21:10:43 +02:00
|
|
|
async def ufora_course_with_alias(postgres: AsyncSession, ufora_course: UforaCourse) -> UforaCourse:
|
2022-07-15 23:06:40 +02:00
|
|
|
"""Fixture to create a course with an alias"""
|
|
|
|
alias = UforaCourseAlias(course_id=ufora_course.course_id, alias="alias")
|
2022-07-25 19:12:27 +02:00
|
|
|
postgres.add(alias)
|
|
|
|
await postgres.commit()
|
|
|
|
await postgres.refresh(ufora_course)
|
2022-07-15 23:06:40 +02:00
|
|
|
return ufora_course
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-07-27 21:10:43 +02:00
|
|
|
async def ufora_announcement(postgres: AsyncSession, ufora_course: UforaCourse) -> UforaAnnouncement:
|
2022-07-15 23:06:40 +02:00
|
|
|
"""Fixture to create an announcement"""
|
|
|
|
announcement = UforaAnnouncement(course_id=ufora_course.course_id, publication_date=datetime.datetime.now())
|
2022-07-25 19:12:27 +02:00
|
|
|
postgres.add(announcement)
|
|
|
|
await postgres.commit()
|
2022-07-15 23:06:40 +02:00
|
|
|
return announcement
|