Skip to content

Commit

Permalink
✨ [FEAT] Add tests for CirkwiParser (refs #3947)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Nov 20, 2024
1 parent 90e8703 commit 2431963
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 32 deletions.
28 changes: 18 additions & 10 deletions geotrek/cirkwi/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@


class CirkwiParser(AttachmentParserMixin, Parser):
update_only = False
delete = False
"""
auth: Allow to configure HTTP auth on parser requests
create: Create a Cirkwi Locomotion from label, before trying to map it to a Trek Practice with same label
delete: Delete old objects that are now missing from flux (based on 'get_to_delete_kwargs')
default_language: Allow to define which language this parser will populate by default
eid: Field to use as Cirwki id
page_count: Amount of objects to load per page (Cirkwi pagination)
provider: Allow to differentiate multiple Parser for the same model
update_only: Do not delete previous objects, and query Cirkwi API with most recent date_update
"""
auth = ()
create = False
provider = "Cirkwi"
eid = 'eid'
delete = False
default_language = settings.MODELTRANSLATION_DEFAULT_LANGUAGE
eid = 'eid'
page_count = 10
provider = "Cirkwi"
update_only = False

field_options = {
"geom": {"required": True},
"name": {"required": True},
Expand All @@ -30,8 +43,6 @@ class CirkwiParser(AttachmentParserMixin, Parser):
non_fields = {
'attachments': "informations/information[@langue='<LANG>']/medias/images/image/*"
}
# Pagination : how many objects to retrieve per page
page_count = 10

def __init__(self, *args, **kwargs):
# Extract URL parameter to use to retrieve updates only
Expand Down Expand Up @@ -193,7 +204,7 @@ def filter_description(self, src, val):
if step_descriptions:
desc += "<ol>\r\n"
for step_description in step_descriptions:
desc += f"<li>{step_description}</li>\r\n"
desc += f"<li>{step_description}</li>"
desc += "</ol>"
return desc

Expand Down Expand Up @@ -221,9 +232,6 @@ class CirkwiTouristicContentParser(CirkwiParser):
m2m_fields = {
"type1": "categories/categorie/*",
}
non_fields = {
'attachments': "informations/information[@langue='<LANG>']/medias/images/image/*"
}
field_options = {
"geom": {"required": True},
"name": {"required": True},
Expand Down
78 changes: 71 additions & 7 deletions geotrek/cirkwi/tests/data/circuits.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<circuits version="2">
<listing_ids nb_objects="2" first="0" rows="100">
<id>10925</id>
<id>10926</id>
</listing_ids>
<circuit date_creation="1295825772" date_modification="1295828456" id_circuit="10925"
id_utilisateur="1">
<informations>
Expand Down Expand Up @@ -60,6 +64,58 @@
</medias>
</information>
</informations>
<locomotions>
<locomotion type="Marche" id_locomotion="2" difficulte="5" duree="7200"/>
</locomotions>
<infos_parcours>
<info_parcours numero="1" id_info_parcours="2784327" date_modification="0">
<categories>
<categorie nom="Autres" id_categorie="6"/>
</categories>
<informations>
<information langue="fr">
<titre>Étape 1</titre>
<description>
Au départ du terminal des car-ferrys.
</description>
<medias/>
</information>
</informations>
<adresse>
<code_insee>62193</code_insee>
<position>
<lat>50.9647654</lat>
<lng>1.8614236</lng>
</position>
<altitude>5.54</altitude>
</adresse>
</info_parcours>
<info_parcours numero="2" id_info_parcours="2784328" date_modification="0">
<categories>
<categorie nom="Autres" id_categorie="6"/>
</categories>
<informations>
<information langue="fr">
<titre>Étape 2</titre>
<description>
Virer à droite, direction la plage-corniche de la Côte d'Opale.
</description>
<medias/>
</information>
</informations>
<adresse>
<code_insee>62193</code_insee>
<position>
<lat>50.9588189</lat>
<lng>1.8521179</lng>
</position>
<altitude>4.37</altitude>
</adresse>
</info_parcours>
</infos_parcours>
<fichier_trace
url="https://demo-admin.geotrek.fr/static/boucle-du-pic-des-trois-seigneurs.gpx"
info_parcours="false" />
<sens_circuit id="1" label="aller_simple">
<adresse>
<num>74</num>
Expand All @@ -83,13 +139,6 @@
<ddr id_ddr="45" />
<ddr id_ddr="53" />
</ddrs>
<locomotions>
<locomotion type="voiture" id_locomotion="2" difficulte="1" duree="45" jours="0" />
<locomotion type="vtt" id_locomotion="3" difficulte="3" duree="129" />
</locomotions>
<fichier_trace
url="https://demo-admin.geotrek.fr/static/boucle-du-pic-des-trois-seigneurs.gpx"
info_parcours="false" />
<infos_parcours>
<info_parcours numero="1" date_modification="1365413342" id_info_parcours="357">
<categories>
Expand Down Expand Up @@ -201,4 +250,19 @@
<diffusion cirkwi="1" mobile="1" reseau="1" />
</sens_circuit>
</circuit>
<circuit date_creation="1295825772" date_modification="1295828456" id_circuit="10926"
id_utilisateur="1">
<informations>
<information langue="fr">
<titre>Le patrimoine de Plancoët à vélo</titre>
<description>Laissez-vous guider par ce chemin</description>
</information>
</informations>
<locomotions>
<locomotion type="Vélo" id_locomotion="3" difficulte="5" duree="0"/>
</locomotions>
<fichier_trace
url="https://demo-admin.geotrek.fr/static/boucle-du-pic-des-trois-seigneurs.gpx"
info_parcours="false" />
</circuit>
</circuits>
Loading

0 comments on commit 2431963

Please sign in to comment.