feat: add awards to REST response
This commit is contained in:
parent
f0f69c1954
commit
b0f5ec4cc9
5 changed files with 142 additions and 5 deletions
|
|
@ -32,6 +32,74 @@ def admin_client() -> TestClient:
|
|||
return client
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_ratings_for_group_with_awards(
|
||||
conn: db.Connection, unauthorized_client: TestClient
|
||||
):
|
||||
user = models.User(
|
||||
imdb_id="ur12345678",
|
||||
name="user-1",
|
||||
secret="secret-1", # noqa: S106
|
||||
groups=[],
|
||||
)
|
||||
group = models.Group(
|
||||
name="group-1",
|
||||
users=[models.GroupUser(id=str(user.id), name=user.name)],
|
||||
)
|
||||
user.groups = [models.UserGroup(id=str(group.id), access="r")]
|
||||
path = app.url_path_for("get_ratings_for_group", group_id=str(group.id))
|
||||
|
||||
await db.add(conn, user)
|
||||
await db.add(conn, group)
|
||||
|
||||
movie1 = models.Movie(
|
||||
title="test movie",
|
||||
release_year=2013,
|
||||
media_type="Movie",
|
||||
imdb_id="tt12345678",
|
||||
genres={"genre-1"},
|
||||
)
|
||||
await db.add(conn, movie1)
|
||||
movie2 = models.Movie(
|
||||
title="test movie 2",
|
||||
release_year=2014,
|
||||
media_type="Movie",
|
||||
imdb_id="tt12345679",
|
||||
genres={"genre-2"},
|
||||
)
|
||||
await db.add(conn, movie2)
|
||||
|
||||
award1 = models.Award(
|
||||
movie_id=movie1.id, category="imdb-top-250", details='{"position":23}'
|
||||
)
|
||||
award2 = models.Award(
|
||||
movie_id=movie2.id, category="imdb-top-250", details='{"position":99}'
|
||||
)
|
||||
await db.add(conn, award1)
|
||||
await db.add(conn, award2)
|
||||
|
||||
rating = models.Rating(
|
||||
movie_id=movie1.id, user_id=user.id, score=66, rating_date=datetime.now(tz=UTC)
|
||||
)
|
||||
await db.add(conn, rating)
|
||||
|
||||
rating_aggregate = {
|
||||
"canonical_title": movie1.title,
|
||||
"imdb_score": movie1.imdb_score,
|
||||
"imdb_votes": movie1.imdb_votes,
|
||||
"link": imdb.movie_url(movie1.imdb_id),
|
||||
"media_type": movie1.media_type,
|
||||
"original_title": movie1.original_title,
|
||||
"user_scores": [rating.score],
|
||||
"year": movie1.release_year,
|
||||
"awards": ["imdb-top-250:23"],
|
||||
}
|
||||
|
||||
resp = unauthorized_client.get(path)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json() == [rating_aggregate]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_ratings_for_group(
|
||||
conn: db.Connection, unauthorized_client: TestClient
|
||||
|
|
@ -82,6 +150,7 @@ async def test_get_ratings_for_group(
|
|||
"original_title": movie.original_title,
|
||||
"user_scores": [rating.score],
|
||||
"year": movie.release_year,
|
||||
"awards": [],
|
||||
}
|
||||
|
||||
resp = unauthorized_client.get(path)
|
||||
|
|
@ -158,6 +227,7 @@ async def test_list_movies(
|
|||
"original_title": m.original_title,
|
||||
"user_scores": [],
|
||||
"year": m.release_year,
|
||||
"awards": [],
|
||||
}
|
||||
|
||||
response = authorized_client.get(path, params={"imdb_id": m.imdb_id})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue