I defined a simple Document, like this:
class Company(Document):
screen_name = StringField(max_length=100, required=True, unique=True)
official_name = StringField(required=False)
meta = {
'indexes': [{'fields': 'screen_name', 'unique': True}]
}
but when I am writing a test
@use_tdb
def test_company3():
""" test company2 """
company = Company(screen_name='asdasd')
company.save()
company = Company(screen_name='asdasd')
with nt.assert_raises(OperationError):
company.save()
pprint([(x.id, x.screen_name,) for x in Company.objects.all()])
It actually saves both of them. And I see in output:
[(ObjectId('4f719f915c121a21ad000003'), u'asdasd'),
(ObjectId('4f719f915c121a21ad000004'), u'asdasd')]
Any ideas, what I’ve done wrong?
Thanks
That is may be required drop_collection.
See this tests. Mongoengine is all tests is passed.
https://github.com/hmarr/mongoengine/blob/master/tests/document.py#L875
Mongoengine team Recently relaeed 0.6.3.