Coverage for src/tests/modules/portal/repositories/test_author_db_repository.py: 100%
23 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 author database repository."""
3import pytest
5from kwai_bc_portal.repositories.author_db_repository import AuthorDbRepository
6from kwai_core.db.database import Database
9pytestmark = [pytest.mark.db]
12async def test_create_author(database: Database, make_author, make_user_account_in_db):
13 """Test saving an author."""
14 author = make_author(user_account=await make_user_account_in_db())
15 author = await AuthorDbRepository(database).create(author)
16 assert author is not None, "There should be an author"
19async def test_get_author(database: Database, make_author_in_db):
20 """Test fetching an author."""
21 author = await make_author_in_db()
22 uuid = author.uuid
23 author = await AuthorDbRepository(database).get(author.id)
24 assert author is not None, "There should be an author"
25 assert author.uuid == uuid, "The unique id should be the same"
28async def test_get_author_by_uuid(
29 database: Database, make_author_in_db, make_user_account_in_db
30):
31 """Test fetching an author."""
32 user_account = await make_user_account_in_db()
33 author = await make_author_in_db(user_account=user_account)
34 author = await AuthorDbRepository(database).get_by_uuid(user_account.user.uuid)
35 assert author is not None, "There should be an author with the given uuid"
38async def test_get_all(database: Database, make_author_in_db):
39 """Test fetching all authors."""
40 await make_author_in_db()
41 result = AuthorDbRepository(database).get_all()
42 assert await anext(result) is not None, "There should be an author."