summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpengyuesheng <pengyuesheng@gohighsec.com>2018-11-14 14:20:36 +0800
committerpengyuesheng <pengyuesheng@gohighsec.com>2018-11-16 09:58:00 +0800
commit6216715e7d0f6924a71013867956b7df49c816d7 (patch)
tree0da189d062a97ab99d16d47180c71f9af1bdfecb
parent82ec5135d611bf355da61fdca2cc6fe8c225f11c (diff)
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
Notes
Notes (review): Code-Review+1: Vishal Manchanda <manchandavishal143@gmail.com> Code-Review+2: Akihiro Motoki <amotoki@gmail.com> Code-Review+2: Radomir Dopieralski <openstack@sheep.art.pl> Workflow+1: Radomir Dopieralski <openstack@sheep.art.pl> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 20 Nov 2018 12:35:54 +0000 Reviewed-on: https://review.openstack.org/617887 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--openstack_dashboard/dashboards/admin/networks/tests.py6
-rw-r--r--openstack_dashboard/dashboards/project/networks/subnets/tests.py2
-rw-r--r--openstack_dashboard/test/helpers.py28
3 files changed, 32 insertions, 4 deletions
diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py
index 1cb64b9..38b616a 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):
665 url = reverse('horizon:admin:networks:create') 665 url = reverse('horizon:admin:networks:create')
666 res = self.client.post(url, form_data) 666 res = self.client.post(url, form_data)
667 667
668 self.assertFormErrors(res, 1) 668 self.assertWorkflowErrors(res, 1)
669 self.assertContains(res, "1 through 4094") 669 self.assertContains(res, "1 through 4094")
670 670
671 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest()) 671 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
@@ -698,7 +698,7 @@ class NetworkTests(test.BaseAdminViewTests):
698 url = reverse('horizon:admin:networks:create') 698 url = reverse('horizon:admin:networks:create')
699 res = self.client.post(url, form_data) 699 res = self.client.post(url, form_data)
700 700
701 self.assertFormErrors(res, 1) 701 self.assertWorkflowErrors(res, 1)
702 self.assertContains(res, "1 through %s" % ((2 ** 32) - 1)) 702 self.assertContains(res, "1 through %s" % ((2 ** 32) - 1))
703 703
704 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest()) 704 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
@@ -734,7 +734,7 @@ class NetworkTests(test.BaseAdminViewTests):
734 url = reverse('horizon:admin:networks:create') 734 url = reverse('horizon:admin:networks:create')
735 res = self.client.post(url, form_data) 735 res = self.client.post(url, form_data)
736 736
737 self.assertFormErrors(res, 1) 737 self.assertWorkflowErrors(res, 1)
738 self.assertContains(res, "10 through 20") 738 self.assertContains(res, "10 through 20")
739 739
740 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest()) 740 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 57f3055..518a324 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):
336 res = self.client.post(url, form_data) 336 res = self.client.post(url, form_data)
337 337
338 expected_msg = 'Network Address and IP version are inconsistent.' 338 expected_msg = 'Network Address and IP version are inconsistent.'
339 self.assertFormErrors(res, 1, expected_msg) 339 self.assertWorkflowErrors(res, 1, expected_msg)
340 self.assertTemplateUsed(res, views.WorkflowView.template_name) 340 self.assertTemplateUsed(res, views.WorkflowView.template_name)
341 341
342 self.mock_network_get.assert_called_once_with(test.IsHttpRequest(), 342 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 d1c7eea..856235a 100644
--- a/openstack_dashboard/test/helpers.py
+++ b/openstack_dashboard/test/helpers.py
@@ -400,6 +400,34 @@ class TestCase(horizon_helpers.TestCase):
400 0, len(errors), 400 0, len(errors),
401 "Unexpected errors were found on the workflow: %s" % errors) 401 "Unexpected errors were found on the workflow: %s" % errors)
402 402
403 def assertWorkflowErrors(self, response, count=0, message=None,
404 context_name="workflow"):
405 """Check for workflow errors.
406
407 Asserts that the response does contain a workflow in its
408 context, and that workflow has errors, if count were given,
409 it must match the exact numbers of errors
410 """
411 context = getattr(response, "context", {})
412 self.assertIn(context_name, context,
413 msg="The response did not contain a workflow.")
414 errors = {}
415 for step in response.context[context_name].steps:
416 errors.update(step.action._errors)
417 if count:
418 self.assertEqual(
419 count, len(errors),
420 "%d errors were found on the workflow, %d expected" %
421 (len(errors), count))
422 if message and message not in six.text_type(errors):
423 self.fail("Expected message not found, instead found: %s"
424 % ["%s: %s" % (key, [e for e in field_errors]) for
425 (key, field_errors) in errors.items()])
426 else:
427 self.assertGreater(
428 len(errors), 0,
429 "No errors were found on the workflow")
430
403 431
404class BaseAdminViewTests(TestCase): 432class BaseAdminViewTests(TestCase):
405 """Sets an active user with the "admin" role. 433 """Sets an active user with the "admin" role.