Support Django 3.0 and 3.1 support (4)
assertFormErrors() now compares actual and expected messages after parsing them as HTML. Similar to the previous commit, after Django 3.0 escaped characters are handled differently (decimal representation, hexdecimal representation and unescaped representation) so we need an uniform way to compare texts. Instead of comparing texts literally, this commit changes assertFormErrors to compare texts after parsing them as HTML. Change-Id: I4ff89cdcb27a2671c7d79fb2caec30585696a30f
This commit is contained in:
parent
a0dd4d738c
commit
44b7c03fba
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue