* adds workflow tests for checkability and recordability for interventions
* fixes/improves code snippets detected by testing
This commit is contained in:
2021-11-11 10:37:22 +01:00
parent 34fd78be5e
commit 796990ffbc
7 changed files with 205 additions and 34 deletions

View File

@@ -5,13 +5,15 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 26.10.21
"""
from abc import abstractmethod
import datetime
from django.contrib.auth.models import User, Group
from django.contrib.gis.geos import MultiPolygon, Polygon
from django.core.exceptions import ObjectDoesNotExist
from django.test import TestCase, Client
from django.urls import reverse
from codelist.models import KonovaCode
from compensation.models import Compensation, CompensationState, CompensationAction, EcoAccount
from intervention.models import LegalData, ResponsibilityData, Intervention
from konova.management.commands.setup_data import GROUPS_DATA
@@ -32,17 +34,22 @@ class BaseTestCase(TestCase):
eco_account = None
comp_state = None
comp_action = None
codes = None
superuser_pw = "root"
user_pw = "root"
class Meta:
abstract = True
@classmethod
def setUpTestData(cls):
cls.create_users()
cls.create_groups()
cls.create_dummy_intervention()
cls.create_dummy_compensation()
cls.create_dummy_eco_account()
cls.intervention = cls.create_dummy_intervention()
cls.compensation = cls.create_dummy_compensation()
cls.eco_account = cls.create_dummy_eco_account()
cls.codes = cls.create_dummy_codes()
@classmethod
def create_users(cls):
@@ -69,9 +76,6 @@ class BaseTestCase(TestCase):
)
cls.groups = Group.objects.all()
class Meta:
abstract = True
@classmethod
def create_dummy_intervention(cls):
""" Creates an intervention which can be used for tests
@@ -91,7 +95,7 @@ class BaseTestCase(TestCase):
responsibility_data = ResponsibilityData.objects.create()
geometry = Geometry.objects.create()
# Finally create main object, holding the other objects
cls.intervention = Intervention.objects.create(
intervention = Intervention.objects.create(
identifier="TEST",
title="Test_title",
responsible=responsibility_data,
@@ -100,8 +104,8 @@ class BaseTestCase(TestCase):
geometry=geometry,
comment="Test",
)
cls.intervention.generate_access_token(make_unique=True)
return cls.intervention
intervention.generate_access_token(make_unique=True)
return intervention
@classmethod
def create_dummy_compensation(cls):
@@ -111,7 +115,7 @@ class BaseTestCase(TestCase):
"""
if cls.intervention is None:
cls.create_dummy_intervention()
cls.intervention = cls.create_dummy_intervention()
# Create dummy data
# Create log entry
action = UserActionLogEntry.objects.create(
@@ -120,7 +124,7 @@ class BaseTestCase(TestCase):
)
geometry = Geometry.objects.create()
# Finally create main object, holding the other objects
cls.compensation = Compensation.objects.create(
compensation = Compensation.objects.create(
identifier="TEST",
title="Test_title",
intervention=cls.intervention,
@@ -128,8 +132,7 @@ class BaseTestCase(TestCase):
geometry=geometry,
comment="Test",
)
cls.intervention.generate_access_token(make_unique=True)
return cls.compensation
return compensation
@classmethod
def create_dummy_eco_account(cls):
@@ -149,7 +152,7 @@ class BaseTestCase(TestCase):
lega_data = LegalData.objects.create()
responsible_data = ResponsibilityData.objects.create()
# Finally create main object, holding the other objects
cls.eco_account = EcoAccount.objects.create(
eco_account = EcoAccount.objects.create(
identifier="TEST",
title="Test_title",
legal=lega_data,
@@ -158,7 +161,7 @@ class BaseTestCase(TestCase):
geometry=geometry,
comment="Test",
)
return cls.eco_account
return eco_account
@classmethod
def create_dummy_states(cls):
@@ -185,6 +188,47 @@ class BaseTestCase(TestCase):
)
return cls.comp_action
@classmethod
def create_dummy_codes(cls):
""" Creates some dummy KonovaCodes which can be used for testing
Returns:
"""
codes = KonovaCode.objects.bulk_create([
KonovaCode(id=1, is_selectable=True, long_name="Test1"),
KonovaCode(id=2, is_selectable=True, long_name="Test2"),
KonovaCode(id=3, is_selectable=True, long_name="Test3"),
KonovaCode(id=4, is_selectable=True, long_name="Test4"),
])
return codes
@staticmethod
def fill_out_intervention(intervention: Intervention) -> Intervention:
""" Adds all required (dummy) data to an intervention
Args:
intervention (Intervention): The intervention which shall be filled out
Returns:
intervention (Intervention): The modified intervention
"""
intervention.responsible.registration_office = KonovaCode.objects.get(id=1)
intervention.responsible.conservation_office = KonovaCode.objects.get(id=2)
intervention.responsible.registration_file_number = "test"
intervention.responsible.conservation_file_number = "test"
intervention.responsible.handler = "handler"
intervention.responsible.save()
intervention.legal.registration_date = datetime.date.fromisoformat("1970-01-01")
intervention.legal.binding_date = datetime.date.fromisoformat("1970-01-01")
intervention.legal.process_type = KonovaCode.objects.get(id=3)
intervention.legal.save()
intervention.legal.laws.set([KonovaCode.objects.get(id=(4))])
intervention.geometry.geom = MultiPolygon(Polygon.from_bbox([-4.526367, 18.354526, -1.801758, 20.591652]))
intervention.geometry.save()
intervention.save()
return intervention
class BaseViewTestCase(BaseTestCase):
""" Wraps basic test functionality, reusable for every specialized ViewTestCase
@@ -348,6 +392,9 @@ class BaseWorkflowTestCase(BaseTestCase):
client_user = None
client_anon = None
class Meta:
abstract = True
@classmethod
def setUpTestData(cls):
super().setUpTestData()