Coverage for src/tests/modules/identity/user_invitations/test_user_invitation_db_repository.py: 100%
31 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 UserInvitationDbRepository."""
3import pytest
5from kwai_bc_identity.user_invitations.user_invitation import UserInvitationEntity
6from kwai_bc_identity.user_invitations.user_invitation_db_repository import (
7 UserInvitationDbRepository,
8)
9from kwai_bc_identity.user_invitations.user_invitation_repository import (
10 UserInvitationNotFoundException,
11 UserInvitationRepository,
12)
13from kwai_bc_identity.users.user import UserEntity
14from kwai_core.db.database import Database
15from kwai_core.domain.value_objects.email_address import EmailAddress
16from kwai_core.domain.value_objects.name import Name
19pytestmark = pytest.mark.db
22@pytest.fixture(scope="module")
23def repo(database: Database) -> UserInvitationRepository:
24 """Fixture for creating the invitation repository."""
25 return UserInvitationDbRepository(database)
28@pytest.fixture(scope="module")
29async def invitation(
30 repo: UserInvitationRepository, user: UserEntity
31) -> UserInvitationEntity:
32 """Fixture for an invitation."""
33 invitation = UserInvitationEntity(
34 email=EmailAddress("ichiro.abe@kwai.com"),
35 name=Name(first_name="Ichiro", last_name="Abe"),
36 remark="Created with pytest",
37 user=user,
38 )
39 return await repo.create(invitation)
42def test_create(invitation: UserInvitationEntity):
43 """Test if the invitation was created."""
44 assert not invitation.id.is_empty(), "There should be an invitation created"
47async def test_get_by_id(
48 repo: UserInvitationRepository, invitation: UserInvitationEntity
49):
50 """Test if the invitation can be found with the id."""
51 entity = await repo.get_invitation_by_id(invitation.id)
52 assert entity.id == invitation.id
55async def test_get_by_uuid(
56 repo: UserInvitationRepository, invitation: UserInvitationEntity
57):
58 """Test if the invitation can be found with the unique id."""
59 entity = await repo.get_invitation_by_uuid(invitation.uuid)
60 assert entity.id == invitation.id
63async def test_get_all(repo: UserInvitationRepository):
64 """Test get all."""
65 invitations = [invitation async for invitation in repo.get_all(repo.create_query())]
66 assert len(invitations) > 0, "There should be at least 1 row"
69async def test_delete(repo: UserInvitationRepository, invitation: UserInvitationEntity):
70 """Test if the invitation can be deleted."""
71 await repo.delete(invitation)
73 with pytest.raises(UserInvitationNotFoundException):
74 await repo.get_invitation_by_id(invitation.id)