예제 #1
0
 def test_non_existing_view(self, app, post):
     field = Relationship(
         related_view='non_existing_view',
         related_view_kwargs={'author_id': '<author>'}
     )
     with pytest.raises(BuildError):
         field.serialize('author', post)
예제 #2
0
 def test_non_existing_view(self, app, post):
     field = Relationship(
         related_view='non_existing_view',
         related_view_kwargs={'author_id': '<author>'}
     )
     with pytest.raises(BuildError):
         field.serialize('author', post)
예제 #3
0
 def test_non_existing_view(self, app, post):
     field = Relationship(
         related_view="non_existing_view",
         related_view_kwargs={"author_id": "<author>"},
     )
     with pytest.raises(BuildError):
         field.serialize("author", post)
예제 #4
0
    def test_empty_relationship(self, app, post_with_null_author):
        field = Relationship(
            related_view='author_detail',
            related_view_kwargs={'author_id': '<author>'}
        )
        result = field.serialize('author', post_with_null_author)

        assert not result
예제 #5
0
 def test_serialize_external(self, app, post):
     field = Relationship(
         related_view='posts_comments',
         related_view_kwargs={'post_id': '<id>', '_external': True},
     )
     result = field.serialize('comments', post)
     related = result['links']['related']
     assert related == url_for('posts_comments', post_id=post.id, _external=True)
예제 #6
0
 def test_serialize_self_link(self, app, post):
     field = Relationship(self_view="posts_comments",
                          self_view_kwargs={"post_id": "<id>"})
     result = field.serialize("comments", post)
     assert "links" in result
     assert "self" in result["links"]
     related = result["links"]["self"]
     assert related == url_for("posts_comments", post_id=post.id)
예제 #7
0
    def test_empty_relationship(self, app, post_with_null_author):
        field = Relationship(
            related_view='author_detail',
            related_view_kwargs={'author_id': '<author>'}
        )
        result = field.serialize('author', post_with_null_author)

        assert not result
예제 #8
0
 def test_serialize_external(self, app, post):
     field = Relationship(
         related_view='posts_comments',
         related_view_kwargs={'post_id': '<id>', '_external': True},
     )
     result = field.serialize('comments', post)
     related = result['links']['related']
     assert related == url_for('posts_comments', post_id=post.id, _external=True)
예제 #9
0
    def test_empty_relationship_with_alternative_identifier_field(self, app, post_with_null_author):
        field = Relationship(
            related_view='author_detail',
            related_view_kwargs={'author_id': '<author.last_name>'},
            default=None
        )
        result = field.serialize('author', post_with_null_author)

        assert not result
예제 #10
0
 def test_serialize_self_link(self, app, post):
     field = Relationship(
         self_view='posts_comments',
         self_view_kwargs={'post_id': '<id>'},
     )
     result = field.serialize('comments', post)
     assert 'comments' in result
     related = result['comments']['links']['self']
     assert related == url_for('posts_comments', post_id=post.id)
예제 #11
0
 def test_serialize_self_link(self, app, post):
     field = Relationship(
         self_view='posts_comments',
         self_view_kwargs={'post_id': '<id>'},
     )
     result = field.serialize('comments', post)
     assert 'comments' in result
     related = result['comments']['links']['self']
     assert related == url_for('posts_comments', post_id=post.id)
예제 #12
0
 def test_serialize_basic(self, app, post):
     field = Relationship(
         related_view='posts_comments',
         related_view_kwargs={'post_id': '<id>'},
     )
     result = field.serialize('comments', post)
     assert 'links' in result
     assert 'related' in result['links']
     related = result['links']['related']
     assert related == url_for('posts_comments', post_id=post.id)
예제 #13
0
    def test_empty_relationship_with_alternative_identifier_field(
            self, app, post_with_null_author):
        field = Relationship(
            related_view="author_detail",
            related_view_kwargs={"author_id": "<author.last_name>"},
            default=None,
        )
        result = field.serialize("author", post_with_null_author)

        assert not result
예제 #14
0
 def test_serialize_basic(self, app, post):
     field = Relationship(
         related_view='posts_comments',
         related_view_kwargs={'post_id': '<id>'},
     )
     result = field.serialize('comments', post)
     assert 'links' in result
     assert 'related' in result['links']
     related = result['links']['related']
     assert related == url_for('posts_comments', post_id=post.id)
예제 #15
0
 def test_serialize_external(self, app, post):
     field = Relationship(
         related_view="posts_comments",
         related_view_kwargs={
             "post_id": "<id>",
             "_external": True
         },
     )
     result = field.serialize("comments", post)
     related = result["links"]["related"]
     assert related == url_for("posts_comments",
                               post_id=post.id,
                               _external=True)
예제 #16
0
    def test_empty_relationship(self, app, post_with_null_author):
        field = Relationship(related_view="author_detail",
                             related_view_kwargs={"author_id": "<author>"})
        result = field.serialize("author", post_with_null_author)

        assert not result