-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Module for the use case "Get Page".""" | ||
from dataclasses import dataclass | ||
|
||
from kwai.modules.page.pages.page import PageEntity, PageIdentifier | ||
from kwai.modules.page.pages.page_repository import PageRepository | ||
|
||
|
||
@dataclass(kw_only=True, frozen=True, slots=True) | ||
class GetPageCommand: | ||
"""Input for the use case "Get Page".""" | ||
|
||
id: int | ||
|
||
|
||
class GetPage: | ||
"""Use case "Get Page".""" | ||
|
||
def __init__(self, repo: PageRepository): | ||
"""Initialize the use case. | ||
Args: | ||
repo: A repository to get the page. | ||
""" | ||
self._repo = repo | ||
|
||
async def execute(self, command: GetPageCommand) -> PageEntity: | ||
"""Execute the use case.""" | ||
return await self._repo.get_by_id(PageIdentifier(command.id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Module for testing the use case "Get Page".""" | ||
from kwai.modules.page.get_page import GetPage, GetPageCommand | ||
from kwai.modules.page.pages.page import PageEntity | ||
from kwai.modules.page.pages.page_repository import PageRepository | ||
|
||
|
||
async def test_get_page(repo: PageRepository, saved_page: PageEntity): | ||
"""Test the "Get Page" use case.""" | ||
command = GetPageCommand(id=saved_page.id.value) | ||
page = await GetPage(repo).execute(command) | ||
assert page is not None, "There should be a page." | ||
assert page.id == saved_page.id, "The id of the pages should be the same." |