Browse Source

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
pengyuesheng 5 months ago
parent
commit
6216715e7d

+ 3
- 3
openstack_dashboard/dashboards/admin/networks/tests.py View File

@@ -665,7 +665,7 @@ class NetworkTests(test.BaseAdminViewTests):
665 665
         url = reverse('horizon:admin:networks:create')
666 666
         res = self.client.post(url, form_data)
667 667
 
668
-        self.assertFormErrors(res, 1)
668
+        self.assertWorkflowErrors(res, 1)
669 669
         self.assertContains(res, "1 through 4094")
670 670
 
671 671
         self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
@@ -698,7 +698,7 @@ class NetworkTests(test.BaseAdminViewTests):
698 698
         url = reverse('horizon:admin:networks:create')
699 699
         res = self.client.post(url, form_data)
700 700
 
701
-        self.assertFormErrors(res, 1)
701
+        self.assertWorkflowErrors(res, 1)
702 702
         self.assertContains(res, "1 through %s" % ((2 ** 32) - 1))
703 703
 
704 704
         self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
@@ -734,7 +734,7 @@ class NetworkTests(test.BaseAdminViewTests):
734 734
         url = reverse('horizon:admin:networks:create')
735 735
         res = self.client.post(url, form_data)
736 736
 
737
-        self.assertFormErrors(res, 1)
737
+        self.assertWorkflowErrors(res, 1)
738 738
         self.assertContains(res, "10 through 20")
739 739
 
740 740
         self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())

+ 1
- 1
openstack_dashboard/dashboards/project/networks/subnets/tests.py View File

@@ -336,7 +336,7 @@ class NetworkSubnetTests(test.TestCase):
336 336
         res = self.client.post(url, form_data)
337 337
 
338 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 340
         self.assertTemplateUsed(res, views.WorkflowView.template_name)
341 341
 
342 342
         self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),

+ 28
- 0
openstack_dashboard/test/helpers.py View File

@@ -400,6 +400,34 @@ class TestCase(horizon_helpers.TestCase):
400 400
             0, len(errors),
401 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
 
404 432
 class BaseAdminViewTests(TestCase):
405 433
     """Sets an active user with the "admin" role.

Loading…
Cancel
Save