-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [TEST] Add tests for Annotation Categories in HD Views (refs #4032)
- Loading branch information
Showing
2 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
import json | ||
from django.test import TestCase | ||
from geotrek.common.forms import HDViewPointAnnotationForm | ||
from geotrek.common.tests.factories import HDViewPointFactory | ||
from geotrek.common.tests.factories import AnnotationCategoryFactory, HDViewPointFactory | ||
from geotrek.trekking.tests.factories import TrekFactory | ||
|
||
|
||
class HDViewPointAnnotateFormTest(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.vp = HDViewPointFactory(content_object=TrekFactory()) | ||
cls.annotationcategory = AnnotationCategoryFactory() | ||
|
||
def test_annotation_form(self): | ||
geojson = '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [7903.518111498841, 3618.542606516288]}, "properties": {"name": "Test point", "annotationId": 13, "annotationType": "point"}}]}' | ||
data = { | ||
"annotations": geojson | ||
"annotations": geojson, | ||
"annotations_categories": f'{{"13":"{self.annotationcategory.pk}"}}' | ||
} | ||
form = HDViewPointAnnotationForm(instance=self.vp, data=data) | ||
form.save() | ||
self.assertEqual(self.vp.annotations, json.loads(geojson)) | ||
self.assertEqual(self.vp.annotations_categories, {'13': str(self.annotationcategory.pk)}) | ||
|
||
def test_annotation_empty_values_form(self): | ||
data = { | ||
"annotations": "", | ||
"annotations_categories": "" | ||
} | ||
form = HDViewPointAnnotationForm(instance=self.vp, data=data) | ||
self.assertTrue(form.is_valid()) |