feat: add support for new ratings page
Genres are no longer available for ratings, so we make them optional. Adds support for validating generics in union types.
This commit is contained in:
parent
06e60fb212
commit
1a7d85b31d
7 changed files with 385 additions and 37 deletions
BIN
tests/fixtures/ratings-ur655321-20240510.gql.json.bz2
vendored
Normal file
BIN
tests/fixtures/ratings-ur655321-20240510.gql.json.bz2
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/ratings-ur655321-20240510.html.bz2
vendored
Normal file
BIN
tests/fixtures/ratings-ur655321-20240510.html.bz2
vendored
Normal file
Binary file not shown.
|
|
@ -1,4 +1,5 @@
|
|||
import bz2
|
||||
import json
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
|
|
@ -75,10 +76,102 @@ async def test_load_ratings_page(monkeypatch):
|
|||
|
||||
monkeypatch.setattr(imdb, "asoup_from_url", AsyncMock(return_value=soup))
|
||||
|
||||
page = await imdb.load_ratings_page("fakeurl")
|
||||
page = await imdb._load_ratings_page("fakeurl", "ur655321")
|
||||
assert len(page.ratings) == 100
|
||||
assert page.imdb_user_id is not None
|
||||
assert page.imdb_user_id == "ur655321"
|
||||
assert page.imdb_user_name == "AlexUltra"
|
||||
assert page.next_page_url is not None
|
||||
assert page.next_page_url.startswith("/user/ur655321/ratings?")
|
||||
|
||||
|
||||
def _mock_response(content: bytes):
|
||||
class MockResponse:
|
||||
def raise_for_status(self):
|
||||
pass
|
||||
|
||||
def json(self):
|
||||
return json.loads(content)
|
||||
|
||||
return MockResponse()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_ratings_page_20240510(monkeypatch):
|
||||
with bz2.open(fixturesdir / "ratings-ur655321-20240510.html.bz2", "rb") as f:
|
||||
html = f.read()
|
||||
soup = bs4.BeautifulSoup(html, "html5lib")
|
||||
monkeypatch.setattr(imdb, "asoup_from_url", AsyncMock(return_value=soup))
|
||||
|
||||
with bz2.open(fixturesdir / "ratings-ur655321-20240510.gql.json.bz2", "rb") as f:
|
||||
jsonstr = f.read()
|
||||
async with imdb.asession() as s:
|
||||
monkeypatch.setattr(s, "post", AsyncMock(return_value=_mock_response(jsonstr)))
|
||||
page = await imdb._load_ratings_page("fakeurl", "ur655321")
|
||||
assert len(page.ratings) == 100
|
||||
assert page.imdb_user_id is not None
|
||||
assert page.imdb_user_id == "ur655321"
|
||||
assert page.imdb_user_name == "AlexUltra"
|
||||
assert page.next_page_url is None, "not supported for new ratings page"
|
||||
|
||||
def movie(item: dict):
|
||||
for rating in page.ratings:
|
||||
assert rating.movie
|
||||
if rating.movie.imdb_id == item["imdb_id"]:
|
||||
rating_dict = {key: getattr(rating.movie, key) for key in item.keys()}
|
||||
return rating_dict
|
||||
raise AssertionError()
|
||||
|
||||
a_movie = {
|
||||
"title": "Kung Fu Panda 4",
|
||||
"release_year": 2024,
|
||||
"media_type": "Movie",
|
||||
"imdb_id": "tt21692408",
|
||||
"imdb_score": 59,
|
||||
"imdb_votes": 36000,
|
||||
"runtime": 94,
|
||||
}
|
||||
assert a_movie == movie(a_movie)
|
||||
|
||||
a_running_tvseries = {
|
||||
"title": "Palm Royale",
|
||||
"release_year": 2024,
|
||||
"media_type": "TV Series",
|
||||
"imdb_id": "tt8888540",
|
||||
"imdb_score": 64,
|
||||
"imdb_votes": 6000,
|
||||
}
|
||||
assert a_running_tvseries == movie(a_running_tvseries)
|
||||
|
||||
a_finished_tvseries = {
|
||||
"title": "Fawlty Towers",
|
||||
"release_year": 1975,
|
||||
"media_type": "TV Series",
|
||||
"imdb_id": "tt0072500",
|
||||
"imdb_score": 87,
|
||||
"imdb_votes": 100000,
|
||||
}
|
||||
assert a_finished_tvseries == movie(a_finished_tvseries)
|
||||
|
||||
a_tvepisode = {
|
||||
"title": "Columbo / No Time to Die",
|
||||
"original_title": None,
|
||||
"release_year": 1992,
|
||||
"media_type": "TV Episode",
|
||||
"imdb_id": "tt0103987",
|
||||
"imdb_score": 59,
|
||||
"imdb_votes": 2100,
|
||||
"runtime": 98,
|
||||
}
|
||||
assert a_tvepisode == movie(a_tvepisode)
|
||||
|
||||
a_videogame = {
|
||||
"title": "Alan Wake",
|
||||
"original_title": None,
|
||||
"release_year": 2010,
|
||||
"media_type": "Video Game",
|
||||
"imdb_id": "tt0466662",
|
||||
"imdb_score": 82,
|
||||
"imdb_votes": 7300,
|
||||
}
|
||||
assert a_videogame == movie(a_videogame)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue