workflow_test: mock date globally for skip time action (#88412)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2024-03-26 15:17:21 +01:00
parent cc62ff430c
commit 27a0a87bf8
4 changed files with 11 additions and 11 deletions

1
debian/control vendored
View File

@ -23,6 +23,7 @@ Depends: graphviz,
python3-django-ratelimit,
python3-dnspython,
python3-emoji,
python3-freezegun,
python3-hobo,
python3-lasso,
python3-lxml,

View File

@ -205,6 +205,7 @@ setup(
'phonenumbers',
'emoji',
'psutil',
'freezegun',
],
package_dir={'wcs': 'wcs'},
packages=find_packages(),

View File

@ -458,7 +458,6 @@ def test_workflow_tests_automatic_jump_condition(pub):
assert str(excinfo.value) == 'Form should be in status "Frog status" but is in status "Bear status".'
@pytest.mark.freeze_time('2024-02-19 12:00')
def test_workflow_tests_automatic_jump_timeout(pub):
user = pub.user_class(name='test user')
user.store()

View File

@ -17,6 +17,8 @@
import datetime
import uuid
import freezegun
from django.utils.timezone import localtime
from quixote import get_publisher, get_session
from wcs import wf
@ -90,9 +92,13 @@ class WorkflowTests(XmlStorableObject):
# mark formdata as running workflow tests
formdata.workflow_test = True
formdata.frozen_receipt_time = formdata.receipt_time
self.reset_formdata_test_attributes(formdata)
with freezegun.freeze_time(formdata.receipt_time) as frozen_datetime:
formdata.frozen_datetime = frozen_datetime
self._run(formdata)
def _run(self, formdata):
formdata.perform_workflow()
for action in self.actions:
status = formdata.get_status()
@ -542,15 +548,8 @@ class SkipTime(WorkflowTestAction):
if previous_trace:
self.seconds = (trace.timestamp - previous_trace.timestamp).total_seconds()
def rewind(self, formdata):
def rewind_time(timestamp):
return timestamp - datetime.timedelta(seconds=self.seconds)
formdata.receipt_time = rewind_time(formdata.receipt_time)
formdata.evolution[-1].time = rewind_time(formdata.evolution[-1].time)
def perform(self, formdata):
self.rewind(formdata)
formdata.frozen_datetime.tick(self.seconds)
jump_actions = []
status = formdata.get_status()
@ -560,7 +559,7 @@ class SkipTime(WorkflowTestAction):
delay = wf.jump.get_min_jumps_delay(jump_actions)
if formdata.last_update_time > formdata.frozen_receipt_time - datetime.timedelta(seconds=delay):
if formdata.last_update_time > localtime() - datetime.timedelta(seconds=delay):
return
for jump_action in jump_actions: