Ticket #24282: ticket_24282.patch

File ticket_24282.patch, 2.3 KB (added by Andriy Sokolovskiy, 9 years ago)

test to reproduce the issue (but it is passing correct)

  • tests/migrations/test_operations.py

    diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
    index d8a042d..7bcdf5d 100644
    a b class OperationTestBase(MigrationTestBase):  
    112112                [
    113113                    ("id", models.AutoField(primary_key=True)),
    114114                    ("pony", models.ForeignKey("Pony")),
    115                     ("friend", models.ForeignKey("self"))
     115                    ("friend", models.ForeignKey("self", null=True))
    116116                ],
    117117            ))
    118118        if mti_model:
    class OperationTests(OperationTestBase):  
    15381538        Tests the RunPython operation
    15391539        """
    15401540
    1541         project_state = self.set_up_test_model("test_runpython", mti_model=True)
     1541        project_state = self.set_up_test_model("test_runpython", mti_model=True, related_model=True)
    15421542
    15431543        # Create the operation
    15441544        def inner_method(models, schema_editor):
    class OperationTests(OperationTestBase):  
    16161616        self.assertEqual(project_state.apps.get_model("test_runpython", "Pony").objects.count(), 6)
    16171617        self.assertEqual(project_state.apps.get_model("test_runpython", "ShetlandPony").objects.count(), 2)
    16181618
     1619    def test_run_python_with_related_objects(self):
     1620        project_state = self.set_up_test_model("test_runpython_with_rel_objects", related_model=True)
     1621        new_state = project_state.clone()
     1622
     1623        def create_pony_with_rider(models, schema_editor):
     1624            Pony = models.get_model("test_runpython_with_rel_objects", "Pony")
     1625            Rider = models.get_model("test_runpython_with_rel_objects", "Rider")
     1626            pony_obj = Pony.objects.create(weight=13.13)
     1627            rider = Rider(pony=pony_obj)
     1628            rider.save()
     1629
     1630        operation = migrations.RunPython(create_pony_with_rider)
     1631        with connection.schema_editor() as editor:
     1632            operation.database_forwards("test_runpython_with_rel_objects", editor, project_state, new_state)
     1633        self.assertEqual(project_state.apps.get_model("test_runpython_with_rel_objects", "Pony").objects.count(), 1)
     1634        self.assertEqual(project_state.apps.get_model("test_runpython_with_rel_objects", "Rider").objects.count(), 1)
     1635
    16191636    def test_run_python_atomic(self):
    16201637        """
    16211638        Tests the RunPython operation correctly handles the "atomic" keyword
Back to Top