fix: support new "most popular 100" & "bottom 100" HTML
The previous version had all 100 movies rendered into the HTML. The new version has only the top 25 rendered into HTML, but the whole list has been made available as LD+JSON data. Since we can easily support both, we don't (yet) remove the old parser.
This commit is contained in:
parent
aaaf66c715
commit
d7530e6bb0
4 changed files with 54 additions and 14 deletions
BIN
tests/fixtures/bottom_100-20240714.html.bz2
vendored
Normal file
BIN
tests/fixtures/bottom_100-20240714.html.bz2
vendored
Normal file
Binary file not shown.
BIN
tests/fixtures/most_popular_100-20240714.html.bz2
vendored
Normal file
BIN
tests/fixtures/most_popular_100-20240714.html.bz2
vendored
Normal file
Binary file not shown.
|
|
@ -30,29 +30,43 @@ def test_score_conversion(score: int):
|
|||
assert score == score_from_imdb_rating(imdb_rating_from_score(score))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"fixture",
|
||||
(
|
||||
("most_popular_100.html.bz2"),
|
||||
("most_popular_100-20240714.html.bz2"),
|
||||
),
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_most_popular_100(monkeypatch):
|
||||
with bz2.open(fixturesdir / "most_popular_100.html.bz2", "rb") as f:
|
||||
async def test_load_most_popular_100(monkeypatch, fixture: str):
|
||||
with bz2.open(fixturesdir / fixture, "rb") as f:
|
||||
html = f.read()
|
||||
soup = bs4.BeautifulSoup(html, "html5lib")
|
||||
|
||||
monkeypatch.setattr(imdb, "asoup_from_url", AsyncMock(return_value=soup))
|
||||
|
||||
movie_ids = await imdb.load_most_popular_100()
|
||||
assert len(movie_ids) == 100
|
||||
assert len(set(movie_ids)) == 100
|
||||
assert all(id_.startswith("tt") for id_ in movie_ids)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"fixture",
|
||||
(
|
||||
("bottom_100.html.bz2"),
|
||||
("bottom_100-20240714.html.bz2"),
|
||||
),
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_bottom_100(monkeypatch):
|
||||
with bz2.open(fixturesdir / "bottom_100.html.bz2", "rb") as f:
|
||||
async def test_load_bottom_100(monkeypatch, fixture: str):
|
||||
with bz2.open(fixturesdir / fixture, "rb") as f:
|
||||
html = f.read()
|
||||
soup = bs4.BeautifulSoup(html, "html5lib")
|
||||
|
||||
monkeypatch.setattr(imdb, "asoup_from_url", AsyncMock(return_value=soup))
|
||||
|
||||
movie_ids = await imdb.load_bottom_100()
|
||||
assert len(movie_ids) == 100
|
||||
assert len(set(movie_ids)) == 100
|
||||
assert all(id_.startswith("tt") for id_ in movie_ids)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue