Skip to content

Commit

Permalink
✅ [TEST] Add tests for Annotation Categories in HD Views (refs #4032)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chatewgne committed Jul 31, 2024
1 parent cf980b6 commit 5ccc914
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
84 changes: 81 additions & 3 deletions geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,55 @@ 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
)
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()
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions geotrek/common/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 5ccc914

Please sign in to comment.