MCPcopy
hub / github.com/django/django / test_add_field

Method test_add_field

tests/migrations/test_state.py:1432–1468  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1430 )
1431
1432 def test_add_field(self):
1433 project_state = self.get_base_project_state()
1434 self.assertNotIn(("tests", "post"), project_state.relations)
1435 # Add a self-referential foreign key.
1436 new_field = models.ForeignKey("self", models.CASCADE)
1437 project_state.add_field(
1438 "tests",
1439 "post",
1440 "next_post",
1441 new_field,
1442 preserve_default=True,
1443 )
1444 self.assertEqual(
1445 list(project_state.relations["tests", "post"]),
1446 [("tests", "post")],
1447 )
1448 self.assertEqual(
1449 project_state.relations["tests", "post"]["tests", "post"],
1450 {"next_post": new_field},
1451 )
1452 # Add a foreign key.
1453 new_field = models.ForeignKey("tests.post", models.CASCADE)
1454 project_state.add_field(
1455 "tests",
1456 "comment",
1457 "post",
1458 new_field,
1459 preserve_default=True,
1460 )
1461 self.assertEqual(
1462 list(project_state.relations["tests", "post"]),
1463 [("tests", "post"), ("tests", "comment")],
1464 )
1465 self.assertEqual(
1466 project_state.relations["tests", "post"]["tests", "comment"],
1467 {"post": new_field},
1468 )
1469
1470 def test_add_field_m2m_with_through(self):
1471 project_state = self.get_base_project_state()

Callers

nothing calls this directly

Calls 2

add_fieldMethod · 0.45

Tested by

no test coverage detected