diff --git a/django/contrib/formtools/tests/wizard/cookiestorage.py b/django/contrib/formtools/tests/wizard/cookiestorage.py
index d450f478614..3f26b85f7d3 100644
--- a/django/contrib/formtools/tests/wizard/cookiestorage.py
+++ b/django/contrib/formtools/tests/wizard/cookiestorage.py
@@ -43,5 +43,5 @@ class TestCookieStorage(TestStorage, TestCase):
storage.init_data()
storage.update_response(response)
unsigned_cookie_data = cookie_signer.unsign(response.cookies[storage.prefix].value)
- self.assertEqual(json.loads(unsigned_cookie_data),
+ self.assertJSONEqual(unsigned_cookie_data,
{"step_files": {}, "step": None, "extra_data": {}, "step_data": {}})
diff --git a/tests/modeltests/field_subclassing/tests.py b/tests/modeltests/field_subclassing/tests.py
index 48755123f2b..55017fe366f 100644
--- a/tests/modeltests/field_subclassing/tests.py
+++ b/tests/modeltests/field_subclassing/tests.py
@@ -61,7 +61,11 @@ class CustomField(TestCase):
# Serialization works, too.
stream = serializers.serialize("json", MyModel.objects.all())
- self.assertEqual(stream, '[{"pk": %d, "model": "field_subclassing.mymodel", "fields": {"data": "12", "name": "m"}}]' % m1.pk)
+ self.assertJSONEqual(stream, [{
+ "pk": m1.pk,
+ "model": "field_subclassing.mymodel",
+ "fields": {"data": "12", "name": "m"}
+ }])
obj = list(serializers.deserialize("json", stream))[0]
self.assertEqual(obj.object, m)
diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
index b667c8c6d45..dc809122c83 100644
--- a/tests/modeltests/fixtures/tests.py
+++ b/tests/modeltests/fixtures/tests.py
@@ -22,7 +22,7 @@ class TestCaseFixtureLoadingTests(TestCase):
])
-class FixtureLoadingTests(TestCase):
+class DumpDataAssertMixin(object):
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
use_base_manager=False, exclude_list=[]):
@@ -34,7 +34,15 @@ class FixtureLoadingTests(TestCase):
'use_base_manager': use_base_manager,
'exclude': exclude_list})
command_output = new_io.getvalue().strip()
- self.assertEqual(command_output, output)
+ if format == "json":
+ self.assertJSONEqual(command_output, output)
+ elif format == "xml":
+ self.assertXMLEqual(command_output, output)
+ else:
+ self.assertEqual(command_output, output)
+
+
+class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_initial_data(self):
# syncdb introduces 1 initial data object from initial_data.json.
@@ -290,12 +298,7 @@ class FixtureLoadingTests(TestCase):
""", format='xml', natural_keys=True)
-class FixtureTransactionTests(TransactionTestCase):
- def _dumpdata_assert(self, args, output, format='json'):
- new_io = six.StringIO()
- management.call_command('dumpdata', *args, **{'format': format, 'stdout': new_io})
- command_output = new_io.getvalue().strip()
- self.assertEqual(command_output, output)
+class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
@skipUnlessDBFeature('supports_forward_references')
def test_format_discovery(self):
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index e8d4cbff162..7a3a5c0e031 100644
--- a/tests/regressiontests/admin_changelist/tests.py
+++ b/tests/regressiontests/admin_changelist/tests.py
@@ -122,12 +122,11 @@ class ChangeListTests(TestCase):
table_output = template.render(context)
# make sure that hidden fields are in the correct place
hiddenfields_div = '
' % new_child.id
- self.assertFalse(table_output.find(hiddenfields_div) == -1,
- 'Failed to find hidden fields in: %s' % table_output)
+ self.assertInHTML(hiddenfields_div, table_output, msg_prefix='Failed to find hidden fields')
+
# make sure that list editable fields are rendered in divs correctly
editable_name_field = ''
- self.assertFalse('%s | ' % editable_name_field == -1,
- 'Failed to find "name" list_editable field in: %s' % table_output)
+ self.assertInHTML('%s | ' % editable_name_field, table_output, msg_prefix='Failed to find "name" list_editable field')
def test_result_list_editable(self):
"""
diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
index 988c5acd0c9..67911434730 100644
--- a/tests/regressiontests/fixtures_regress/tests.py
+++ b/tests/regressiontests/fixtures_regress/tests.py
@@ -358,7 +358,7 @@ class TestFixtures(TestCase):
format='json',
stdout=stdout
)
- self.assertEqual(
+ self.assertJSONEqual(
stdout.getvalue(),
"""[{"pk": %d, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]"""
% widget.pk
@@ -519,7 +519,7 @@ class NaturalKeyFixtureTests(TestCase):
use_natural_keys=True,
stdout=stdout,
)
- self.assertEqual(
+ self.assertJSONEqual(
stdout.getvalue(),
"""[{"pk": 2, "model": "fixtures_regress.store", "fields": {"main": null, "name": "Amazon"}}, {"pk": 3, "model": "fixtures_regress.store", "fields": {"main": null, "name": "Borders"}}, {"pk": 4, "model": "fixtures_regress.person", "fields": {"name": "Neal Stephenson"}}, {"pk": 1, "model": "fixtures_regress.book", "fields": {"stores": [["Amazon"], ["Borders"]], "name": "Cryptonomicon", "author": ["Neal Stephenson"]}}]"""
)
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index dcc288e600c..44d84f91432 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -634,7 +634,7 @@ class FormattingTests(TestCase):
self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added'])
with self.settings(USE_THOUSAND_SEPARATOR=True):
# Checking for the localized "products_delivered" field
- self.assertTrue('' in form6.as_ul())
+ self.assertInHTML('', form6.as_ul())
def test_iter_format_modules(self):
"""
diff --git a/tests/regressiontests/m2m_through_regress/tests.py b/tests/regressiontests/m2m_through_regress/tests.py
index eba956b3ba5..7448396013c 100644
--- a/tests/regressiontests/m2m_through_regress/tests.py
+++ b/tests/regressiontests/m2m_through_regress/tests.py
@@ -71,12 +71,12 @@ class M2MThroughTestCase(TestCase):
out = StringIO()
management.call_command("dumpdata", "m2m_through_regress", format="json", stdout=out)
- self.assertEqual(out.getvalue().strip(), """[{"pk": %(m_pk)s, "model": "m2m_through_regress.membership", "fields": {"person": %(p_pk)s, "price": 100, "group": %(g_pk)s}}, {"pk": %(p_pk)s, "model": "m2m_through_regress.person", "fields": {"name": "Bob"}}, {"pk": %(g_pk)s, "model": "m2m_through_regress.group", "fields": {"name": "Roll"}}]""" % pks)
+ self.assertJSONEqual(out.getvalue().strip(), """[{"pk": %(m_pk)s, "model": "m2m_through_regress.membership", "fields": {"person": %(p_pk)s, "price": 100, "group": %(g_pk)s}}, {"pk": %(p_pk)s, "model": "m2m_through_regress.person", "fields": {"name": "Bob"}}, {"pk": %(g_pk)s, "model": "m2m_through_regress.group", "fields": {"name": "Roll"}}]""" % pks)
out = StringIO()
management.call_command("dumpdata", "m2m_through_regress", format="xml",
indent=2, stdout=out)
- self.assertEqual(out.getvalue().strip(), """
+ self.assertXMLEqual(out.getvalue().strip(), """