Skip to content

Commit 3448c16

Browse files
committed
add test for ModelForm data using numeric pks
1 parent 4dbb5f6 commit 3448c16

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tests/model_forms/tests.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,9 @@ def test_auto_id(self):
15121512
<li>The URL: <input type="text" name="url" maxlength="40" required></li>""",
15131513
)
15141514

1515-
def test_initial_values(self):
1516-
self.create_basic_data()
1515+
def test_initial_values(self, create_data=True):
1516+
if create_data:
1517+
self.create_basic_data()
15171518
# Initial values can be provided for model forms
15181519
f = ArticleForm(
15191520
auto_id=False,
@@ -1624,6 +1625,26 @@ def test_initial_values(self):
16241625
test_art = Article.objects.get(id=art_id_1)
16251626
self.assertEqual(test_art.headline, "Test headline")
16261627

1628+
def test_int_pks(self):
1629+
"""
1630+
MongoAutoField supports numeric pks in ModelForm data, not just
1631+
ObjectId.
1632+
"""
1633+
# The following lines repeat self.create_initial_data() but with
1634+
# manually assigned pks.
1635+
self.c1 = Category.objects.create(
1636+
pk=1, name="Entertainment", slug="entertainment", url="entertainment"
1637+
)
1638+
self.c2 = Category.objects.create(
1639+
pk=2, name="It's a test", slug="its-test", url="test"
1640+
)
1641+
self.c3 = Category.objects.create(
1642+
pk=3, name="Third test", slug="third-test", url="third"
1643+
)
1644+
self.w_royko = Writer.objects.create(name="Mike Royko", pk=1)
1645+
self.w_woodward = Writer.objects.create(name="Bob Woodward", pk=2)
1646+
self.test_initial_values(create_data=False)
1647+
16271648
def test_m2m_initial_callable(self):
16281649
"""
16291650
A callable can be provided as the initial value for an m2m field.

0 commit comments

Comments
 (0)