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

15 statements  

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

1"""Module for testing the "Create Page" use case.""" 

2 

3from kwai_bc_portal.applications.application_db_repository import ( 

4 ApplicationDbRepository, 

5) 

6from kwai_bc_portal.create_page import CreatePage, CreatePageCommand 

7from kwai_bc_portal.domain.page import PageEntity 

8from kwai_bc_portal.page_command import TextCommand 

9from kwai_bc_portal.pages.page_db_repository import PageDbRepository 

10from kwai_core.db.database import Database 

11from kwai_core.domain.presenter import EntityPresenter 

12from kwai_core.domain.value_objects.owner import Owner 

13 

14 

15async def test_create_page( 

16 database: Database, make_application_in_db, make_author_in_db 

17): 

18 """Test "Create Page" use case.""" 

19 application = await make_application_in_db() 

20 author = await make_author_in_db() 

21 

22 command = CreatePageCommand( 

23 enabled=True, 

24 texts=[ 

25 TextCommand( 

26 locale="nl", 

27 format="md", 

28 title="Test", 

29 summary="This is a test page", 

30 content="This is a test page", 

31 ), 

32 ], 

33 application=application.id.value, 

34 priority=0, 

35 remark="This is a test page created with test_create_page.", 

36 ) 

37 presenter = EntityPresenter[PageEntity]() 

38 await CreatePage( 

39 PageDbRepository(database), 

40 ApplicationDbRepository(database), 

41 Owner(id=author.id, uuid=author.uuid, name=author.name), 

42 presenter, 

43 ).execute(command) 

44 assert presenter.entity is not None, "There should be a page."