|
40 | 40 |
|
41 | 41 | from pygeoapi.api import (
|
42 | 42 | API, APIRequest, FORMAT_TYPES, F_HTML, F_JSON, F_JSONLD, F_GZIP,
|
43 |
| - __version__, validate_bbox, validate_datetime, evaluate_limit, |
44 |
| - validate_subset, landing_page, openapi_, conformance, describe_collections, |
45 |
| - get_collection_schema, |
| 43 | + __version__, validate_bbox, validate_filter_dims, validate_datetime, |
| 44 | + evaluate_limit, validate_subset, landing_page, openapi_, conformance, |
| 45 | + describe_collections, get_collection_schema, |
46 | 46 | )
|
47 | 47 | from pygeoapi.util import yaml_load, get_api_rules, get_base_url
|
48 | 48 |
|
@@ -778,6 +778,39 @@ def test_validate_bbox():
|
778 | 778 | validate_bbox('1,2,6,4,5,3')
|
779 | 779 |
|
780 | 780 |
|
| 781 | +def test_validate_filter_dims(): |
| 782 | + with pytest.raises(ValueError) as error: |
| 783 | + validate_filter_dims(123) |
| 784 | + assert error.type == ValueError |
| 785 | + assert error.match('dimension query must be string') |
| 786 | + |
| 787 | + assert validate_filter_dims('key1:val1') == {'key1': 'val1'} |
| 788 | + with pytest.raises(ValueError) as error: |
| 789 | + validate_filter_dims('key1val1') |
| 790 | + assert error.type == ValueError |
| 791 | + assert error.match("filter dimension and value must be separated by a colon ':' ") # noqa |
| 792 | + |
| 793 | + assert validate_filter_dims('key1:val1,key2:val2') == {'key1': 'val1', |
| 794 | + 'key2': 'val2'} |
| 795 | + with pytest.raises(ValueError) as error: |
| 796 | + validate_filter_dims('key1:val1,key1:val2') |
| 797 | + assert error.match("""Duplicate key found: 'key1'""") |
| 798 | + |
| 799 | + with pytest.raises(ValueError) as error: |
| 800 | + validate_filter_dims(':val1,key1:val2') |
| 801 | + assert error.match("Empty key or value in pair: ':val1'") |
| 802 | + |
| 803 | + with pytest.raises(ValueError) as error: |
| 804 | + validate_filter_dims('key1:,key1:val2') |
| 805 | + assert error.match("Empty key or value in pair: 'key1:'") |
| 806 | + |
| 807 | + with pytest.raises(ValueError) as error: |
| 808 | + validate_filter_dims('') |
| 809 | + assert error.match("filter dimension and value must be separated by a colon ':' ") # noqa |
| 810 | + |
| 811 | + assert validate_filter_dims(None) == {} |
| 812 | + |
| 813 | + |
781 | 814 | def test_validate_datetime():
|
782 | 815 | config = yaml_load('''
|
783 | 816 | temporal:
|
|
0 commit comments