diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index d8a042d..7bcdf5d 100644
a
|
b
|
class OperationTestBase(MigrationTestBase):
|
112 | 112 | [ |
113 | 113 | ("id", models.AutoField(primary_key=True)), |
114 | 114 | ("pony", models.ForeignKey("Pony")), |
115 | | ("friend", models.ForeignKey("self")) |
| 115 | ("friend", models.ForeignKey("self", null=True)) |
116 | 116 | ], |
117 | 117 | )) |
118 | 118 | if mti_model: |
… |
… |
class OperationTests(OperationTestBase):
|
1538 | 1538 | Tests the RunPython operation |
1539 | 1539 | """ |
1540 | 1540 | |
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) |
1542 | 1542 | |
1543 | 1543 | # Create the operation |
1544 | 1544 | def inner_method(models, schema_editor): |
… |
… |
class OperationTests(OperationTestBase):
|
1616 | 1616 | self.assertEqual(project_state.apps.get_model("test_runpython", "Pony").objects.count(), 6) |
1617 | 1617 | self.assertEqual(project_state.apps.get_model("test_runpython", "ShetlandPony").objects.count(), 2) |
1618 | 1618 | |
| 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 | |
1619 | 1636 | def test_run_python_atomic(self): |
1620 | 1637 | """ |
1621 | 1638 | Tests the RunPython operation correctly handles the "atomic" keyword |