diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py index 1cb64b9f08..38b616a8ee 100644 --- a/openstack_dashboard/dashboards/admin/networks/tests.py +++ b/openstack_dashboard/dashboards/admin/networks/tests.py @@ -665,7 +665,7 @@ class NetworkTests(test.BaseAdminViewTests): url = reverse('horizon:admin:networks:create') res = self.client.post(url, form_data) - self.assertFormErrors(res, 1) + self.assertWorkflowErrors(res, 1) self.assertContains(res, "1 through 4094") self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest()) @@ -698,7 +698,7 @@ class NetworkTests(test.BaseAdminViewTests): url = reverse('horizon:admin:networks:create') 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.mock_tenant_list.assert_called_once_with(test.IsHttpRequest()) @@ -734,7 +734,7 @@ class NetworkTests(test.BaseAdminViewTests): url = reverse('horizon:admin:networks:create') res = self.client.post(url, form_data) - self.assertFormErrors(res, 1) + self.assertWorkflowErrors(res, 1) self.assertContains(res, "10 through 20") self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest()) diff --git a/openstack_dashboard/dashboards/project/networks/subnets/tests.py b/openstack_dashboard/dashboards/project/networks/subnets/tests.py index 57f3055a1a..518a324007 100644 --- a/openstack_dashboard/dashboards/project/networks/subnets/tests.py +++ b/openstack_dashboard/dashboards/project/networks/subnets/tests.py @@ -336,7 +336,7 @@ class NetworkSubnetTests(test.TestCase): res = self.client.post(url, form_data) 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.mock_network_get.assert_called_once_with(test.IsHttpRequest(), diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py index d1c7eea042..856235aabf 100644 --- a/openstack_dashboard/test/helpers.py +++ b/openstack_dashboard/test/helpers.py @@ -400,6 +400,34 @@ class TestCase(horizon_helpers.TestCase): 0, len(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): """Sets an active user with the "admin" role.