diff options
| author | Ian Clelland <ian@fullfactor.com> | 2012-09-28 00:20:01 -0700 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2012-12-24 02:19:16 +0000 |
| commit | 515cf94b6031cd03039d2a6617969b673eacf848 (patch) | |
| tree | 728b9c2d71aa86511d2117d5ced0906d3433298b /tests/modeltests | |
| parent | 5eba053459272dce908656a5bfca2c6bab2cfc76 (diff) | |
[1.5.x] Use new TestCase methods for equality comparisons
Backport of 8d35fd4c327e05b63c72a1c1e9a4a68de4dddcf0 from master
Diffstat (limited to 'tests/modeltests')
| -rw-r--r-- | tests/modeltests/field_subclassing/tests.py | 6 | ||||
| -rw-r--r-- | tests/modeltests/fixtures/tests.py | 19 |
2 files changed, 16 insertions, 9 deletions
diff --git a/tests/modeltests/field_subclassing/tests.py b/tests/modeltests/field_subclassing/tests.py index 48755123f2..55017fe366 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 b667c8c6d4..dc809122c8 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): <django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Time to reform copyright</field><field type="DateTimeField" name="pub_date">2006-06-16T13:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">law</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>""", 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): |
