Skip to content

Commit

Permalink
refactor: move fixtures to conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fbraem committed Sep 21, 2023
1 parent c54fea0 commit 1a37751
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
14 changes: 14 additions & 0 deletions backend/src/tests/modules/page/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from kwai.core.domain.value_objects.owner import Owner
from kwai.core.domain.value_objects.text import DocumentFormat, Locale, LocaleText
from kwai.modules.page.pages.page import Application, PageEntity
from kwai.modules.page.pages.page_db_repository import PageDbRepository
from kwai.modules.page.pages.page_repository import PageRepository
from kwai.modules.portal.applications.application import ApplicationEntity
from kwai.modules.portal.applications.application_db_repository import (
ApplicationDbRepository,
Expand Down Expand Up @@ -44,3 +46,15 @@ def page(owner: Owner, application: Application) -> PageEntity:
priority=0,
remark="Test",
)


@pytest.fixture(scope="module")
def repo(database: Database) -> PageRepository:
"""Fixture for a page repository."""
return PageDbRepository(database)


@pytest.fixture(scope="module")
async def saved_page(repo: PageRepository, page: PageEntity) -> PageEntity:
"""Fixture for a page stored in the database."""
return await repo.create(page)
15 changes: 0 additions & 15 deletions backend/src/tests/modules/page/pages/test_page_db_repository.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
"""Module for testing the page database repository."""
import pytest

from kwai.core.db.database import Database
from kwai.core.domain.entity import Entity
from kwai.modules.page.pages.page import PageEntity
from kwai.modules.page.pages.page_db_repository import PageDbRepository
from kwai.modules.page.pages.page_repository import PageRepository


@pytest.fixture(scope="module")
def repo(database: Database) -> PageRepository:
"""Fixture for a page repository."""
return PageDbRepository(database)


@pytest.fixture(scope="module")
async def saved_page(repo: PageRepository, page: PageEntity) -> PageEntity:
"""Fixture for a page stored in the database."""
return await repo.create(page)


async def test_create(repo: PageRepository, saved_page: PageEntity):
"""Test create page."""
assert not saved_page.id.is_empty(), "There should be an id for a new page."
Expand Down
15 changes: 0 additions & 15 deletions backend/src/tests/modules/page/test_get_pages.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
"""Module for testing the use case "Get Pages"."""
import pytest

from kwai.core.db.database import Database
from kwai.modules.page.get_pages import GetPages, GetPagesCommand
from kwai.modules.page.pages.page import PageEntity
from kwai.modules.page.pages.page_db_repository import PageDbRepository
from kwai.modules.page.pages.page_repository import PageRepository


@pytest.fixture(scope="module")
def repo(database: Database) -> PageRepository:
"""Fixture for a page repository."""
return PageDbRepository(database)


@pytest.fixture(scope="module")
async def saved_page(repo: PageRepository, page: PageEntity) -> PageEntity:
"""Fixture for a page stored in the database."""
return await repo.create(page)


async def test_get_pages(repo: PageRepository, saved_page: PageEntity):
"""Test use case."""
command = GetPagesCommand()
Expand Down

0 comments on commit 1a37751

Please sign in to comment.