1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

[py3] Used six.StringIO to simulate stdout buffer in tests

This commit is contained in:
Claude Paroz
2012-08-11 18:56:14 +02:00
parent 09c589810d
commit 3eb28d0119
4 changed files with 13 additions and 15 deletions

View File

@@ -1,10 +1,9 @@
from __future__ import absolute_import
from io import BytesIO
from django.core import management
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils.six import StringIO
from .models import (Person, Group, Membership, UserMembership, Car, Driver,
CarDriver)
@@ -70,11 +69,11 @@ class M2MThroughTestCase(TestCase):
pks = {"p_pk": p.pk, "g_pk": g.pk, "m_pk": m.pk}
out = BytesIO()
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)
out = BytesIO()
out = StringIO()
management.call_command("dumpdata", "m2m_through_regress", format="xml",
indent=2, stdout=out)
self.assertEqual(out.getvalue().strip(), """
@@ -142,6 +141,6 @@ class ThroughLoadDataTestCase(TestCase):
def test_sequence_creation(self):
"Check that sequences on an m2m_through are created for the through model, not a phantom auto-generated m2m table. Refs #11107"
out = BytesIO()
out = StringIO()
management.call_command("dumpdata", "m2m_through_regress", format="json", stdout=out)
self.assertEqual(out.getvalue().strip(), """[{"pk": 1, "model": "m2m_through_regress.usermembership", "fields": {"price": 100, "group": 1, "user": 1}}, {"pk": 1, "model": "m2m_through_regress.person", "fields": {"name": "Guido"}}, {"pk": 1, "model": "m2m_through_regress.group", "fields": {"name": "Python Core Group"}}]""")