# Deadline form logic
* adds logic to NewDeadlineModalForm to invalidate 'other' deadline types without comment (as explanation for 'other')
This commit is contained in:
parent
0a3b91e69a
commit
13da5dbc32
@ -21,7 +21,7 @@ from compensation.utils.quality import CompensationQualityChecker
|
|||||||
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
|
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
|
||||||
GeoReferencedMixin, DeadlineType, ResubmitableObjectMixin
|
GeoReferencedMixin, DeadlineType, ResubmitableObjectMixin
|
||||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
|
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
|
||||||
DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
|
DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, DEADLINE_ADDED, \
|
||||||
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class AbstractCompensation(BaseObject,
|
|||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
self.deadlines.add(deadline)
|
self.deadlines.add(deadline)
|
||||||
self.mark_as_edited(user, edit_comment=ADDED_DEADLINE)
|
self.mark_as_edited(user, edit_comment=DEADLINE_ADDED)
|
||||||
return deadline
|
return deadline
|
||||||
|
|
||||||
def remove_deadline(self, form):
|
def remove_deadline(self, form):
|
||||||
|
7
konova/tests/unit/__init__.py
Normal file
7
konova/tests/unit/__init__.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 29.08.23
|
||||||
|
|
||||||
|
"""
|
118
konova/tests/unit/test_deadline.py
Normal file
118
konova/tests/unit/test_deadline.py
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||||
|
Created on: 29.08.23
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.test import RequestFactory
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from compensation.forms.modals.deadline import NewDeadlineModalForm, EditDeadlineModalForm
|
||||||
|
from konova.models import DeadlineType
|
||||||
|
from konova.tests.test_views import BaseTestCase
|
||||||
|
from konova.utils.generators import generate_random_string
|
||||||
|
from konova.utils.message_templates import DEADLINE_ADDED, DEADLINE_EDITED
|
||||||
|
from user.models import UserAction
|
||||||
|
|
||||||
|
|
||||||
|
class NewDeadlineModalFormTestCase(BaseTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
self.request = RequestFactory().request()
|
||||||
|
self.request.user = self.superuser
|
||||||
|
self.today = now().date()
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
form = NewDeadlineModalForm(request=self.request, instance=self.compensation)
|
||||||
|
self.assertEqual(form.form_title, str(_("New deadline")))
|
||||||
|
self.assertEqual(form.form_caption, str(_("Insert data for the new deadline")))
|
||||||
|
self.assertEqual(form.user, self.superuser)
|
||||||
|
self.assertEqual(form.request, self.request)
|
||||||
|
|
||||||
|
def test_is_valid(self):
|
||||||
|
data = {
|
||||||
|
"type": DeadlineType.MAINTAIN,
|
||||||
|
"date": self.today,
|
||||||
|
"comment": "",
|
||||||
|
}
|
||||||
|
form = NewDeadlineModalForm(
|
||||||
|
data,
|
||||||
|
request=self.request,
|
||||||
|
instance=self.compensation
|
||||||
|
)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
data["type"] = DeadlineType.OTHER
|
||||||
|
form = NewDeadlineModalForm(
|
||||||
|
data,
|
||||||
|
request=self.request,
|
||||||
|
instance=self.compensation
|
||||||
|
)
|
||||||
|
self.assertFalse(form.is_valid(), msg=form.errors)
|
||||||
|
self.assertTrue(form.has_error("comment"))
|
||||||
|
_error = form.errors["comment"]
|
||||||
|
self.assertEqual(len(_error), 1)
|
||||||
|
self.assertEqual(_error[0], str(_("Please explain this 'other' type of deadline.")))
|
||||||
|
|
||||||
|
data["comment"] = "Test"
|
||||||
|
data["type"] = DeadlineType.OTHER
|
||||||
|
form = NewDeadlineModalForm(
|
||||||
|
data,
|
||||||
|
request=self.request,
|
||||||
|
instance=self.compensation
|
||||||
|
)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_save(self):
|
||||||
|
data = {
|
||||||
|
"type": DeadlineType.MAINTAIN,
|
||||||
|
"date": self.today,
|
||||||
|
"comment": generate_random_string(length=20, use_letters_lc=True),
|
||||||
|
}
|
||||||
|
form = NewDeadlineModalForm(
|
||||||
|
data,
|
||||||
|
request=self.request,
|
||||||
|
instance=self.compensation
|
||||||
|
)
|
||||||
|
self.assertTrue(form.is_valid(), msg=form.errors)
|
||||||
|
deadline = form.save()
|
||||||
|
self.assertEqual(deadline.type, data["type"])
|
||||||
|
self.assertEqual(deadline.date, data["date"])
|
||||||
|
self.assertEqual(deadline.comment, data["comment"])
|
||||||
|
self.assertIn(deadline, self.compensation.deadlines.all())
|
||||||
|
|
||||||
|
last_log = self.compensation.log.first()
|
||||||
|
self.assertEqual(last_log.user, self.superuser)
|
||||||
|
self.assertEqual(last_log.action, UserAction.EDITED)
|
||||||
|
self.assertEqual(last_log.comment, DEADLINE_ADDED)
|
||||||
|
|
||||||
|
|
||||||
|
class EditDeadlineModalFormTestCase(NewDeadlineModalFormTestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
def test_save(self):
|
||||||
|
data = {
|
||||||
|
"type": DeadlineType.MAINTAIN,
|
||||||
|
"date": self.today,
|
||||||
|
"comment": generate_random_string(length=20, use_letters_lc=True),
|
||||||
|
}
|
||||||
|
form = EditDeadlineModalForm(
|
||||||
|
data,
|
||||||
|
request=self.request,
|
||||||
|
instance=self.compensation,
|
||||||
|
deadline=self.finished_deadline,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(form.is_valid(), msg=form.errors)
|
||||||
|
deadline = form.save()
|
||||||
|
self.assertEqual(deadline.type, data["type"])
|
||||||
|
self.assertEqual(deadline.date, data["date"])
|
||||||
|
self.assertEqual(deadline.comment, data["comment"])
|
||||||
|
|
||||||
|
last_log = self.compensation.log.first()
|
||||||
|
self.assertEqual(last_log.action, UserAction.EDITED)
|
||||||
|
self.assertEqual(last_log.user, self.superuser)
|
||||||
|
self.assertEqual(last_log.comment, DEADLINE_EDITED)
|
@ -79,7 +79,6 @@ DOCUMENT_EDITED = _("Document edited")
|
|||||||
|
|
||||||
# Edited
|
# Edited
|
||||||
EDITED_GENERAL_DATA = _("Edited general data")
|
EDITED_GENERAL_DATA = _("Edited general data")
|
||||||
ADDED_DEADLINE = _("Added deadline")
|
|
||||||
|
|
||||||
# Geometry
|
# Geometry
|
||||||
GEOMETRY_CONFLICT_WITH_TEMPLATE = _("Geometry conflict detected with {}")
|
GEOMETRY_CONFLICT_WITH_TEMPLATE = _("Geometry conflict detected with {}")
|
||||||
|
Loading…
Reference in New Issue
Block a user