Skip to content

Commit 3f15542

Browse files
authored
Fix visibility hidden edge case (#2330)
1 parent 23e36b3 commit 3f15542

3 files changed

Lines changed: 221 additions & 1 deletion

File tree

pygeoapi/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,8 @@ def describe_collections(api: API, request: APIRequest,
944944

945945
LOGGER.debug('Creating collections')
946946
for k, v in collections_dict.items():
947-
if v.get('visibility', 'default') == 'hidden':
947+
if v.get('visibility', 'default') == 'hidden' \
948+
and dataset is None:
948949
LOGGER.debug(f'Skipping hidden layer: {k}')
949950
continue
950951

tests/api/test_api.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def config_hidden_resources():
7979
return yaml_load(fh)
8080

8181

82+
@pytest.fixture()
83+
def config_exclusively_hidden_resources():
84+
filename = 'pygeoapi-test-config-exclusively-hidden-resources.yml'
85+
with open(get_test_file_path(filename)) as fh:
86+
return yaml_load(fh)
87+
88+
8289
@pytest.fixture()
8390
def config_failing_collection():
8491
filename = 'pygeoapi-test-config-failing-collection.yml'
@@ -105,6 +112,12 @@ def api_hidden_resources(config_hidden_resources, openapi):
105112
return API(config_hidden_resources, openapi)
106113

107114

115+
@pytest.fixture()
116+
def api_exclusively_hidden_resources(config_exclusively_hidden_resources, openapi): # noqa
117+
'''Returns an API instance where all resources are marked as hidden'''
118+
return API(config_exclusively_hidden_resources, openapi)
119+
120+
108121
@pytest.fixture()
109122
def api_failing_collection(config_failing_collection, openapi):
110123
return API(config_failing_collection, openapi)
@@ -747,6 +760,32 @@ def test_describe_collections_hidden_resources(
747760
assert len(collections['collections']) == 1
748761

749762

763+
def test_describe_collections_with_only_hidden_resources(
764+
api_exclusively_hidden_resources
765+
):
766+
'''
767+
Test an API with only hidden resources to ensure
768+
there are no indexing errors when no collections are returned
769+
'''
770+
req = mock_api_request({})
771+
_, code, response = describe_collections(api_exclusively_hidden_resources, req) # noqa
772+
assert code == HTTPStatus.OK
773+
774+
collections = json.loads(response)
775+
assert len(collections['collections']) == 0, \
776+
'All collections are hidden so there should be none in the response'
777+
778+
hidden_collection_name = 'objects'
779+
_, code, response = describe_collections(
780+
api_exclusively_hidden_resources, req, hidden_collection_name
781+
)
782+
783+
assert code == HTTPStatus.OK
784+
collection = json.loads(response)
785+
assert collection['title'] == 'GeoJSON objects', \
786+
'The collection should have its normal title even if hidden'
787+
788+
750789
def test_describe_collections_failing_collection(
751790
config_failing_collection, api_failing_collection):
752791
req = mock_api_request({})
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# =================================================================
2+
#
3+
# Authors: Tom Kralidis <tomkralidis@gmail.com>
4+
#
5+
# Copyright (c) 2019 Tom Kralidis
6+
#
7+
# Permission is hereby granted, free of charge, to any person
8+
# obtaining a copy of this software and associated documentation
9+
# files (the "Software"), to deal in the Software without
10+
# restriction, including without limitation the rights to use,
11+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
# copies of the Software, and to permit persons to whom the
13+
# Software is furnished to do so, subject to the following
14+
# conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be
17+
# included in all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26+
# OTHER DEALINGS IN THE SOFTWARE.
27+
#
28+
# =================================================================
29+
30+
server:
31+
bind:
32+
host: 0.0.0.0
33+
port: 5000
34+
url: http://localhost:5000/
35+
mimetype: application/json; charset=UTF-8
36+
encoding: utf-8
37+
gzip: false
38+
languages:
39+
# First language is the default language
40+
- en-US
41+
- fr-CA
42+
cors: true
43+
pretty_print: true
44+
limits:
45+
default_items: 10
46+
max_items: 10
47+
# templates: /path/to/templates
48+
map:
49+
url: https://tile.openstreetmap.org/{z}/{x}/{y}.png
50+
attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
51+
manager:
52+
name: TinyDB
53+
connection: /tmp/pygeoapi-test-process-manager.db
54+
output_dir: /tmp
55+
56+
logging:
57+
level: DEBUG
58+
#logfile: /tmp/pygeoapi.log
59+
60+
metadata:
61+
identification:
62+
title:
63+
en: pygeoapi default instance
64+
fr: instance par défaut de pygeoapi
65+
description:
66+
en: pygeoapi provides an API to geospatial data
67+
fr: pygeoapi fournit une API aux données géospatiales
68+
keywords:
69+
en:
70+
- geospatial
71+
- data
72+
- api
73+
fr:
74+
- géospatiale
75+
- données
76+
- api
77+
keywords_type: theme
78+
terms_of_service: https://creativecommons.org/licenses/by/4.0/
79+
url: http://example.org
80+
license:
81+
name: CC-BY 4.0 license
82+
url: https://creativecommons.org/licenses/by/4.0/
83+
provider:
84+
name: Organization Name
85+
url: https://pygeoapi.io
86+
contact:
87+
name: Lastname, Firstname
88+
position: Position Title
89+
address: Mailing Address
90+
city: City
91+
stateorprovince: Administrative Area
92+
postalcode: Zip or Postal Code
93+
country: Country
94+
phone: +xx-xxx-xxx-xxxx
95+
fax: +xx-xxx-xxx-xxxx
96+
email: you@example.org
97+
url: Contact URL
98+
hours: Hours of Service
99+
instructions: During hours of service. Off on weekends.
100+
role: pointOfContact
101+
102+
resources:
103+
obs:
104+
type: collection
105+
visibility: hidden
106+
title:
107+
en: Observations
108+
fr: Observations
109+
description:
110+
en: My cool observations
111+
fr: Mes belles observations
112+
keywords:
113+
- observations
114+
- monitoring
115+
links:
116+
- type: text/csv
117+
rel: canonical
118+
title: data
119+
href: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv
120+
hreflang: en-US
121+
- type: text/csv
122+
rel: alternate
123+
title: data
124+
href: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv
125+
hreflang: en-US
126+
linked-data:
127+
context:
128+
- schema: https://schema.org/
129+
stn_id:
130+
"@id": schema:identifier
131+
"@type": schema:Text
132+
datetime:
133+
"@type": schema:DateTime
134+
"@id": schema:observationDate
135+
value:
136+
"@type": schema:Number
137+
"@id": schema:QuantitativeValue
138+
extents:
139+
spatial:
140+
bbox: [-180,-90,180,90]
141+
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
142+
temporal:
143+
begin: 2000-10-30T18:24:39Z
144+
end: 2007-10-30T08:57:29Z
145+
trs: http://www.opengis.net/def/uom/ISO-8601/0/Gregorian
146+
providers:
147+
- type: feature
148+
name: CSV
149+
data: tests/data/obs.csv
150+
id_field: id
151+
geometry:
152+
x_field: long
153+
y_field: lat
154+
155+
objects:
156+
type: collection
157+
title: GeoJSON objects
158+
visibility: hidden
159+
description: GeoJSON geometry types for GeoSparql and Schema Geometry conversion.
160+
keywords:
161+
- shapes
162+
links:
163+
- type: text/html
164+
rel: canonical
165+
title: data source
166+
href: https://en.wikipedia.org/wiki/GeoJSON
167+
hreflang: en-US
168+
extents:
169+
spatial:
170+
bbox: [-180,-90,180,90]
171+
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
172+
temporal:
173+
begin: null
174+
end: null # or empty (either means open ended)
175+
providers:
176+
- type: feature
177+
name: GeoJSON
178+
data: tests/data/items.geojson
179+
id_field: fid
180+
uri_field: uri

0 commit comments

Comments
 (0)