diff --git a/openstack_dashboard/dashboards/admin/aggregates/tests.py b/openstack_dashboard/dashboards/admin/aggregates/tests.py index 2b6d66da27..2eb825d7e1 100644 --- a/openstack_dashboard/dashboards/admin/aggregates/tests.py +++ b/openstack_dashboard/dashboards/admin/aggregates/tests.py @@ -104,7 +104,7 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests): workflow_data['name'] = '' workflow_data['availability_zone'] = '' self._test_generic_create_aggregate(workflow_data, aggregate, (), 1, - 'This field is required') + 'This field is required.') def test_create_aggregate_fails_missing_fields_existing_aggregates(self): aggregate = self.aggregates.first() @@ -115,7 +115,7 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests): self._test_generic_create_aggregate(workflow_data, aggregate, existing_aggregates, 1, - 'This field is required') + 'This field is required.') def test_create_aggregate_fails_duplicated_name(self): aggregate = self.aggregates.first() @@ -254,7 +254,7 @@ class AggregatesViewTests(test.BaseAdminViewTests): 'availability_zone': aggregate.availability_zone} self._test_generic_update_aggregate(form_data, aggregate, 1, - 'This field is required') + 'This field is required.') def test_update_aggregate_fails_missing_az_field(self): aggregate = self.aggregates.first() diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py index 42ef34fc73..b4a561bd59 100644 --- a/openstack_dashboard/test/helpers.py +++ b/openstack_dashboard/test/helpers.py @@ -28,6 +28,7 @@ from django.contrib.messages.storage import default_storage from django.core.handlers import wsgi from django.test.client import RequestFactory from django.test import tag +from django.test import testcases from django import urls from django.utils import http @@ -313,10 +314,14 @@ class TestCase(horizon_helpers.TestCase): assert len(errors) == count, \ "%d errors were found on the form, %d expected" % \ (len(errors), count) - if message and message not in str(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()]) + if message: + text = testcases.assert_and_parse_html( + self, message, None, '"message" contains invalid HTML:') + content = testcases.assert_and_parse_html( + self, str(errors), None, + '"_errors" in the response context is not valid HTML:') + match_count = content.count(text) + self.assertGreaterEqual(match_count, 1) else: assert len(errors) > 0, "No errors were found on the form"