feat: implement remaining repo methods for chatbot and quote
This commit is contained in:
parent
95101a6573
commit
4b7ffbc914
10 changed files with 352 additions and 177 deletions
|
|
@ -65,7 +65,7 @@ def db(s, cdb):
|
|||
pass
|
||||
|
||||
async def list( # type: ignore[empty-body]
|
||||
self, obj: BaseModel, offset: int = 0, limit: int = 10, auto_commit=True
|
||||
self, offset: int = 0, limit: int = 10, auto_commit=True
|
||||
) -> list[BaseModel]:
|
||||
pass
|
||||
|
||||
|
|
@ -169,6 +169,16 @@ async def chatbot(chatbot_factory, user):
|
|||
return chatbot_factory.build(user_id=user.id)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def five_chatbots(chatbot_factory, user):
|
||||
return [chatbot_factory.build() for _ in range(5)]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def persisted_five_chatbots(five_chatbots, chatbot_repo):
|
||||
return [await chatbot_repo.create(chatbot) for chat in five_chatbots]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def persisted_chatbot(chatbot_repo, chatbot, persisted_user):
|
||||
return await chatbot_repo.create(chatbot)
|
||||
|
|
@ -204,11 +214,21 @@ async def quote(quote_factory):
|
|||
return quote_factory.build()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def five_quotes(quote_factory):
|
||||
return [quote_factory.build() for _ in range(5)]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def persisted_quote(quote_repo, quote):
|
||||
return await quote_repo.create(quote)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def persisted_five_quotes(five_quotes, quote_repo):
|
||||
return [await quote_repo.create(quote) for quote in five_quotes]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def create_quote_svc(quote_repo):
|
||||
return CreateQuoteSvc(repo=quote_repo)
|
||||
|
|
|
|||
|
|
@ -88,8 +88,79 @@ async def test_update_chatbot_raises_value_error_on_non_existing_chatbot(
|
|||
await chatbot_repo.update(chatbot)
|
||||
|
||||
|
||||
async def test_delete_chatbot_raises_value_error_on_non_existing_chatbot(
|
||||
chatbot_repo, chatbot
|
||||
):
|
||||
with pytest.raises(ValueError, match=f"Chatbot {chatbot.id} does not exist"):
|
||||
await chatbot_repo.delete(chatbot)
|
||||
|
||||
|
||||
async def test_delete_chatbot(chatbot_repo, persisted_chatbot):
|
||||
assert await chatbot_repo.delete(persisted_chatbot) is None
|
||||
assert await chatbot_repo.get_by_id(persisted_chatbot.id) is None
|
||||
|
||||
|
||||
async def test_get_by_id(chatbot_repo, persisted_chatbot):
|
||||
chatbot = await chatbot_repo.get_by_id(persisted_chatbot.id)
|
||||
assert chatbot == persisted_chatbot
|
||||
|
||||
|
||||
async def test_list(chatbot_repo, persisted_five_chatbots):
|
||||
chatbots = await chatbot_repo.list()
|
||||
assert len(chatbots) == 5 # noqa: PLR2004
|
||||
|
||||
|
||||
async def test_list_offset_limit(chatbot_repo, persisted_five_chatbots):
|
||||
chatbots = await chatbot_repo.list(offset=1, limit=2)
|
||||
assert len(chatbots) == 2 # noqa: PLR2004
|
||||
|
||||
|
||||
async def test_get_random_quote(quote_repo: QuoteRepo, persisted_quote):
|
||||
quote = await quote_repo.get_random(persisted_quote.channel_name)
|
||||
assert quote
|
||||
assert quote.author == persisted_quote.author
|
||||
assert quote.channel_name == persisted_quote.channel_name
|
||||
|
||||
|
||||
async def test_create_quote_raises_value_error_for_existing_quote(
|
||||
quote_repo: QuoteRepo, persisted_quote
|
||||
):
|
||||
with pytest.raises(
|
||||
ValueError, match=f"Quote {persisted_quote.quote} already exists"
|
||||
):
|
||||
await quote_repo.create(persisted_quote)
|
||||
|
||||
|
||||
async def test_create_quote(quote_repo: QuoteRepo, quote_factory):
|
||||
quote = quote_factory.build()
|
||||
created_quote = await quote_repo.create(quote)
|
||||
assert created_quote == quote
|
||||
|
||||
|
||||
async def test_update_quote_raises_value_error_on_non_existing_quote(
|
||||
quote_repo: QuoteRepo, quote
|
||||
):
|
||||
with pytest.raises(ValueError, match=f"Quote {quote.id} does not exist"):
|
||||
await quote_repo.update(quote)
|
||||
|
||||
|
||||
async def test_update_quote(quote_repo: QuoteRepo, persisted_quote):
|
||||
persisted_quote.quote = "new quote"
|
||||
updated_quote = await quote_repo.update(persisted_quote)
|
||||
persisted_quote.last_updated_at = updated_quote.last_updated_at
|
||||
assert updated_quote == persisted_quote
|
||||
|
||||
|
||||
async def test_delete_quote(quote_repo: QuoteRepo, persisted_quote):
|
||||
assert await quote_repo.delete(persisted_quote) is None
|
||||
assert await quote_repo.get_by_id(persisted_quote.id) is None
|
||||
|
||||
|
||||
async def test_list_quotes(quote_repo, persisted_five_quotes):
|
||||
quotes = await quote_repo.list()
|
||||
assert len(quotes) == 5 # noqa: PLR2004
|
||||
|
||||
|
||||
async def test_list_quotes_offset_limit(quote_repo, persisted_five_quotes):
|
||||
quotes = await quote_repo.list(offset=1, limit=2)
|
||||
assert len(quotes) == 2 # noqa: PLR2004
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue