Coverage for src/tests/modules/training/trainings/test_training_schedule_db_repository.py: 94%
34 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 training schema repository."""
3from dataclasses import replace
5import pytest
7from kwai_bc_training.trainings.training_schedule_db_repository import (
8 TrainingScheduleDbRepository,
9)
10from kwai_bc_training.trainings.training_schedule_repository import (
11 TrainingScheduleNotFoundException,
12)
13from kwai_core.db.database import Database
14from kwai_core.db.exceptions import QueryException
17pytestmark = pytest.mark.db
20async def test_create(make_training_schedule_in_db):
21 """Test if the training schema was created."""
22 schema = await make_training_schedule_in_db()
23 assert schema is not None, "There should be a training schema created"
26async def test_get_by_id(
27 database: Database,
28 make_training_schedule_in_db,
29):
30 """Test if the training schema can be found with the id."""
31 repo = TrainingScheduleDbRepository(database)
32 schema = await make_training_schedule_in_db()
33 entity = await repo.get_by_id(schema.id)
35 assert entity.id == schema.id, "The training schema should be found"
38async def test_get_all(
39 database: Database,
40 make_training_schedule_in_db,
41):
42 """Test if all training schemas can be loaded."""
43 repo = TrainingScheduleDbRepository(database)
44 schema = await make_training_schedule_in_db()
45 entities = {entity.id: entity async for entity in repo.get_all()}
46 assert schema.id in entities, "Schema should be in the list."
49async def test_update(
50 database: Database,
51 make_training_schedule_in_db,
52):
53 """Test update of training schema."""
54 repo = TrainingScheduleDbRepository(database)
55 schema = await make_training_schedule_in_db()
56 schema = replace(schema, remark="Training schema updated")
57 try:
58 await repo.update(schema)
59 except QueryException as qe:
60 pytest.fail(str(qe))
63async def test_delete(
64 database: Database,
65 make_training_schedule_in_db,
66):
67 """Test if the training schema can be deleted."""
68 repo = TrainingScheduleDbRepository(database)
69 schema = await make_training_schedule_in_db()
70 await repo.delete(schema)
72 with pytest.raises(TrainingScheduleNotFoundException):
73 await repo.get_by_id(schema.id)