Coverage for src/tests/modules/portal/applications/test_application_db_query.py: 71%

42 statements  

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

1"""Module for testing the ApplicationDBQuery.""" 

2 

3import pytest 

4 

5from kwai_bc_portal.applications.application_db_query import ApplicationDbQuery 

6from kwai_bc_portal.domain.application import ApplicationIdentifier 

7from kwai_core.db.database import Database 

8 

9 

10pytestmark = pytest.mark.db 

11 

12 

13async def test_application_db_query(database: Database): 

14 """Test the query.""" 

15 query = ApplicationDbQuery(database) 

16 try: 

17 await query.count() 

18 await query.fetch_one() 

19 except Exception as exc: 

20 pytest.fail(f"An exception occurred: {exc}") 

21 

22 

23async def test_filter_by_id(database: Database): 

24 """Test filter by id.""" 

25 query = ApplicationDbQuery(database).filter_by_id(ApplicationIdentifier(1)) 

26 try: 

27 await query.fetch_one() 

28 except Exception as exc: 

29 pytest.fail(f"An exception occurred: {exc}") 

30 

31 

32async def test_filter_by_name(database: Database): 

33 """Test filter by name.""" 

34 query = ApplicationDbQuery(database).filter_by_name("test") 

35 try: 

36 await query.fetch_one() 

37 except Exception as exc: 

38 pytest.fail(f"An exception occurred: {exc}") 

39 

40 

41async def test_filter_only_news(database: Database): 

42 """Test filter for only news.""" 

43 query = ApplicationDbQuery(database).filter_only_news() 

44 try: 

45 await query.fetch_one() 

46 except Exception as exc: 

47 pytest.fail(f"An exception occurred: {exc}") 

48 

49 

50async def test_filter_only_events(database: Database): 

51 """Test filter for only events.""" 

52 query = ApplicationDbQuery(database).filter_only_events() 

53 try: 

54 await query.fetch_one() 

55 except Exception as exc: 

56 pytest.fail(f"An exception occurred: {exc}") 

57 

58 

59async def test_filter_only_pages(database: Database): 

60 """Test filter for only pages.""" 

61 query = ApplicationDbQuery(database).filter_only_pages() 

62 try: 

63 await query.fetch_one() 

64 except Exception as exc: 

65 pytest.fail(f"An exception occurred: {exc}")