Skip to content

Commit

Permalink
Add label on Trekking parser api v2
Browse files Browse the repository at this point in the history
  • Loading branch information
LePetitTim committed Aug 3, 2022
1 parent c068603 commit 6661937
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
7 changes: 5 additions & 2 deletions geotrek/trekking/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ class GeotrekTrekParser(GeotrekParser):
"themes": "/api/v2/theme/",
"practice": "/api/v2/trek_practice/",
"accessibilities": "/api/v2/trek_accessibility/",
"networks": "/api/v2/trek_network/"
"networks": "/api/v2/trek_network/",
'labels': '/api/v2/label/'
}
categories_keys_api_v2 = {
'difficulty': 'label',
'route': 'route',
'themes': 'label',
'practice': 'name',
'accessibilities': 'name',
'networks': 'label'
'networks': 'label',
'labels': 'name'
}
natural_keys = {
'difficulty': 'difficulty',
Expand All @@ -97,6 +99,7 @@ class GeotrekTrekParser(GeotrekParser):
'practice': 'name',
'accessibilities': 'name',
'networks': 'network',
'labels': 'name'
}

def next_row(self):
Expand Down
58 changes: 58 additions & 0 deletions geotrek/trekking/tests/data/geotrek_parser_v2/trek_label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"count": 3,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"advice": {
"fr": "<p>La divagation des chiens est autoris&eacute;e sur le sentier.</p>\r\n<p><img src=\"http://www.mercantour-parcnational.fr/sites/mercantour.eu/files/styles/slide_750x500/public/22259_pnm-800px.jpg?itok=S1nrGDX_\" alt=\"Chient sur le territoire\" width=\"750\" height=\"500\" /></p>",
"en": "The national park is an unrestricted natural area but subjected to regulations which must be known by all visitors.",
"es": "El parque nacional es un área natural sin restricciones pero sometido a regulaciones que deben ser conocidas por todos los visitantes.",
"it": "Il Parco Nazionale è un territorio naturale, aperto a tutti, ma soggetto ad un regolamento che è utile conoscere per preparare il vostro soggiorno."
},
"filter": true,
"name": {
"fr": "Chien autorisé",
"en": "Is in the midst of the park",
"es": "En coeur de parc",
"it": "Nel cuore del parco"
},
"pictogram": "https://demo-admin.geotrek.fr/media/upload/dog.png"
},
{
"id": 2,
"advice": {
"fr": "Le Parc national est un territoire naturel, ouvert à tous, mais soumis à une réglementation qu’il est utile de connaître pour préparer son séjour",
"en": null,
"es": null,
"it": null
},
"filter": true,
"name": {
"fr": "En coeur de parc",
"en": null,
"es": null,
"it": null
},
"pictogram": null
},
{
"id": 3,
"advice": {
"fr": "Cette randonnée se déroule sur un territoire où les patous sont présents.",
"en": null,
"es": null,
"it": null
},
"filter": true,
"name": {
"fr": "Information Patou",
"en": null,
"es": null,
"it": null
},
"pictogram": null
}
]
}
5 changes: 4 additions & 1 deletion geotrek/trekking/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class TestGeotrekTrekParser(GeotrekTrekParser):
'accessibilities': {'create': True},
'networks': {'create': True},
'geom': {'required': True},
'labels': {'create': True},
}


Expand Down Expand Up @@ -175,7 +176,7 @@ def setUpTestData(cls):
def test_create(self, mocked_head, mocked_get):
self.mock_time = 0
self.mock_json_order = ['trek_difficulty.json', 'trek_route.json', 'trek_theme.json', 'trek_practice.json',
'trek_accessibility.json', 'trek_network.json', 'trek.json', 'trek_children.json']
'trek_accessibility.json', 'trek_network.json', 'trek_label.json', 'trek.json', 'trek_children.json', ]

def mocked_json():
filename = os.path.join(os.path.dirname(__file__), 'data', 'geotrek_parser_v2',
Expand All @@ -199,6 +200,8 @@ def mocked_json():
self.assertAlmostEqual(trek.geom[0][0], 569946.9850365581, places=5)
self.assertAlmostEqual(trek.geom[0][1], 6190964.893167565, places=5)
self.assertEqual(trek.children.first().name, "Foo")
self.assertEqual(trek.labels.count(), 3)
self.assertEqual(trek.labels.first().name, "Chien autorisé")


@skipIf(settings.TREKKING_TOPOLOGY_ENABLED, 'Test without dynamic segmentation only')
Expand Down

0 comments on commit 6661937

Please sign in to comment.