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