Commit 13fa98dc authored by Tomáš Peterka's avatar Tomáš Peterka

[erp5_hal_json_style] Add test for failing dialog with HTTP400 and field errors

parent b3dc32f5
...@@ -50,7 +50,7 @@ def simulate(script_id, params_string, code_string): ...@@ -50,7 +50,7 @@ def simulate(script_id, params_string, code_string):
def createIndexedDocument(): def createIndexedDocument():
def decorator(func): def decorator(func):
def wrapped(self, *args, **kwargs): def wrapped(self, *args, **kwargs):
self._makeDocument() kwargs.update(document=self._makeDocument())
self.portal.portal_caches.clearAllCache() self.portal.portal_caches.clearAllCache()
self.tic() self.tic()
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
...@@ -1062,7 +1062,7 @@ class TestERP5Document_getHateoas_mode_worklist(ERP5HALJSONStyleSkinsMixin): ...@@ -1062,7 +1062,7 @@ class TestERP5Document_getHateoas_mode_worklist(ERP5HALJSONStyleSkinsMixin):
'return "application/hal+json"') 'return "application/hal+json"')
@createIndexedDocument() @createIndexedDocument()
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoasWorklist_default_view(self): def test_getHateoasWorklist_default_view(self, document):
# self._makeDocument() # self._makeDocument()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas( result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
...@@ -1203,3 +1203,36 @@ return msg" ...@@ -1203,3 +1203,36 @@ return msg"
) )
result_dict = json.loads(result) result_dict = json.loads(result)
self.assertEqual(result_dict['title'], 'Foo_zhongwen') self.assertEqual(result_dict['title'], 'Foo_zhongwen')
class TestERP5Action_getHateoas(ERP5HALJSONStyleSkinsMixin):
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
@createIndexedDocument()
def test_getHateoasDialog_dialog_failure(self, document):
"""Test an dialog on Foo object with empty required for a failure.
Expected behaviour is response Http 400 with field errors.
"""
fake_request = do_fake_request("POST")
# user form fields (no need to set meta-fields because we pass them directly to script)
fake_request.set('field_your_workflow_action', 'custom_dialog_required_action')
fake_request.set('field_your_comment', 'My comment')
fake_request.set('field_your_custom_workflow_variable', '') # empty required field!
# call the standard dialog submit script
response = document.Base_callDialogMethod(
REQUEST=fake_request,
dialog_method='Foo_doNothing', # 'Workflow_statusModify' would lead us to different code path,
dialog_id='Foo_viewCustomWorkflowRequiredActionDialog',
)
response = json.loads(response)
self.assertEqual(fake_request.RESPONSE.status, 400)
self.assertIn('your_custom_workflow_variable', response, "Invalid field '{}' must be in the response {!s}".format(
'your_custom_workflow_variable', response))
self.assertIn('error_text', response['your_custom_workflow_variable'], "Invalid field must contain error message")
self.assertGreater(len(response['your_custom_workflow_variable']['error_text']), 0, "Error message must not be empty")
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment