Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-33646)[API] fix: allow none values in titelive response for images #15775

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class TiteliveArticle(BaseModel):
gtl: TiteliveGtl | None
has_image: bool = pydantic_v1.Field(alias="image")
has_verso_image: bool = pydantic_v1.Field(alias="image_4")
imagesUrl: TiteliveImage
imagesUrl: TiteliveImage | None
# TODO: (lixxday, 2024-04-17): titlelive sends an int for dispo, casting to str works ; but we probably want to change this
dispo: str
dispo: str | None
# TODO: (lixxday, 2024-04-17): titlelive sends a float for prix, casting to str works ; but we probably want to change this
prix: str | None
resume: str | None
Expand Down
2 changes: 2 additions & 0 deletions api/src/pcapi/core/providers/titelive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def update_product_thumbnails(
for work in titelive_page:
for article in work.article:
thumbnail_url_by_ean[article.gencod] = {}
if not article.imagesUrl:
continue
if article.has_image:
thumbnail_url_by_ean[article.gencod][
offers_models.TiteliveImageType.RECTO
Expand Down
208 changes: 208 additions & 0 deletions api/tests/connectors/titelive/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,214 @@ def build_titelive_one_book_response(
"changeEncodingTo": "UTF-8",
}

NO_IMAGE_IN_RESULT_FIXTURE = {
"type": 1,
"magid": "6505",
"nombre": 10,
"page": "1",
"result": [
{
"id": 1151334,
"titre": "Mortelle Adèle Tome 1 : tout ça finira mal",
"auteurs": "Mr tan, Miss prickly, Rémi Chaurand",
"auteurs_multi": ["Mr tan", "Miss prickly", "Rémi Chaurand"],
"auteurs_id": [],
"auteurs_fonctions": [],
"realisateur_multi": [],
"article": {
"1": {
"nombre": 0,
"gencod": "9782848018676",
"id_catalogue": ["0"],
"collection_no": "0",
"editeur": "BAYARD JEUNESSE",
"distributeur": "HACHETTE",
"code_distributeur": "64",
"prix": 11.5,
"prixpays": {
"fr": {"value": 11.5, "devise": "€"},
"be": {"value": 12.9, "devise": "€"},
"ch": {"value": 17.8, "devise": "CHF"},
},
"dateparution": "06/06/2013",
"dateparutionentier": 1370469600,
"dispo": 1,
"dispopays": {"fr": 1, "be": 1, "ch": 1},
"libelledispo": "Disponible",
"resume": "« Que ce soit pour faire enrager mes parents, torturer mon stupide chat, lutter contre Jade et ses copines ou briser le coeur de Geoffroy... j'ai toujours une idée intéressante ! »\r\n\r\nUne bonne dose d'humour noir et un soupçon de tendresse, voici la recette d'Adèle, une héroïne d'un nouveau genre... Accrochez votre ceinture, ça va déménager !\r\n\r\n© Mr Tan / Miss Prickly",
"image": 0,
"image_spe": 0,
"image_alkor": 0,
"image_4": 0,
# No imageUrl in the response here
"detailUrl": "/livre/9782848018676-mortelle-adele-tome-1-tout-ca-finira-mal-mr-tan-miss-prickly-remi-chaurand/",
"langue": "Français",
"langueiso": "fra",
"langueflag": "https://static.epagine.fr/commonfiles/flags/fr.png",
"nbmag": "996",
"codesupport": "T",
"libellesupport": "Grand format",
"codesupport2": [],
"libellesupport2": [],
"chapitre": 0,
"biblio": "0",
"extrait": 0,
"extrait_oeuvre": "1",
"pages": "96",
"longueur": 20.2,
"largeur": 16,
"hauteur": 0,
"epaisseur": 1,
"poids": "282",
"biographie": "1",
"biographies": [],
"websites": [],
"datecreation": "18/01/2013",
"datecreationentier": 1358463600,
"datemodification": "21/03/2024",
"serie": "mortelle Adèle",
"idserie": "2170",
"scolaire": "0",
"lectorat": "à partir de 8 ANS",
"livre_etranger": "0",
"racine_editeur": "27470",
"code_clil": "3772",
"type_prix": "4",
"contenu_explicite": 0,
"nb_galettes": 0,
"duree": 0,
"anneesortie": 0,
"interpretes": [],
"typeproduit": 0,
"colors": [],
"langues": [],
"audios": [],
"soustitres": [],
"iad": "0",
"id_code_langue": "10000",
"taux_tva": "5.50",
"code_tva": "2",
"nboccasions": 0,
"stock": 0,
"gtl": {
"first": {
"1": {"code": "3000000", "libelle": "Bandes dessinées / Comics / Mangas"},
"2": {"code": "3020000", "libelle": "Bandes dessinées"},
"3": {"code": "3020200", "libelle": "Tout public"},
"4": {"code": "3020211", "libelle": "Humour"},
}
},
"gtlvideo": [],
"operations": [],
"tracks": [],
"cmb": "130114",
"deee_ht": 0,
"tva": 0,
"minutesdejeu": 0,
"nbjoueursmin": 0,
"nbjoueursmax": 0,
"colisage": 0,
"longueurboite": 0,
"largeurboite": 0,
"hauteurboite": 0,
"grammesboite": 0,
"nbpiles": 0,
"pilesincluses": 0,
"nbanneegarantie": 0,
"produits_recycles": 0,
"nbpages": 0,
"grammage": 0,
"taille_ecriture_mm": 0,
"poignee": 0,
"lavable": 0,
"impermeable": 0,
"contenance_ml": 0,
"nbfeuilles": 0,
"diametre": 0,
"diametreboite": 0,
"garantiemois": 0,
"precommande": 0,
"ispromotion": 0,
"isnew": 0,
"multijoueur": 0,
"nblicenses": 0,
"nbutilisateur": 0,
"internet": 0,
"pegi": [],
"solo": 0,
"online": 0,
"avertissement": [],
"drmlcp": 0,
"bonus_extraits": {
"gencod": "9782848018676",
"pagesinterieures": "0",
"pdfextrait": "0",
"pdfchapitre": "0",
"pdfparagraphe": "0",
"mp3_count": "0",
},
"id_lectorat": "5",
"livre_lu": "0",
"grands_caracteres": "0",
"multilingue": "0",
"illustre": "0",
"luxe": "0",
"relie": "0",
"broche": "1",
"lectureEnLigne": 0,
"NombreMagasins": 0,
"collector": "0",
"code_editeur": "12165",
"sorecop": 0,
"pcb": 0,
"spcb": 0,
"volume": 0,
"compartiment": 0,
"poche": 0,
},
},
"biographies": [],
"websites": [],
"typeproduit": 1,
},
],
"suggestions": [],
"nbreponses": 50000,
"temps": 1.18904,
"tri_ordre": "desc",
"params": {
"base": "paper",
"login": "PASSCULTURE",
"mid": "6505",
"nombre": "2",
"page": "1",
"hash": "839cbc2ea11289d2f551e829aa8d3749",
"dispo": [0, 1, 2],
"biblio": 0,
"is_promotion": 0,
"magasin": ["6505"],
"support": 1,
"ws": 1,
},
"exact": [],
"version": "json",
"magasin": ["6505", 0],
"support": "1",
"dispo": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"biblio": 0,
"stocks": 0,
"drmlcp": 0,
"occasion": 0,
"image": 0,
"ws": 1,
"compatibility": [],
"is_promotion": 0,
"flou": 0,
"idserie": 0,
"scolaire": 0,
"changeEncodingTo": "UTF-8",
}


# Extracted from actual response:
# curl --location 'https://catsearch.epagine.fr/v1/ean/9782070455379' --header 'Authorization: Bearer xxx'
Expand Down
9 changes: 9 additions & 0 deletions api/tests/providers/titelive_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,12 @@ def test_ignores_verso_image_if_it_is_a_placeholder(self, requests_mock):

assert product_with_verso_image is not None
assert product_with_verso_image.images.get("verso") is not None

def test_does_serialize_if_no_image(self, requests_mock):
self.setup_api_response_fixture(requests_mock, fixtures.NO_IMAGE_IN_RESULT_FIXTURE)

TiteliveBookSearch().synchronize_products(datetime.date(2022, 12, 1))

(product,) = offers_models.Product.query.all()

assert product.images.get("recto") is None
Loading