def test_deserialize_many_non_list_relationship(self):
     field = Relationship(many=True,
                          include_resource_linkage=True,
                          type_="comments")
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({"data": "1"})
     assert excinfo.value.args[0] == "Relationship is list-like"
Пример #2
0
 def test_deserialize_non_many_list_relationship(self):
     field = Relationship(many=False,
                          include_resource_linkage=True,
                          type_='comments')
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({'data': ['1']})
     assert excinfo.value.args[0] == 'Relationship is not list-like'
Пример #3
0
 def test_deserialize_empty_relationship_node(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=False, include_resource_linkage=False, type_='comments'
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({})
     assert excinfo.value.args[0] == 'Must include a `data` key'
Пример #4
0
 def test_deserialize_null_value_disallow_none(self):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'}, allow_none=False,
         many=False, include_resource_linkage=False, type_='comments'
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({'data': None})
     assert excinfo.value.args[0] == 'Field may not be null.'
Пример #5
0
 def test_deserialize_empty_relationship_node(self):
     field = Relationship(related_url='/posts/{post_id}/comments',
                          related_url_kwargs={'post_id': '<id>'},
                          many=False,
                          include_resource_linkage=False,
                          type_='comments')
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({})
     assert excinfo.value.args[0] == 'Must include a `data` key'
Пример #6
0
 def test_deserialize_null_value_disallow_none(self):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'}, allow_none=False,
         many=False, include_data=False, type_='comments'
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({'data': None})
     assert excinfo.value.args[0] == 'Field may not be null.'
Пример #7
0
 def test_deserialize_data_missing_id(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=False, include_resource_linkage=True, type_='comments'
     )
     with pytest.raises(ValidationError) as excinfo:
         value = {'data': {'type': 'comments'}}
         field.deserialize(value)
     assert excinfo.value.args[0] == ['Must have an `id` field']
Пример #8
0
 def test_deserialize_data_incorrect_type(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=False, include_resource_linkage=True, type_='comments'
     )
     with pytest.raises(ValidationError) as excinfo:
         value = {'data': {'type': 'posts', 'id': '1'}}
         field.deserialize(value)
     assert excinfo.value.args[0] == ['Invalid `type` specified']
Пример #9
0
 def test_deserialize_empty_data_node(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=False, include_data=False, type_='comments'
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({'data': {}})
     assert excinfo.value.args[0] == [
         'Must have an `id` field', 'Must have a `type` field']
Пример #10
0
 def test_deserialize_data_missing_id(self):
     field = Relationship(related_url='/posts/{post_id}/comments',
                          related_url_kwargs={'post_id': '<id>'},
                          many=False,
                          include_resource_linkage=True,
                          type_='comments')
     with pytest.raises(ValidationError) as excinfo:
         value = {'data': {'type': 'comments'}}
         field.deserialize(value)
     assert excinfo.value.args[0] == ['Must have an `id` field']
Пример #11
0
 def test_deserialize_data_incorrect_type(self):
     field = Relationship(related_url='/posts/{post_id}/comments',
                          related_url_kwargs={'post_id': '<id>'},
                          many=False,
                          include_resource_linkage=True,
                          type_='comments')
     with pytest.raises(ValidationError) as excinfo:
         value = {'data': {'type': 'posts', 'id': '1'}}
         field.deserialize(value)
     assert excinfo.value.args[0] == ['Invalid `type` specified']
 def test_deserialize_required_empty(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         required=True,
         many=False,
         include_resource_linkage=False,
         type_="comments",
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({})
     assert excinfo.value.args[0] == "Must include a `data` key"
 def test_deserialize_null_value_disallow_none(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         allow_none=False,
         many=False,
         include_resource_linkage=False,
         type_="comments",
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({"data": None})
     assert excinfo.value.args[0] == "Field may not be null."
 def test_deserialize_data_incorrect_type(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         many=False,
         include_resource_linkage=True,
         type_="comments",
     )
     with pytest.raises(ValidationError) as excinfo:
         value = {"data": {"type": "posts", "id": "1"}}
         field.deserialize(value)
     assert excinfo.value.args[0] == ["Invalid `type` specified"]
 def test_deserialize_data_missing_id(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         many=False,
         include_resource_linkage=True,
         type_="comments",
     )
     with pytest.raises(ValidationError) as excinfo:
         value = {"data": {"type": "comments"}}
         field.deserialize(value)
     assert excinfo.value.args[0] == ["Must have an `id` field"]
 def test_deserialize_empty_data(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         many=False,
         include_resource_linkage=False,
         type_="comments",
     )
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({"data": {}})
     assert excinfo.value.args[0] == [
         "Must have an `id` field",
         "Must have a `type` field",
     ]
Пример #17
0
    def test_resource_linkage_id_of_invalid_type(self):
        class AuthorSchema(Schema):
            id = Int(attribute="author_id", as_string=True)

            class Meta:
                type_ = "authors"
                strict = True

        field = Relationship(
            include_resource_linkage=True, type_="authors", schema=AuthorSchema
        )

        with pytest.raises(ValidationError) as excinfo:
            field.deserialize({"data": {"type": "authors", "id": "not_a_number"}})
        assert excinfo.value.args[0] == "Not a valid integer."
Пример #18
0
 def test_deserialize_empty_data_list(self):
     field = Relationship(related_url='/posts/{post_id}/comments',
                          related_url_kwargs={'post_id': '<id>'},
                          many=True,
                          include_resource_linkage=False,
                          type_='comments')
     result = field.deserialize({'data': []})
     assert result == []
Пример #19
0
 def test_deserialize_null_data_value(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'}, allow_none=True,
         many=False, include_data=False, type_='comments'
     )
     result = field.deserialize({'data': None})
     assert result is None
Пример #20
0
 def test_deserialize_null_data_value(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'}, allow_none=True,
         many=False, include_resource_linkage=False, type_='comments'
     )
     result = field.deserialize({'data': None})
     assert result is None
Пример #21
0
 def test_deserialize_empty_data_list(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=True, include_resource_linkage=False, type_='comments'
     )
     result = field.deserialize({'data': []})
     assert result == []
Пример #22
0
 def test_deserialize_data_many(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=True, include_resource_linkage=True, type_='comments'
     )
     value = {'data': [{'type': 'comments', 'id': '1'}]}
     result = field.deserialize(value)
     assert result == ['1']
Пример #23
0
 def test_deserialize_data_many(self):
     field = Relationship(related_url='/posts/{post_id}/comments',
                          related_url_kwargs={'post_id': '<id>'},
                          many=True,
                          include_resource_linkage=True,
                          type_='comments')
     value = {'data': [{'type': 'comments', 'id': '1'}]}
     result = field.deserialize(value)
     assert result == ['1']
Пример #24
0
 def test_deserialize_data_single(self, post):
     field = Relationship(
         related_url='/posts/{post_id}/comments',
         related_url_kwargs={'post_id': '<id>'},
         many=False, include_data=True, type_='comments'
     )
     value = {'data': {'type': 'comments', 'id': '1'}}
     result = field.deserialize(value)
     assert result == '1'
 def test_deserialize_empty_data_list(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         many=True,
         include_resource_linkage=False,
         type_="comments",
     )
     result = field.deserialize({"data": []})
     assert result == []
Пример #26
0
 def test_deserialize_missing(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         many=False,
         include_resource_linkage=True,
         type_="comments",
     )
     result = field.deserialize(missing_)
     assert result is missing_
 def test_deserialize_null_data_value(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         allow_none=True,
         many=False,
         include_resource_linkage=False,
         type_="comments",
     )
     result = field.deserialize({"data": None})
     assert result is None
 def test_deserialize_data_many(self):
     field = Relationship(
         related_url="/posts/{post_id}/comments",
         related_url_kwargs={"post_id": "<id>"},
         many=True,
         include_resource_linkage=True,
         type_="comments",
     )
     value = {"data": [{"type": "comments", "id": "1"}]}
     result = field.deserialize(value)
     assert result == ["1"]
Пример #29
0
    def test_resource_linkage_id_of_invalid_type(self):
        class AuthorSchema(Schema):
            id = Int(attribute='author_id', as_string=True)

            class Meta:
                type_ = 'authors'
                strict = True

        field = Relationship(
            include_resource_linkage=True,
            type_='authors',
            schema=AuthorSchema,
        )

        with pytest.raises(ValidationError) as excinfo:
            field.deserialize(
                {'data': {
                    'type': 'authors',
                    'id': 'not_a_number'
                }})
        assert excinfo.value.args[0] == 'Not a valid integer.'
    def test_resource_linkage_id_type_from_schema(self):
        class AuthorSchema(Schema):
            id = Int(attribute="author_id", as_string=True)

            class Meta:
                type_ = "authors"
                strict = True

        field = Relationship(include_resource_linkage=True,
                             type_="authors",
                             schema=AuthorSchema)

        result = field.deserialize({"data": {"type": "authors", "id": "1"}})

        assert result == 1
Пример #31
0
    def test_resource_linkage_id_type_from_schema(self):
        class AuthorSchema(Schema):
            id = Int(attribute='author_id', as_string=True)

            class Meta:
                type_ = 'authors'
                strict = True

        field = Relationship(
            include_resource_linkage=True,
            type_='authors',
            schema=AuthorSchema,
        )

        result = field.deserialize({'data': {'type': 'authors', 'id': '1'}})

        assert result == 1
Пример #32
0
 def test_deserialize_many_non_list_relationship(self):
     field = Relationship(many=True, include_data=True, type_='comments')
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({'data': '1'})
     assert excinfo.value.args[0] == 'Relationship is list-like'
Пример #33
0
 def test_deserialize_non_many_list_relationship(self):
     field = Relationship(many=False, include_resource_linkage=True, type_='comments')
     with pytest.raises(ValidationError) as excinfo:
         field.deserialize({'data': ['1']})
     assert excinfo.value.args[0] == 'Relationship is not list-like'