implement unique constraint checking
This commit is contained in:
@@ -3,6 +3,7 @@ from tinydb.storages import MemoryStorage
|
||||
|
||||
from grung import examples
|
||||
from grung.db import GrungDB
|
||||
from grung.exceptions import UniqueConstraintError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -49,3 +50,13 @@ def test_crud(db):
|
||||
# delete
|
||||
db.delete(players)
|
||||
assert len(db.Group) == 0
|
||||
|
||||
|
||||
def test_unique(db):
|
||||
user1 = examples.User(name="john", email="john@foo")
|
||||
user2 = examples.User(name="john", email="john@foo")
|
||||
|
||||
user1 = db.save(user1)
|
||||
with pytest.raises(UniqueConstraintError):
|
||||
user2 = db.save(user2)
|
||||
db.save(user1)
|
||||
|
||||
Reference in New Issue
Block a user