add the assertWorkflowErrors
some of the action pages use workflow, but the check is using assertFormErrors, which is unreasonable, assertFormErrors only checks one step, not all Change-Id: I764be4a243fb9c4790c195610514663d71e18373
This commit is contained in:
parent
82ec5135d6
commit
6216715e7d
|
@ -665,7 +665,7 @@ class NetworkTests(test.BaseAdminViewTests):
|
||||||
url = reverse('horizon:admin:networks:create')
|
url = reverse('horizon:admin:networks:create')
|
||||||
res = self.client.post(url, form_data)
|
res = self.client.post(url, form_data)
|
||||||
|
|
||||||
self.assertFormErrors(res, 1)
|
self.assertWorkflowErrors(res, 1)
|
||||||
self.assertContains(res, "1 through 4094")
|
self.assertContains(res, "1 through 4094")
|
||||||
|
|
||||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||||
|
@ -698,7 +698,7 @@ class NetworkTests(test.BaseAdminViewTests):
|
||||||
url = reverse('horizon:admin:networks:create')
|
url = reverse('horizon:admin:networks:create')
|
||||||
res = self.client.post(url, form_data)
|
res = self.client.post(url, form_data)
|
||||||
|
|
||||||
self.assertFormErrors(res, 1)
|
self.assertWorkflowErrors(res, 1)
|
||||||
self.assertContains(res, "1 through %s" % ((2 ** 32) - 1))
|
self.assertContains(res, "1 through %s" % ((2 ** 32) - 1))
|
||||||
|
|
||||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||||
|
@ -734,7 +734,7 @@ class NetworkTests(test.BaseAdminViewTests):
|
||||||
url = reverse('horizon:admin:networks:create')
|
url = reverse('horizon:admin:networks:create')
|
||||||
res = self.client.post(url, form_data)
|
res = self.client.post(url, form_data)
|
||||||
|
|
||||||
self.assertFormErrors(res, 1)
|
self.assertWorkflowErrors(res, 1)
|
||||||
self.assertContains(res, "10 through 20")
|
self.assertContains(res, "10 through 20")
|
||||||
|
|
||||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||||
|
|
|
@ -336,7 +336,7 @@ class NetworkSubnetTests(test.TestCase):
|
||||||
res = self.client.post(url, form_data)
|
res = self.client.post(url, form_data)
|
||||||
|
|
||||||
expected_msg = 'Network Address and IP version are inconsistent.'
|
expected_msg = 'Network Address and IP version are inconsistent.'
|
||||||
self.assertFormErrors(res, 1, expected_msg)
|
self.assertWorkflowErrors(res, 1, expected_msg)
|
||||||
self.assertTemplateUsed(res, views.WorkflowView.template_name)
|
self.assertTemplateUsed(res, views.WorkflowView.template_name)
|
||||||
|
|
||||||
self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
|
self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
|
||||||
|
|
|
@ -400,6 +400,34 @@ class TestCase(horizon_helpers.TestCase):
|
||||||
0, len(errors),
|
0, len(errors),
|
||||||
"Unexpected errors were found on the workflow: %s" % errors)
|
"Unexpected errors were found on the workflow: %s" % errors)
|
||||||
|
|
||||||
|
def assertWorkflowErrors(self, response, count=0, message=None,
|
||||||
|
context_name="workflow"):
|
||||||
|
"""Check for workflow errors.
|
||||||
|
|
||||||
|
Asserts that the response does contain a workflow in its
|
||||||
|
context, and that workflow has errors, if count were given,
|
||||||
|
it must match the exact numbers of errors
|
||||||
|
"""
|
||||||
|
context = getattr(response, "context", {})
|
||||||
|
self.assertIn(context_name, context,
|
||||||
|
msg="The response did not contain a workflow.")
|
||||||
|
errors = {}
|
||||||
|
for step in response.context[context_name].steps:
|
||||||
|
errors.update(step.action._errors)
|
||||||
|
if count:
|
||||||
|
self.assertEqual(
|
||||||
|
count, len(errors),
|
||||||
|
"%d errors were found on the workflow, %d expected" %
|
||||||
|
(len(errors), count))
|
||||||
|
if message and message not in six.text_type(errors):
|
||||||
|
self.fail("Expected message not found, instead found: %s"
|
||||||
|
% ["%s: %s" % (key, [e for e in field_errors]) for
|
||||||
|
(key, field_errors) in errors.items()])
|
||||||
|
else:
|
||||||
|
self.assertGreater(
|
||||||
|
len(errors), 0,
|
||||||
|
"No errors were found on the workflow")
|
||||||
|
|
||||||
|
|
||||||
class BaseAdminViewTests(TestCase):
|
class BaseAdminViewTests(TestCase):
|
||||||
"""Sets an active user with the "admin" role.
|
"""Sets an active user with the "admin" role.
|
||||||
|
|
Loading…
Reference in New Issue