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:
ducklet 2024-07-14 16:09:02 +02:00
parent aaaf66c715
commit d7530e6bb0
4 changed files with 54 additions and 14 deletions

Binary file not shown.

Binary file not shown.

View file

@ -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)