* adds workflow testing for geometries on new creation of intervention and compensation
*
This commit is contained in:
2021-11-12 14:54:33 +01:00
parent 6c35fc59af
commit 92cfb95789
4 changed files with 101 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ from intervention.models import LegalData, ResponsibilityData, Intervention
from konova.management.commands.setup_data import GROUPS_DATA
from konova.models import Geometry
from konova.settings import DEFAULT_GROUP
from konova.utils.generators import generate_random_string
from user.models import UserActionLogEntry, UserAction
@@ -79,6 +80,15 @@ class BaseTestCase(TestCase):
)
cls.groups = Group.objects.all()
@staticmethod
def create_dummy_string(prefix: str = ""):
""" Create
Returns:
"""
return f"{prefix}{generate_random_string(3, True)}"
@classmethod
def create_dummy_intervention(cls):
""" Creates an intervention which can be used for tests
@@ -213,7 +223,10 @@ class BaseTestCase(TestCase):
Returns:
"""
return MultiPolygon(Polygon.from_bbox([-4.526367, 18.354526, -1.801758, 20.591652]))
polygon = Polygon.from_bbox((7.157593, 49.882247, 7.816772, 50.266521))
polygon.srid = 4326
polygon = polygon.transform(3857, clone=True)
return MultiPolygon(polygon, srid=3857) # 3857 is the default srid used for MultiPolygonField in the form
@classmethod
def fill_out_intervention(cls, intervention: Intervention) -> Intervention:
@@ -258,6 +271,27 @@ class BaseTestCase(TestCase):
compensation.geometry.save()
return compensation
def assert_equal_geometries(self, geom1: MultiPolygon, geom2: MultiPolygon):
""" Assert for geometries to be equal
Transforms the geometries to matching srids before checking
Args:
geom1 (MultiPolygon): A geometry
geom2 (MultiPolygon): A geometry
Returns:
"""
if geom1.srid != geom2.srid:
# Due to prior possible transformation of any of these geometries, we need to make sure there exists a
# transformation from one coordinate system into the other, which is valid
geom1_t = geom1.transform(geom2.srid, clone=True)
geom2_t = geom2.transform(geom1.srid, clone=True)
self.assertTrue(geom1_t.equals(geom2) or geom2_t.equals(geom1))
else:
self.assertTrue(geom1.equals(geom2))
class BaseViewTestCase(BaseTestCase):
""" Wraps basic test functionality, reusable for every specialized ViewTestCase