Coverage for src/tests/modules/club/repositories/test_coach_db_repository.py: 87%
30 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 for testing the coach database repository."""
3from dataclasses import replace
5import pytest
7from kwai_bc_club.repositories.coach_db_repository import CoachDbRepository
8from kwai_core.db.exceptions import QueryException
11pytestmark = pytest.mark.db
14async def test_create_coach(make_coach_in_db):
15 """Test creating a coach."""
16 coach = await make_coach_in_db()
17 assert coach is not None, "There should be a coach."
18 assert coach.id is not None, "Coach id should be provided."
21async def test_update_coach(make_coach_in_db, database):
22 """Test updating a coach."""
23 coach = await make_coach_in_db()
24 updated_coach = replace(coach, remark="Updated")
25 coach_repo = CoachDbRepository(database)
26 try:
27 await coach_repo.update(updated_coach)
28 except QueryException as qe:
29 pytest.fail(str(qe))
32async def test_get_by_id(make_coach_in_db, database):
33 """Test getting a coach by its id."""
34 coach = await make_coach_in_db()
35 coach_repo = CoachDbRepository(database)
36 coach = await coach_repo.get_by_id(coach.id)
37 assert coach is not None, "There should be a coach."
40async def test_get_all(make_coach_in_db, database):
41 """Test get all."""
42 await make_coach_in_db()
43 coach_repo = CoachDbRepository(database)
44 try:
45 it = coach_repo.get_all()
46 await anext(it)
47 except Exception as exc:
48 pytest.fail(f"An exception occurred: {exc}")