mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 23:55:46 +02:00
Test all crud stuff up until now
This commit is contained in:
parent
a0781a046b
commit
e4e77502e8
4 changed files with 64 additions and 2 deletions
|
|
@ -23,6 +23,7 @@ async def wordle_game(wordle_collection: MongoCollection, test_user_id: int) ->
|
|||
yield game
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
async def test_start_new_game(mongodb: MongoDatabase, wordle_collection: MongoCollection, test_user_id: int):
|
||||
"""Test starting a new game"""
|
||||
result = await wordle_collection.find_one({"user_id": test_user_id})
|
||||
|
|
@ -34,24 +35,28 @@ async def test_start_new_game(mongodb: MongoDatabase, wordle_collection: MongoCo
|
|||
assert result is not None
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
async def test_get_active_wordle_game_none(mongodb: MongoDatabase, test_user_id: int):
|
||||
"""Test getting an active game when there is none"""
|
||||
result = await crud.get_active_wordle_game(mongodb, test_user_id)
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
async def test_get_active_wordle_game(mongodb: MongoDatabase, wordle_game: WordleGame):
|
||||
"""Test getting an active game when there is one"""
|
||||
result = await crud.get_active_wordle_game(mongodb, wordle_game.user_id)
|
||||
assert result.dict(by_alias=True) == wordle_game.dict(by_alias=True)
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
async def test_get_daily_word_none(mongodb: MongoDatabase):
|
||||
"""Test getting the daily word when the database is empty"""
|
||||
result = await crud.get_daily_word(mongodb)
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
@freeze_time("2022-07-30")
|
||||
async def test_get_daily_word_not_today(mongodb: MongoDatabase):
|
||||
"""Test getting the daily word when there is an entry, but not for today"""
|
||||
|
|
@ -64,6 +69,7 @@ async def test_get_daily_word_not_today(mongodb: MongoDatabase):
|
|||
assert await crud.get_daily_word(mongodb) is None
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
@freeze_time("2022-07-30")
|
||||
async def test_get_daily_word_present(mongodb: MongoDatabase):
|
||||
"""Test getting the daily word when there is one for today"""
|
||||
|
|
@ -74,3 +80,56 @@ async def test_get_daily_word_present(mongodb: MongoDatabase):
|
|||
await collection.insert_one({"key": TempStorageKey.WORDLE_WORD, "day": day, "word": word})
|
||||
|
||||
assert await crud.get_daily_word(mongodb) == word
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
@freeze_time("2022-07-30")
|
||||
async def test_set_daily_word_none_present(mongodb: MongoDatabase):
|
||||
"""Test setting the daily word when there is none"""
|
||||
assert await crud.get_daily_word(mongodb) is None
|
||||
word = "testword"
|
||||
await crud.set_daily_word(mongodb, word)
|
||||
assert await crud.get_daily_word(mongodb) == word
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
@freeze_time("2022-07-30")
|
||||
async def test_set_daily_word_present(mongodb: MongoDatabase):
|
||||
"""Test setting the daily word when there already is one"""
|
||||
word = "testword"
|
||||
await crud.set_daily_word(mongodb, word)
|
||||
await crud.set_daily_word(mongodb, "another word")
|
||||
assert await crud.get_daily_word(mongodb) == word
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
@freeze_time("2022-07-30")
|
||||
async def test_set_daily_word_force_overwrite(mongodb: MongoDatabase):
|
||||
"""Test setting the daily word when there already is one, but "forced" is set to True"""
|
||||
word = "testword"
|
||||
await crud.set_daily_word(mongodb, word)
|
||||
word = "anotherword"
|
||||
await crud.set_daily_word(mongodb, word, forced=True)
|
||||
assert await crud.get_daily_word(mongodb) == word
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
async def test_make_wordle_guess(mongodb: MongoDatabase, wordle_game: WordleGame, test_user_id: int):
|
||||
"""Test making a guess in your current game"""
|
||||
guess = "guess"
|
||||
await crud.make_wordle_guess(mongodb, test_user_id, guess)
|
||||
wordle_game = await crud.get_active_wordle_game(mongodb, test_user_id)
|
||||
assert wordle_game.guesses == [guess]
|
||||
|
||||
other_guess = "otherguess"
|
||||
await crud.make_wordle_guess(mongodb, test_user_id, other_guess)
|
||||
wordle_game = await crud.get_active_wordle_game(mongodb, test_user_id)
|
||||
assert wordle_game.guesses == [guess, other_guess]
|
||||
|
||||
|
||||
@pytest.mark.mongo
|
||||
async def test_reset_wordle_games(mongodb: MongoDatabase, wordle_game: WordleGame, test_user_id: int):
|
||||
"""Test dropping the collection of active games"""
|
||||
assert await crud.get_active_wordle_game(mongodb, test_user_id) is not None
|
||||
await crud.reset_wordle_games(mongodb)
|
||||
assert await crud.get_active_wordle_game(mongodb, test_user_id) is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue