* adds workflow tests for compensation checking and recording
* improves related code
This commit is contained in:
2021-11-11 13:13:05 +01:00
parent 796990ffbc
commit ffadfa2f47
6 changed files with 238 additions and 32 deletions

View File

@@ -235,16 +235,7 @@ class CheckModalForm(BaseModalForm):
"""
with transaction.atomic():
user_action = UserActionLogEntry.objects.create(
user=self.user,
action=UserAction.CHECKED
)
# Replace old checked
if self.instance.checked:
self.instance.checked.delete()
self.instance.checked = user_action
self.instance.log.add(user_action)
self.instance.save()
self.instance.toggle_checked(self.user)
# Send message to the SSO server
messenger = Messenger(

View File

@@ -19,7 +19,6 @@ from intervention.utils.quality import InterventionQualityChecker
from konova.models import BaseObject, Geometry, UuidModel, BaseResource, AbstractDocument, \
generate_document_file_upload_path, RecordableObject, CheckableObject, ShareableObject
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT
from konova.utils import generators
from user.models import UserActionLogEntry
@@ -285,6 +284,45 @@ class Intervention(BaseObject, ShareableObject, RecordableObject, CheckableObjec
)
return revoc_docs, regular_docs
def toggle_recorded(self, user: User):
""" Toggle the recorded state
For interventions the recorded action needs to be added to their compensation objects as well
Args:
user (User): The performing user
Returns:
"""
log_entry = super().toggle_recorded(user)
# Add this action to the linked compensation logs as well
comps = self.compensations.all()
for comp in comps:
comp.log.add(log_entry)
def toggle_checked(self, user: User) -> UserActionLogEntry:
""" Toggle the checked state
For interventions the checked action needs to be added to their compensation objects as well
Args:
user (User): The performing user
Returns:
"""
log_entry = super().toggle_checked(user)
# Leave if the log_entry is None (means "unchecked")
if log_entry is None:
return
# Add this action to the linked compensation logs as well
comps = self.compensations.all()
for comp in comps:
comp.log.add(log_entry)
class InterventionDocument(AbstractDocument):
"""

View File

@@ -29,16 +29,6 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase):
# Give the user shared access to the dummy intervention
cls.intervention.users.add(cls.superuser)
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 test_new(self):
"""
Checks a 'normal' case of creating a new intervention.