Coverage for src/tests/modules/portal/news/test_news_item_db_query.py: 77%

43 statements  

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

1"""Module for testing the news item database query.""" 

2 

3import pytest 

4 

5from kwai_bc_portal.news.news_item_db_query import NewsItemDbQuery 

6from kwai_core.db.database import Database 

7 

8 

9pytestmark = pytest.mark.db 

10 

11 

12async def test_news_item_db_query(database: Database): 

13 """Test the query.""" 

14 query = NewsItemDbQuery(database) 

15 try: 

16 await query.count() 

17 query.fetch() 

18 except Exception as exc: 

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

20 

21 

22async def test_filter_by_publication_date(database: Database): 

23 """Test the query with filtering on the news item publication date.""" 

24 query = NewsItemDbQuery(database) 

25 query.filter_by_publication_date(2023) 

26 try: 

27 await query.count() 

28 query.fetch() 

29 except Exception as exc: 

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

31 

32 

33async def test_filter_by_promoted(database: Database): 

34 """Test the query with filtering on promoted news items.""" 

35 query = NewsItemDbQuery(database) 

36 query.filter_by_promoted() 

37 try: 

38 await query.count() 

39 query.fetch() 

40 except Exception as exc: 

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

42 

43 

44async def test_filter_by_active(database: Database): 

45 """Test the query with filtering on active news items.""" 

46 query = NewsItemDbQuery(database) 

47 query.filter_by_active() 

48 try: 

49 await query.count() 

50 query.fetch() 

51 except Exception as exc: 

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

53 

54 

55async def test_filter_by_user(database: Database): 

56 """Test the query with filtering on author.""" 

57 query = NewsItemDbQuery(database) 

58 query.filter_by_user(1) 

59 try: 

60 await query.count() 

61 query.fetch() 

62 except Exception as exc: 

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