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
|
|
@ -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