#19 Tests
* adds workflow tests for compensation checking and recording * improves related code
This commit is contained in:
@@ -18,6 +18,7 @@ from compensation.models import Compensation, CompensationState, CompensationAct
|
||||
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 user.models import UserActionLogEntry, UserAction
|
||||
|
||||
|
||||
@@ -49,6 +50,8 @@ class BaseTestCase(TestCase):
|
||||
cls.intervention = cls.create_dummy_intervention()
|
||||
cls.compensation = cls.create_dummy_compensation()
|
||||
cls.eco_account = cls.create_dummy_eco_account()
|
||||
cls.create_dummy_states()
|
||||
cls.create_dummy_action()
|
||||
cls.codes = cls.create_dummy_codes()
|
||||
|
||||
@classmethod
|
||||
@@ -204,7 +207,16 @@ class BaseTestCase(TestCase):
|
||||
return codes
|
||||
|
||||
@staticmethod
|
||||
def fill_out_intervention(intervention: Intervention) -> Intervention:
|
||||
def create_dummy_geometry() -> MultiPolygon:
|
||||
""" Creates some geometry
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return MultiPolygon(Polygon.from_bbox([-4.526367, 18.354526, -1.801758, 20.591652]))
|
||||
|
||||
@classmethod
|
||||
def fill_out_intervention(cls, intervention: Intervention) -> Intervention:
|
||||
""" Adds all required (dummy) data to an intervention
|
||||
|
||||
Args:
|
||||
@@ -224,11 +236,28 @@ class BaseTestCase(TestCase):
|
||||
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.geom = cls.create_dummy_geometry()
|
||||
intervention.geometry.save()
|
||||
intervention.save()
|
||||
return intervention
|
||||
|
||||
@classmethod
|
||||
def fill_out_compensation(cls, compensation: Compensation) -> Compensation:
|
||||
""" Adds all required (dummy) data to a compensation
|
||||
|
||||
Args:
|
||||
compensation (Compensation): The compensation which shall be filled out
|
||||
|
||||
Returns:
|
||||
compensation (Compensation): The modified compensation
|
||||
"""
|
||||
compensation.after_states.add(cls.comp_state)
|
||||
compensation.before_states.add(cls.comp_state)
|
||||
compensation.actions.add(cls.comp_action)
|
||||
compensation.geometry.geom = cls.create_dummy_geometry()
|
||||
compensation.geometry.save()
|
||||
return compensation
|
||||
|
||||
|
||||
class BaseViewTestCase(BaseTestCase):
|
||||
""" Wraps basic test functionality, reusable for every specialized ViewTestCase
|
||||
@@ -236,6 +265,9 @@ class BaseViewTestCase(BaseTestCase):
|
||||
"""
|
||||
login_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls) -> None:
|
||||
super().setUpTestData()
|
||||
@@ -404,6 +436,16 @@ class BaseWorkflowTestCase(BaseTestCase):
|
||||
cls.client_user.login(username=cls.superuser.username, password=cls.superuser_pw)
|
||||
cls.client_anon = Client()
|
||||
|
||||
def setUp(self) -> None:
|
||||
""" Setup data before each test run
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# Set the default group as only group for the user
|
||||
default_group = self.groups.get(name=DEFAULT_GROUP)
|
||||
self.superuser.groups.set([default_group])
|
||||
|
||||
def assert_object_is_deleted(self, obj):
|
||||
""" Provides a quick check whether an object has been removed from the database or not
|
||||
|
||||
|
||||
Reference in New Issue
Block a user