Coverage for src/tests/modules/club/repositories/test_country_db_repository.py: 100%
21 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 country db repository."""
3import pytest
5from kwai_bc_club.domain.country import CountryEntity
6from kwai_bc_club.repositories.country_db_repository import CountryDbRepository
7from kwai_bc_club.repositories.country_repository import (
8 CountryNotFoundException,
9 CountryRepository,
10)
11from kwai_core.db.database import Database
14pytestmark = pytest.mark.db
17@pytest.fixture
18async def country_repo(database: Database) -> CountryRepository:
19 """A fixture for a country repository."""
20 return CountryDbRepository(database)
23async def test_create_country(make_country_in_db):
24 """Test creating a country."""
25 country = await make_country_in_db(
26 CountryEntity(iso_2="XX", iso_3="XXX", name="Test")
27 )
28 assert not country.id.is_empty(), "Country should be created"
31async def test_get_country_by_iso_2(
32 country_repo: CountryRepository, make_country_in_db
33):
34 """Testing getting a country with an iso_2 code."""
35 await make_country_in_db(CountryEntity(iso_2="XX", iso_3="XXX", name="Test"))
36 country = await country_repo.get_by_iso_2("XX")
37 assert country.iso_2 == "XX", "The returned country should have iso_2 XX."
40async def test_delete_country(country_repo: CountryRepository, make_country_in_db):
41 """Test deleting a country with an iso_2 code."""
42 country = await make_country_in_db(
43 CountryEntity(iso_2="XX", iso_3="XXX", name="Test")
44 )
45 await country_repo.delete(country)
46 with pytest.raises(CountryNotFoundException):
47 await country_repo.get_by_iso_2("XX")