Ticket #13799: django-m2m-tests.diff

File django-m2m-tests.diff, 2.8 KB (added by Alex Gaynor, 13 years ago)
  • tests/regressiontests/m2m_through_regress/tests.py

    diff --git a/tests/regressiontests/m2m_through_regress/tests.py b/tests/regressiontests/m2m_through_regress/tests.py
    index ff1d950..d33ea40 100644
    a b class M2MThroughTestCase(TestCase): 
    6666
    6767        p = Person.objects.create(name="Bob")
    6868        g = Group.objects.create(name="Roll")
    69         Membership.objects.create(person=p, group=g)
     69        m =Membership.objects.create(person=p, group=g)
     70       
     71        pks = {"p_pk": p.pk, "g_pk": g.pk, "m_pk": m.pk}
    7072
    7173        out = StringIO()
    7274        management.call_command("dumpdata", "m2m_through_regress", format="json", stdout=out)
    73         self.assertEqual(out.getvalue().strip(), """[{"pk": 1, "model": "m2m_through_regress.membership", "fields": {"person": 1, "price": 100, "group": 1}}, {"pk": 1, "model": "m2m_through_regress.person", "fields": {"name": "Bob"}}, {"pk": 1, "model": "m2m_through_regress.group", "fields": {"name": "Roll"}}]""")
     75        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)
    7476
    7577        out = StringIO()
    7678        management.call_command("dumpdata", "m2m_through_regress", format="xml",
    class M2MThroughTestCase(TestCase): 
    7880        self.assertEqual(out.getvalue().strip(), """
    7981<?xml version="1.0" encoding="utf-8"?>
    8082<django-objects version="1.0">
    81   <object pk="1" model="m2m_through_regress.membership">
    82     <field to="m2m_through_regress.person" name="person" rel="ManyToOneRel">1</field>
    83     <field to="m2m_through_regress.group" name="group" rel="ManyToOneRel">1</field>
     83  <object pk="%(m_pk)s" model="m2m_through_regress.membership">
     84    <field to="m2m_through_regress.person" name="person" rel="ManyToOneRel">%(p_pk)s</field>
     85    <field to="m2m_through_regress.group" name="group" rel="ManyToOneRel">%(g_pk)s</field>
    8486    <field type="IntegerField" name="price">100</field>
    8587  </object>
    86   <object pk="1" model="m2m_through_regress.person">
     88  <object pk="%(p_pk)s" model="m2m_through_regress.person">
    8789    <field type="CharField" name="name">Bob</field>
    8890  </object>
    89   <object pk="1" model="m2m_through_regress.group">
     91  <object pk="%(g_pk)s" model="m2m_through_regress.group">
    9092    <field type="CharField" name="name">Roll</field>
    9193  </object>
    9294</django-objects>
    93         """.strip())
     95        """.strip() % pks)
    9496
    9597    def test_join_trimming(self):
    9698        "Check that we don't involve too many copies of the intermediate table when doing a join. Refs #8046, #8254"
Back to Top