Coverage for src/tests/modules/portal/applications/test_application_db_repository.py: 100%

24 statements  

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

1"""Module that defines tests for application database repository.""" 

2 

3import pytest 

4 

5from kwai_bc_portal.applications.application_db_repository import ( 

6 ApplicationDbRepository, 

7) 

8from kwai_bc_portal.applications.application_repository import ( 

9 ApplicationNotFoundException, 

10 ApplicationRepository, 

11) 

12from kwai_core.db.database import Database 

13 

14 

15pytestmark = pytest.mark.db 

16 

17 

18@pytest.fixture(scope="module") 

19def repo(database: Database) -> ApplicationRepository: 

20 """Fixture for an application repository.""" 

21 return ApplicationDbRepository(database) 

22 

23 

24async def test_create(make_application_in_db): 

25 """Test if the application was created.""" 

26 application = await make_application_in_db() 

27 assert application is not None, "There should be an application created" 

28 

29 

30async def test_get_by_id(repo: ApplicationRepository, make_application_in_db): 

31 """Test if the application can be found with the id.""" 

32 application = await make_application_in_db() 

33 entity = await repo.get_by_id(application.id) 

34 assert entity.id == application.id, "The application should be found" 

35 

36 

37async def test_get_by_name(repo: ApplicationRepository, make_application_in_db): 

38 """Test if the application can be found with the name.""" 

39 application = await make_application_in_db() 

40 entity = await repo.get_by_name(application.name) 

41 assert entity.id == application.id, "The application should be found using the name" 

42 

43 

44async def test_delete(repo: ApplicationRepository, make_application_in_db): 

45 """Test if the application can be deleted.""" 

46 application = await make_application_in_db() 

47 await repo.delete(application) 

48 

49 with pytest.raises(ApplicationNotFoundException): 

50 await repo.get_by_id(application.id)