From 5ccc91454f9881813f1c2ba6abbade42bf06f86b Mon Sep 17 00:00:00 2001 From: Chatewgne Date: Wed, 31 Jul 2024 12:41:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20[TEST]=20Add=20tests=20for=20Annota?= =?UTF-8?q?tion=20Categories=20in=20HD=20Views=20(refs=20#4032)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geotrek/api/tests/test_v2.py | 84 ++++++++++++++++++++++++++++-- geotrek/common/tests/test_forms.py | 8 +++ 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/geotrek/api/tests/test_v2.py b/geotrek/api/tests/test_v2.py index 820b6e9ee6..7f2187bd94 100644 --- a/geotrek/api/tests/test_v2.py +++ b/geotrek/api/tests/test_v2.py @@ -482,8 +482,48 @@ def setUpTestData(cls): cls.site2.themes.add(cls.theme3) cls.label_3 = common_factory.LabelFactory() cls.site2.labels.add(cls.label_3) + cls.annotationcategory = common_factory.AnnotationCategoryFactory(label='A category') + annotations = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 259.26707830454814, + 148.1029483470403 + ] + }, + "properties": { + "name": "Point 1", + "annotationId": 1234, + "annotationType": "point", + } + }, + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 540.4490176472651, + 161.10558138022952 + ] + }, + "properties": { + "name": "Point 2", + "annotationId": 2, + "annotationType": "point", + } + } + ] + } + annotations_categories = {'1234': str(cls.annotationcategory.pk)} cls.hdviewpoint_trek = common_factory.HDViewPointFactory( - content_object=cls.treks[0] + content_object=cls.treks[0], + annotations = annotations, + annotations_categories = annotations_categories + ) cls.hdviewpoint_poi = common_factory.HDViewPointFactory( content_object=cls.poi @@ -491,7 +531,6 @@ def setUpTestData(cls): cls.hdviewpoint_site = common_factory.HDViewPointFactory( content_object=cls.site ) - cls.annotationcategory = common_factory.AnnotationCategoryFactory() def check_number_elems_response(self, response, model): json_response = response.json() @@ -2488,7 +2527,46 @@ def test_hdviewpoint_detail_content(self): json_response.get('picture_tiles_url'), f"http://testserver/api/hdviewpoint/drf/hdviewpoints/{self.hdviewpoint_trek.pk}/tiles/%7Bz%7D/%7Bx%7D/%7By%7D.png?source=vips" ) - json.dumps(json_response.get('annotations')) + annotations = json_response.get('annotations') + serialized_annotations = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 259.26707830454814, + 148.1029483470403 + ] + }, + "properties": { + "name": "Point 1", + "annotationId": 1234, + "annotationType": "point", + "category": self.annotationcategory.pk + } + }, + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 540.4490176472651, + 161.10558138022952 + ] + }, + "properties": { + "name": "Point 2", + "annotationId": 2, + "annotationType": "point", + "category": None + } + } + ] + } + self.assertEqual(str(self.annotationcategory), 'A category') + self.assertJSONEqual(json.dumps(serialized_annotations), json.dumps(annotations)) self.assertIsNone(json_response.get('site')) self.assertIsNone(json_response.get('poi')) self.assertEqual(json_response.get('trek').get('uuid'), str(self.treks[0].uuid)) diff --git a/geotrek/common/tests/test_forms.py b/geotrek/common/tests/test_forms.py index eed68fd074..ca1edf343d 100644 --- a/geotrek/common/tests/test_forms.py +++ b/geotrek/common/tests/test_forms.py @@ -18,3 +18,11 @@ def test_annotation_form(self): form = HDViewPointAnnotationForm(instance=self.vp, data=data) form.save() self.assertEqual(self.vp.annotations, json.loads(geojson)) + + def test_annotation_empty_values_form(self): + data = { + "annotations": "", + "annotations_categories": "" + } + form = HDViewPointAnnotationForm(instance=self.vp, data=data) + self.assertTrue(form.is_valid())