Coverage for src/tests/modules/portal/test_update_page.py: 100%
17 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 "Update Page" use case."""
3from kwai_bc_portal.applications.application_db_repository import (
4 ApplicationDbRepository,
5)
6from kwai_bc_portal.domain.page import PageEntity
7from kwai_bc_portal.page_command import TextCommand
8from kwai_bc_portal.pages.page_db_repository import PageDbRepository
9from kwai_bc_portal.update_page import UpdatePage, UpdatePageCommand
10from kwai_core.db.database import Database
11from kwai_core.domain.presenter import EntityPresenter
12from kwai_core.domain.value_objects.owner import Owner
15async def test_update_page(
16 database: Database,
17 owner: Owner,
18 make_page_in_db,
19):
20 """Test the "Update Page" use case."""
21 page = await make_page_in_db()
23 page_repo = PageDbRepository(database)
24 application_repo = ApplicationDbRepository(database)
25 command = UpdatePageCommand(
26 id=page.id.value,
27 enabled=page.enabled,
28 texts=[
29 TextCommand(
30 locale=text.locale.value,
31 format=text.format.value,
32 title=text.title,
33 summary=text.summary,
34 content=text.content,
35 )
36 for text in page.texts
37 ],
38 application=page.application.id.value,
39 priority=page.priority,
40 remark="Updated with test_update_page",
41 )
42 presenter = EntityPresenter[PageEntity]()
43 await UpdatePage(page_repo, application_repo, owner, presenter).execute(command)
44 assert presenter.entity is not None, "There should be an updated page."
45 assert presenter.entity.remark == "Updated with test_update_page", (
46 "The page should be updated."
47 )