Skip to content

Commit

Permalink
Add a test for persisting a new doc containing nothing but a custom ID
Browse files Browse the repository at this point in the history
This closes #1246.
  • Loading branch information
wojcikstefan committed Jun 18, 2019
1 parent f8593d8 commit 4714e83
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/document/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ class User(Document):
exc = e.exception
self.assertTrue("Field is required: ['username']" in exc.message)

def test_custom_id_field_save_doc_with_nothing_but_pk(self):
"""Ensure we can still save a doc even if it only has a PK."""
class Sample(Document):
key = StringField(primary_key=True)
count = IntField()

Sample.drop_collection()

sample = Sample()
sample.key = '123'
sample.save()

sample = Sample.objects.first()
self.assertEqual(sample.key, '123')
self.assertEqual(sample.pk, '123')

def test_document_not_registered(self):
class Place(Document):
name = StringField()
Expand Down

0 comments on commit 4714e83

Please sign in to comment.