def test_required_references_throw_a_validation_error_on_empty(): ref = Reference(Address, required=True) with pytest.raises(ValidationError) as exc: ref._load(None) assert exc.value.messages == {"unlinked": ["is required"]}
class Comment(BaseEntity): content = Text() added_on = DateTime() post = Reference("Post") foo = Reference("Foo") class Meta: aggregate_cls = Post
class Comment(BaseEntity): content = Text(required=True) post = Reference("Post") class Meta: aggregate_cls = "Post"
class Author(BaseEntity): first_name = String(required=True, max_length=25) last_name = String(max_length=25) account = Reference("Account") class Meta: aggregate_cls = Account
class CommentViaWithReference(BaseEntity): content = Text() added_on = DateTime() posting = Reference("tests.aggregate.elements.PostVia") class Meta: aggregate_cls = PostViaWithReference
class PostMeta(BaseEntity): likes = Integer(default=0) post = Reference(Post) class Meta: aggregate_cls = Post
class Author(BaseEntity): first_name = String(required=True, max_length=25) last_name = String(max_length=25) posts = HasMany("tests.aggregate.elements.Post") account = Reference("tests.aggregate.elements.Account") class Meta: aggregate_cls = Account
class Comment(BaseEntity): content = Text(required=True) commented_at = DateTime(required=True, default=datetime.now()) post = Reference(Post) class Meta: aggregate_cls = Post
class Comment: content = String(max_length=500) post = Reference("Post") class Meta: aggregate_cls = Post
class User(BaseAggregate): address = Reference(Address, required=True)
class PostViaWithReference(BaseAggregate): content = Text(required=True) comments = HasMany( "tests.aggregate.elements.CommentViaWithReference", via="posting_id" ) author = Reference("tests.aggregate.elements.Author")
class User(BaseView): user_id = Identifier(identifier=True) role = Reference(Role)
class ProfileViaWithReference(BaseAggregate): about_me = Text() ac = Reference("tests.aggregate.elements.AccountViaWithReference")
class ProfileWithAccountId(BaseAggregate): about_me = Text() account = Reference("tests.aggregate.elements.AccountWithId")
class Profile(BaseAggregate): about_me = Text() account = Reference("tests.aggregate.elements.Account", via="username")
class PostMeta(BaseEntity): likes = Integer(default=0) post = Reference(Post)
class Post(BaseAggregate): content = Text(required=True) comments = HasMany("tests.aggregate.elements.Comment") author = Reference("tests.aggregate.elements.Author")