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
|
|
@ -48,11 +48,13 @@ select = [
|
|||
# See https://docs.astral.sh/ruff/rules/ for a list of all rules.
|
||||
"B", # flake8-bugbear
|
||||
"C4", # flake8-comprehensions
|
||||
"DTZ", # flake8-datetimez
|
||||
"E", # pycodestyle Error
|
||||
"F", # Pyflakes unused-import
|
||||
"I", # isort
|
||||
"RUF", # Ruff-specific rules
|
||||
"S", # flake8-bandit
|
||||
"T20", # flake8-print
|
||||
"W", # pycodestyle Warning
|
||||
]
|
||||
ignore = [
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -582,6 +582,10 @@ async def ratings_for_movie_ids(
|
|||
)
|
||||
.outerjoin_from(movies, ratings, movies.c.id == ratings.c.movie_id)
|
||||
.where(sa.or_(*conds))
|
||||
.order_by(
|
||||
ratings.c.rating_date.asc(),
|
||||
movies.c.title.asc(),
|
||||
)
|
||||
)
|
||||
rows = await fetch_all(conn, query)
|
||||
return tuple(dict(r._mapping) for r in rows)
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ async def _load_ratings_page_legacy(url: str, soup: bs4.BeautifulSoup) -> _Ratin
|
|||
|
||||
|
||||
async def load_and_store_ratings(
|
||||
user_id: MovieId,
|
||||
user_id: UserId,
|
||||
) -> AsyncIterable[tuple[Rating, bool]]:
|
||||
async with db.new_connection() as conn:
|
||||
user = await db.get(conn, User, imdb_id=user_id) or User(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue