implement unique constraint checking

This commit is contained in:
evilchili
2025-09-27 12:09:43 -07:00
parent 99dbfe7e2d
commit 7e7d61efe9
3 changed files with 51 additions and 7 deletions
+11
View File
@@ -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)