Mongoengine: Unique does not work in pytest and mongomock

Created on 11 Feb 2018  路  2Comments  路  Source: MongoEngine/mongoengine

I've notice an issue with mongomock and pytest:
mongoengine.errors.NotUniqueError is not raised in my pytest environment, while it works in production with no mongomock db!

class User(LoginDocument):
    id = db.SequenceField(primary_key=True)
    email = db.EmailField(required=True, unique=True)
    password_hash = db.StringField(required=True)

And this test fails:

def test_multiple_email(app, db):
    with pytest.raises(NotUniqueError):
        user1 = User(email="[email protected]", password="")
        user1.save()
        user2 = User(email="[email protected]", password="asd")
        user2.save()
app = <Flask 'server'>
db = <flask_mongoengine.MongoEngine object at 0x10d45a9b0>

    def test_multiple_email(app, db):
        with pytest.raises(NotUniqueError):
            user1 = User(email="[email protected]", password="")
            user1.save()
            user2 = User(email="[email protected]", password="asd")
>           user2.save()
E           Failed: DID NOT RAISE <class 'mongoengine.errors.NotUniqueError'>

Most helpful comment

Looks like this can be closed

All 2 comments

Certainly this is a mongomock issue and not a mongoengine one.

Looks like this can be closed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baruchoxman picture baruchoxman  路  44Comments

bagerard picture bagerard  路  14Comments

gareth-lloyd picture gareth-lloyd  路  26Comments

warvariuc picture warvariuc  路  29Comments

blackvladimir picture blackvladimir  路  22Comments