fix: tests sometimes failed because of missing sorting
This commit is contained in:
parent
1a7d85b31d
commit
05d387a6b5
4 changed files with 20 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -141,21 +141,21 @@ async def test_remove(conn: db.Connection):
|
|||
@pytest.mark.asyncio
|
||||
async def test_find_ratings(conn: db.Connection):
|
||||
m1 = a_movie(
|
||||
title="test movie",
|
||||
title="a test movie",
|
||||
release_year=2013,
|
||||
genres={"genre-1"},
|
||||
)
|
||||
await db.add(conn, m1)
|
||||
|
||||
m2 = a_movie(
|
||||
title="it's anöther Movie, Part 2",
|
||||
title="b it's anöther Movie, Part 2",
|
||||
release_year=2015,
|
||||
genres={"genre-2"},
|
||||
)
|
||||
await db.add(conn, m2)
|
||||
|
||||
m3 = a_movie(
|
||||
title="movie it's, Part 3",
|
||||
title="c movie it's, Part 3",
|
||||
release_year=m2.release_year,
|
||||
genres=m2.genres,
|
||||
)
|
||||
|
|
@ -181,7 +181,7 @@ async def test_find_ratings(conn: db.Connection):
|
|||
user_id=u1.id,
|
||||
user=u1,
|
||||
score=66,
|
||||
rating_date=datetime.now(),
|
||||
rating_date=datetime.now(tz=UTC),
|
||||
)
|
||||
await db.add(conn, r1)
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ async def test_find_ratings(conn: db.Connection):
|
|||
user_id=u2.id,
|
||||
user=u2,
|
||||
score=77,
|
||||
rating_date=datetime.now(),
|
||||
rating_date=datetime.now(tz=UTC),
|
||||
)
|
||||
await db.add(conn, r2)
|
||||
|
||||
|
|
@ -224,35 +224,35 @@ async def test_find_ratings(conn: db.Connection):
|
|||
ratings = tuple(web_models.Rating(**r) for r in rows)
|
||||
assert (
|
||||
web_models.Rating.from_movie(m1),
|
||||
web_models.Rating.from_movie(m3),
|
||||
web_models.Rating.from_movie(m2, rating=r1),
|
||||
web_models.Rating.from_movie(m2, rating=r2),
|
||||
web_models.Rating.from_movie(m3),
|
||||
) == ratings
|
||||
|
||||
aggr = web_models.aggregate_ratings(ratings, user_ids=[])
|
||||
assert tuple(
|
||||
web_models.RatingAggregate.from_movie(m) for m in [m1, m2, m3]
|
||||
web_models.RatingAggregate.from_movie(m) for m in [m1, m3, m2]
|
||||
) == tuple(aggr)
|
||||
|
||||
aggr = web_models.aggregate_ratings(ratings, user_ids=[str(u1.id)])
|
||||
assert (
|
||||
web_models.RatingAggregate.from_movie(m1),
|
||||
web_models.RatingAggregate.from_movie(m2, ratings=[r1]),
|
||||
web_models.RatingAggregate.from_movie(m3),
|
||||
web_models.RatingAggregate.from_movie(m2, ratings=[r1]),
|
||||
) == tuple(aggr)
|
||||
|
||||
aggr = web_models.aggregate_ratings(ratings, user_ids=[str(u1.id), str(u2.id)])
|
||||
assert (
|
||||
web_models.RatingAggregate.from_movie(m1),
|
||||
web_models.RatingAggregate.from_movie(m2, ratings=[r1, r2]),
|
||||
web_models.RatingAggregate.from_movie(m3),
|
||||
web_models.RatingAggregate.from_movie(m2, ratings=[r1, r2]),
|
||||
) == tuple(aggr)
|
||||
|
||||
rows = await db.find_ratings(conn, title="movie", include_unrated=True)
|
||||
ratings = (web_models.Rating(**r) for r in rows)
|
||||
aggr = web_models.aggregate_ratings(ratings, user_ids=[])
|
||||
assert tuple(
|
||||
web_models.RatingAggregate.from_movie(m) for m in [m1, m2, m3]
|
||||
web_models.RatingAggregate.from_movie(m) for m in [m1, m3, m2]
|
||||
) == tuple(aggr)
|
||||
|
||||
rows = await db.find_ratings(conn, title="test", include_unrated=True)
|
||||
|
|
@ -288,7 +288,7 @@ async def test_ratings_for_movies(conn: db.Connection):
|
|||
user_id=u1.id,
|
||||
user=u1,
|
||||
score=66,
|
||||
rating_date=datetime.now(),
|
||||
rating_date=datetime.now(tz=UTC),
|
||||
)
|
||||
await db.add(conn, r1)
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ async def test_find_movies(conn: db.Connection):
|
|||
user_id=u1.id,
|
||||
user=u1,
|
||||
score=66,
|
||||
rating_date=datetime.now(),
|
||||
rating_date=datetime.now(tz=UTC),
|
||||
)
|
||||
await db.add(conn, r1)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue