Coverage for src/tests/modules/club/test_create_coach.py: 100%
29 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 use case 'Create Coach'."""
3import pytest
5from kwai_bc_club.create_coach import CreateCoach, CreateCoachCommand
6from kwai_bc_club.domain.club_coach import ClubCoachEntity
7from kwai_bc_club.repositories.coach_db_repository import CoachDbRepository
8from kwai_bc_club.repositories.coach_repository import CoachAlreadyExistException
9from kwai_bc_club.repositories.member_db_repository import MemberDbRepository
10from kwai_bc_club.repositories.member_repository import MemberNotFoundException
11from kwai_core.db.database import Database
12from kwai_core.domain.presenter import EntityPresenter
13from kwai_core.domain.value_objects.unique_id import UniqueId
16pytestmark = pytest.mark.db
19async def test_create_coach(make_member_in_db, database: Database):
20 """Test creating a coach."""
21 member = await make_member_in_db()
22 command = CreateCoachCommand(
23 diploma="Initiator",
24 description="Head coach",
25 remark="Test",
26 active=True,
27 member_uuid=str(member.uuid),
28 )
29 presenter = EntityPresenter[ClubCoachEntity]()
30 await CreateCoach(
31 CoachDbRepository(database), MemberDbRepository(database), presenter
32 ).execute(command)
33 assert presenter.entity is not None, "There should be a coach"
36async def test_create_coach_without_member(database: Database):
37 """Test creating a coach with a member that doesn't exist."""
38 command = CreateCoachCommand(
39 diploma="Initiator",
40 description="Head coach",
41 remark="Test",
42 active=True,
43 member_uuid=str(UniqueId.generate()),
44 )
45 presenter = EntityPresenter[ClubCoachEntity]()
46 with pytest.raises(MemberNotFoundException):
47 await CreateCoach(
48 CoachDbRepository(database), MemberDbRepository(database), presenter
49 ).execute(command)
52async def test_coach_already_exists(make_member_in_db, database: Database):
53 """Test creating a coach twice."""
54 member = await make_member_in_db()
55 command = CreateCoachCommand(
56 diploma="Initiator",
57 description="Head coach",
58 remark="Test",
59 active=True,
60 member_uuid=str(member.uuid),
61 )
62 presenter = EntityPresenter[ClubCoachEntity]()
63 await CreateCoach(
64 CoachDbRepository(database), MemberDbRepository(database), presenter
65 ).execute(command)
67 with pytest.raises(CoachAlreadyExistException):
68 await CreateCoach(
69 CoachDbRepository(database), MemberDbRepository(database), presenter
70 ).execute(command)