workflow_tests: skip wscall action if response type is attachment (#89894)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2024-04-23 11:29:18 +02:00
parent 0fcf440e0a
commit a2a4b1536b
3 changed files with 47 additions and 1 deletions

View File

@ -825,6 +825,49 @@ def test_workflow_tests_run(pub):
assert resp.pyquery('li#test-action').text() == 'Test action: Assert email is sent'
def test_workflow_tests_run_webservice_call(pub):
create_superuser(pub)
workflow = Workflow(name='Workflow One')
new_status = workflow.add_status(name='New status')
wscall = new_status.add_action('webservice_call')
wscall.url = 'http://example.com/json'
workflow.store()
formdef = FormDef()
formdef.name = 'test title'
formdef.workflow_id = workflow.id
formdef.store()
testdef = TestDef.create_from_formdata(formdef, formdef.data_class()())
testdef.store()
response = WebserviceResponse()
response.testdef_id = testdef.id
response.name = 'Fake response'
response.url = 'http://example.com/json'
response.payload = '{}'
response.store()
testdef.workflow_tests.actions = [
workflow_tests.AssertWebserviceCall(webservice_response_uuid=response.uuid, call_count=1),
]
testdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/forms/1/tests/results/run').follow()
assert 'Success!' in resp.text
wscall.response_type = 'attachment'
workflow.store()
resp = app.get('/backoffice/forms/1/tests/results/run').follow()
assert 'Workflow error: Webservice response Fake response was used 0 times' in resp.text
def test_workfow_tests_creation_from_formdata(pub):
create_superuser(pub)

View File

@ -728,6 +728,9 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
return _('Error calling webservice')
def get_workflow_test_action(self, *args, **kwargs):
if self.response_type != 'json':
return None
return self
def _kv_data_export_to_xml(self, xml_item, include_id, attribute):

View File

@ -418,7 +418,7 @@ class AttachmentEvolutionPart(EvolutionPart):
return os.path.join(get_publisher().app_dir, self.filename)
def get_file_pointer(self):
if not self.filename or self.filename.startswith('uuid-'):
if self.filename.startswith('uuid-'):
return None
return open(self.get_file_path(), 'rb') # pylint: disable=consider-using-with