def test_no_id_field_specified(self, app):
     parser = query_string.SparseFieldsParser(schema=ParentSchema)
     with pytest.raises(ValueError):
         with app.test_request_context(
                 '/parents/?fields[parents]=no_id_field'):
             sparse_fields = parser.parse()
             ParentSchema(strict=True, many=True, only=sparse_fields)
Exemplo n.º 2
0
 def test_invalid_field(self, app):
     parser = query_string.SparseFieldsParser(schema=ParentSchema)
     objects_list = ParentDetailRepository().get_detail('1234')
     with pytest.raises(ValueError):
         with app.test_request_context('/parents/?fields[parents]=id,bad_field'):
             sparse_fields = parser.parse()
             ParentSchema(many=True, only=sparse_fields).dump(objects_list)
Exemplo n.º 3
0
 def __init__(self, *, schema=None):
     if schema:
         self.schema = schema
     self.sort_parser = query_string.SortParser(schema=self.schema)
     self.include_parser = query_string.IncludeParser(schema=self.schema)
     self.sparse_fields_parser = query_string.SparseFieldsParser(
         schema=self.schema)
 def test_no_brackets(self, app):
     parser = query_string.SparseFieldsParser(schema=ParentSchema)
     with pytest.raises(exceptions.InvalidField):
         with app.test_request_context('/parents/?fields[parents=id,ha$h'):
             parser.parse()
 def test_bad_resource(self, app):
     parser = query_string.SparseFieldsParser(schema=ParentSchema)
     with pytest.raises(exceptions.InvalidField):
         with app.test_request_context(
                 '/parents/?fields[par]ents]=no_id_field'):
             parser.parse()
 def test_invalid_type(self, app):
     parser = query_string.SparseFieldsParser(schema=ParentSchema)
     with pytest.raises(KeyError):
         with app.test_request_context('/parents/?fields[bad-type]=id'):
             sparse_fields = parser.parse()
             ParentSchema(strict=True, many=True, only=sparse_fields)
 def test_parse(self, app):
     parser = query_string.SparseFieldsParser(schema=ParentSchema)
     with app.test_request_context(
             '/examples/?fields[parents]=id,name&fields[children]=name'):
         result = parser.parse()
         assert sorted(result) == ['children.name', 'id', 'name']