add constraint check for recursion
This commit is contained in:
+7
-8
@@ -10,7 +10,7 @@ from tinydb.storages import MemoryStorage
|
||||
|
||||
from grung import examples
|
||||
from grung.db import GrungDB
|
||||
from grung.exceptions import PointerReferenceError, UniqueConstraintError
|
||||
from grung.exceptions import CircularReferenceError, UniqueConstraintError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -49,13 +49,7 @@ def test_crud(db):
|
||||
|
||||
|
||||
def test_pointers(db):
|
||||
user = examples.User(name="john", email="john@foo")
|
||||
players = examples.Group(name="players", members=[user])
|
||||
|
||||
with pytest.raises(PointerReferenceError):
|
||||
players = db.save(players)
|
||||
|
||||
user = db.save(user)
|
||||
user = db.save(examples.User(name="john", email="john@foo"))
|
||||
players = db.save(examples.Group(name="players", members=[user]))
|
||||
|
||||
user = db.table("User").get(doc_id=user.doc_id)
|
||||
@@ -86,6 +80,11 @@ def test_subgroups(db):
|
||||
kirk = db.table("User").get(doc_id=kirk.doc_id)
|
||||
assert kirk.reference in unique_users
|
||||
|
||||
# recursion!
|
||||
with pytest.raises(CircularReferenceError):
|
||||
tos.members = [tos]
|
||||
db.save(tos)
|
||||
|
||||
|
||||
def test_unique(db):
|
||||
user1 = examples.User(name="john", email="john@foo")
|
||||
|
||||
Reference in New Issue
Block a user