workflow_tests: display more details for some actions (#88754)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2024-03-27 14:29:40 +01:00
parent d0358afa40
commit e540ebdaa2
2 changed files with 51 additions and 17 deletions

View File

@ -379,6 +379,20 @@ def test_workflow_tests_action_assert_email(pub):
resp = app.get('/backoffice/forms/1/tests/%s/workflow/' % testdef.id)
assert escape('Email to "a@entrouvert.com" (+2)') in resp.text
assert_email.addresses = []
assert_email.subject_strings = ['Hello your form has been submitted']
assert_email.parent.store()
resp = app.get('/backoffice/forms/1/tests/%s/workflow/' % testdef.id)
assert escape('Subject must contain "Hello your form has been su(…)"') in resp.text
assert_email.subject_strings = []
assert_email.body_strings = ['Hello your form has been submitted']
assert_email.parent.store()
resp = app.get('/backoffice/forms/1/tests/%s/workflow/' % testdef.id)
assert escape('Body must contain "Hello your form has been su(…)"') in resp.text
def test_workflow_tests_action_assert_sms(pub):
create_superuser(pub)
@ -408,14 +422,14 @@ def test_workflow_tests_action_assert_sms(pub):
resp = resp.click('Edit')
resp.form['phone_numbers$element0'] = '0123456789'
resp.form['body'] = 'Hello'
resp.form['body'] = 'Hello your form has been submitted'
resp = resp.form.submit().follow()
assert 'SMS to 0123456789' in resp.text
assert_sms = TestDef.get(testdef.id).workflow_tests.actions[0]
assert assert_sms.phone_numbers == ['0123456789']
assert assert_sms.body == 'Hello'
assert assert_sms.body == 'Hello your form has been submitted'
assert_sms.phone_numbers = ['0123456789', '0123456781', '0123456782']
assert_sms.parent.store()
@ -423,6 +437,12 @@ def test_workflow_tests_action_assert_sms(pub):
resp = app.get('/backoffice/forms/1/tests/%s/workflow/' % testdef.id)
assert escape('SMS to 0123456789 (+2)') in resp.text
assert_sms.phone_numbers = []
assert_sms.parent.store()
resp = app.get('/backoffice/forms/1/tests/%s/workflow/' % testdef.id)
assert 'Hello your form has been su(…)' in resp.text
def test_workflow_tests_action_assert_anonymise(pub):
create_superuser(pub)
@ -497,10 +517,11 @@ def test_workflow_tests_action_assert_history_message(pub):
assert 'not configured' in resp.text
resp = resp.click('Edit')
resp.form['message'] = 'Hello'
resp.form['message'] = 'Hello your form has been submitted'
resp = resp.form.submit().follow()
assert 'not configured' not in resp.text
assert 'Hello your form has been su(…)' in resp.text
def test_workflow_tests_action_assert_alert(pub):
@ -525,10 +546,11 @@ def test_workflow_tests_action_assert_alert(pub):
assert 'not configured' in resp.text
resp = resp.click('Edit')
resp.form['message'] = 'Hello'
resp.form['message'] = 'Hello your form has been submitted'
resp = resp.form.submit().follow()
assert 'not configured' not in resp.text
assert 'Hello your form has been su(…)' in resp.text
def test_workflow_tests_action_assert_criticality(pub):

View File

@ -20,7 +20,7 @@ import uuid
from quixote import get_publisher, get_session
from wcs import wf
from wcs.qommon import _
from wcs.qommon import _, misc
from wcs.qommon.form import (
EmailWidget,
IntWidget,
@ -456,13 +456,17 @@ class AssertEmail(WorkflowTestAction):
@property
def details_label(self):
if not self.addresses:
return ''
label = ''
label = _('Email to "%s"') % self.addresses[0]
if self.addresses:
label = _('Email to "%s"') % self.addresses[0]
if len(self.addresses) > 1:
label = '%s (+%s)' % (label, len(self.addresses) - 1)
if len(self.addresses) > 1:
label = '%s (+%s)' % (label, len(self.addresses) - 1)
elif self.subject_strings:
label = _('Subject must contain "%s"') % misc.ellipsize(self.subject_strings[0])
elif self.body_strings:
label = _('Body must contain "%s"') % misc.ellipsize(self.body_strings[0])
return label
@ -750,13 +754,15 @@ class AssertSMS(WorkflowTestAction):
@property
def details_label(self):
if not self.phone_numbers:
return ''
label = ''
label = _('SMS to %s') % self.phone_numbers[0]
if self.phone_numbers:
label = _('SMS to %s') % self.phone_numbers[0]
if len(self.phone_numbers) > 1:
label = '%s (+%s)' % (label, len(self.phone_numbers) - 1)
if len(self.phone_numbers) > 1:
label = '%s (+%s)' % (label, len(self.phone_numbers) - 1)
elif self.body:
label = misc.ellipsize(self.body)
return label
@ -840,7 +846,6 @@ class AssertRedirect(WorkflowTestAction):
class AssertHistoryMessage(WorkflowTestAction):
label = _('Assert history message is displayed')
details_label = ''
key = 'assert-history-message'
message = None
@ -849,6 +854,10 @@ class AssertHistoryMessage(WorkflowTestAction):
('message', 'str'),
]
@property
def details_label(self):
return misc.ellipsize(self.message)
def perform(self, formdata):
try:
message = formdata.history_messages.pop(0)
@ -874,7 +883,6 @@ class AssertHistoryMessage(WorkflowTestAction):
class AssertAlert(WorkflowTestAction):
label = _('Assert alert is displayed')
details_label = ''
key = 'assert-alert'
message = None
@ -883,6 +891,10 @@ class AssertAlert(WorkflowTestAction):
('message', 'str'),
]
@property
def details_label(self):
return misc.ellipsize(self.message)
def perform(self, formdata):
messages = formdata.get_workflow_messages()