class Parameters(object): """ Class that holds all parameter schemas """ api_key = Field( 'api-key', location='query', required=True, schema=String(description='API KEY for access healthsites api.'), ) page = Field( 'page', location='query', required=True, schema=Integer( description='A page number within the paginated result set.'), ) extent = Field( 'extent', location='query', required=False, schema=String( description='Extent of map that is used for filtering data. ' '(format: minLng, minLat, maxLng, maxLat)'), ) timestamp_from = Field( 'from', location='query', required=False, schema=Integer( description='Get latest modified data from this timestamp.'), ) timestamp_to = Field( 'to', location='query', required=False, schema=Integer( description='Get latest modified data from this timestamp.'), ) country = Field( 'country', location='query', required=False, schema=String(description='Filter by country'), ) output = Field( 'output', location='query', required=False, schema=String( description= 'Output format for the request. (json/xml/geojson, default: json)' ), )
def test_array_additional_items_disallowed(): schema = Array(items=[String(), Integer()]) assert schema.validate(['a', 123, True]) == [] schema = Array(items=[String(), Integer()], additional_items=False) assert schema.validate(['a', 123, True]) == [('Must have no more than 2 items.', [])] schema = Array(items=[String(), Integer()], additional_items=Integer()) assert schema.validate(['a', 123, 'c']) == [('Must be an integer.', [2])]
def test_intersection_of_intersections(): # validate will never succeed in this case. schema = (Integer() & String()) & Boolean() assert schema.validate('abc') == [('Must be an integer.', []), ('Must be a boolean.', [])] assert schema.validate(123) == [('Must be a string.', []), ('Must be a boolean.', [])]
def test_intersection_of_type_restrictions(): schema = Integer(multiple_of=3) & Integer(multiple_of=5) assert schema.validate(2) == [('Must be a multiple of 3.', []), ('Must be a multiple of 5.', [])] assert schema.validate(3) == [('Must be a multiple of 5.', [])] assert schema.validate(5) == [('Must be a multiple of 3.', [])] assert schema.validate(15) == []
def test_union_of_unions(): schema = (Integer() | String()) | Boolean() assert schema.validate('abc') == [] assert schema.validate(123) == [] assert schema.validate(True) == [] assert schema.validate({}) == [('Must match one of the options.', [])] schema = Integer() | (String() | Boolean()) assert schema.validate('abc') == [] assert schema.validate(123) == [] assert schema.validate(True) == [] assert schema.validate({}) == [('Must match one of the options.', [])]
def test_xor_of_types(): schema = Integer() ^ String() assert schema.validate('abc') == [] assert schema.validate(123) == [] assert schema.validate(True) == [('Must match one of the options.', [])]
def test_xor_of_type_restrictions(): schema = Integer(multiple_of=3) ^ Integer(multiple_of=5) assert schema.validate(2) == [('Must match one of the options.', [])] assert schema.validate(3) == [] assert schema.validate(5) == [] assert schema.validate(15) == [('Must match only one of the options.', [])]
def test_complex_not(): schema = Integer() & (~Integer(multiple_of=3) & ~Integer(multiple_of=5)) assert schema.validate('') == [('Must be an integer.', [])] assert schema.validate(2) == [] assert schema.validate(3) == [('Must not match the option.', [])] assert schema.validate(5) == [('Must not match the option.', [])]
def test_not(): schema = ~Integer() assert schema.validate('abc') == [] assert schema.validate(123) == [('Must not match the option.', [])]
def test_integer_type(): schema = Integer() assert schema.validate(1) == [] assert schema.validate(1.0) == [] assert schema.validate(1.5) == [('Must be an integer.', [])] assert schema.validate(True) == [('Must be an integer.', [])]
def test_array_items_as_list(): schema = Array(items=[String(), Integer()]) assert schema.validate([]) == [] assert schema.validate(['a', 123]) == [] assert schema.validate(['a', 'b']) == [('Must be an integer.', [1])]