Coverage for src/tests/modules/training/coaches/test_coaches_db_repository.py: 77%

35 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for testing the coach database repository.""" 

2 

3import pytest 

4 

5from kwai_bc_training.coaches.coach_db_repository import CoachDbRepository 

6from kwai_core.db.database import Database 

7from kwai_core.db.exceptions import QueryException 

8 

9 

10async def test_get_by_id(database: Database, make_coach_in_db): 

11 """Test get_by_id method.""" 

12 coach = await make_coach_in_db() 

13 repo = CoachDbRepository(database) 

14 

15 try: 

16 await repo.get_by_id(coach.id) 

17 except QueryException as qe: 

18 pytest.fail(str(qe)) 

19 

20 

21async def test_get_by_ids(database: Database, make_coach_in_db): 

22 """Test get_by_ids method.""" 

23 repo = CoachDbRepository(database) 

24 coach_1 = await make_coach_in_db() 

25 coach_2 = await make_coach_in_db() 

26 

27 try: 

28 {coach.id: coach async for coach in repo.get_by_ids(coach_1.id, coach_2.id)} 

29 except QueryException as qe: 

30 pytest.fail(str(qe)) 

31 

32 

33async def test_get(database: Database, make_coach_in_db): 

34 """Test get method.""" 

35 coach = await make_coach_in_db() 

36 repo = CoachDbRepository(database) 

37 

38 query = repo.create_query() 

39 query.filter_by_id(coach.id) 

40 try: 

41 await repo.get(query) 

42 except QueryException as qe: 

43 pytest.fail(str(qe)) 

44 

45 

46async def test_get_all(database: Database, make_coach_in_db): 

47 """Test get_all method.""" 

48 await make_coach_in_db() 

49 repo = CoachDbRepository(database) 

50 

51 try: 

52 repo.get_all() 

53 except QueryException as qe: 

54 pytest.fail(str(qe))