Merge branch 'optimisation' into exo5

This commit is contained in:
2026-02-09 23:16:44 +01:00
2 changed files with 129 additions and 43 deletions

View File

@@ -10,7 +10,47 @@ def mock_site():
with Mocker() as m:
m.get(
"https://www.millesima.fr/",
text="<html><body><h1>MILLESIMA</h1></body></html>",
text=f"""
<html>
<body>
<script id="__NEXT_DATA__" type="application/json">
{dumps({
"props": {
"pageProps": {
"initialReduxState": {
"product": {
"content": {
"items": [],
"attributes": {}
}
}
}
}
}
})}
</script>
</body>
</html>
""",
)
m.get(
"https://www.millesima.fr/poubelle",
text=f"""
<html>
<body>
<h1>POUBELLE</h1>
<script id="__NEXT_DATA__" type="application/json">
{dumps({
"props": {
"pageProps": {
}
}
})}
</script>
</body>
</html>
""",
)
json_data = {
@@ -80,9 +120,9 @@ def mock_site():
"isSpirit": False,
},
"note_jr": {
"valueId": "17",
"valueId": "17+",
"name": "J. Robinson",
"value": "17",
"value": "17+",
"isSpirit": False,
},
"note_js": {
@@ -101,10 +141,12 @@ def mock_site():
html_product = f"""
<html>
<script id="__NEXT_DATA__" type="application/json">
{dumps(json_data)}
</script>
</body>
<body>
<h1>MILLESIMA</h1>
<script id="__NEXT_DATA__" type="application/json">
{dumps(json_data)}
</script>
</body>
</html>
"""
m.get(
@@ -123,20 +165,53 @@ def scraper() -> Scraper:
# EXO1
def test_soup(scraper: Scraper):
h1: Tag | None = scraper.getsoup("").find("h1")
assert isinstance(h1, Tag)
assert h1.text == "MILLESIMA"
vide = scraper.getsoup("")
poubelle = scraper.getsoup("poubelle")
contenu = scraper.getsoup("nino-negri-5-stelle-sfursat-2022.html")
assert vide.find("h1") is None
assert str(poubelle.find("h1")) == "<h1>POUBELLE</h1>"
assert str(contenu.find("h1")) == "<h1>MILLESIMA</h1>"
# EXO3
def test_appellation(scraper: Scraper):
appellation = scraper.getjsondata("nino-negri-5-stelle-sfursat-2022.html")
assert appellation.appellation() == "Sforzato di Valtellina"
vide = scraper.getjsondata("")
poubelle = scraper.getjsondata("poubelle")
contenu = scraper.getjsondata("nino-negri-5-stelle-sfursat-2022.html")
assert vide.appellation() is None
assert poubelle.appellation() is None
assert contenu.appellation() == "Sforzato di Valtellina"
# test fonctions privée
def test_fonctionprivee(scraper: Scraper):
vide = scraper.getjsondata("")
poubelle = scraper.getjsondata("poubelle")
contenu = scraper.getjsondata("nino-negri-5-stelle-sfursat-2022.html")
assert vide._getattributes() is not None
assert vide._getattributes() == {}
assert vide._getcontent() is not None
assert vide._getcontent() == {"items": [], "attributes": {}}
assert poubelle._getattributes() is None
assert poubelle._getcontent() is None
assert contenu._getcontent() is not None
assert contenu._getattributes() is not None
# EXO4-5
def test_critiques(scraper: Scraper):
critiques = scraper.getjsondata("nino-negri-5-stelle-sfursat-2022.html")
assert critiques.parker() == "91"
assert critiques.robinson() == "17"
assert critiques.suckling() == "93.5"
vide = scraper.getjsondata("")
poubelle = scraper.getjsondata("poubelle")
contenu = scraper.getjsondata("nino-negri-5-stelle-sfursat-2022.html")
assert vide.parker() is None
assert vide.robinson() is None
assert vide.suckling() is None
assert vide._getcritiques("test_ts") is None
assert poubelle.parker() is None
assert poubelle.robinson() is None
assert poubelle.suckling() is None
assert poubelle._getcritiques("test_ts") is None
assert contenu.parker() == "91"
assert contenu.robinson() == "17"
assert contenu.suckling() == "93.5"
assert contenu._getcritiques("test_ts") is None