Skip to content

Commit 3a7b835

Browse files
authored
Fix config validation for OGC Processes connection field (#2159)
* fix validation issue * fix validation issue * Update formatting
1 parent e65c6f2 commit 3a7b835

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

pygeoapi/resources/schemas/config/pygeoapi-config-0.x.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$schema: https://json-schema.org/draft/2020-12/schema
2-
$id: https://raw.githubusercontent.com/geopython/pygeoapi/master/pygeoapi/schemas/config/pygeoapi-config-0.x.yml
2+
$id: https://raw.githubusercontent.com/geopython/pygeoapi/refs/heads/master/pygeoapi/resources/schemas/config/pygeoapi-config-0.x.yml
33
title: pygeoapi configuration schema
44
description: pygeoapi configuration schema
55

@@ -132,7 +132,9 @@ properties:
132132
type: string
133133
description: plugin name (see `pygeoapi.plugin` for supported process_managers)
134134
connection:
135-
type: string
135+
type:
136+
- string
137+
- object
136138
description: connection info to store jobs (e.g. filepath)
137139
output_dir:
138140
type: string

tests/other/test_config.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,39 @@ def test_validate_config(config):
9999
}
100100
with pytest.raises(ValidationError):
101101
validate_config(cfg_copy)
102+
103+
104+
def test_validate_config_process_manager(config):
105+
"""
106+
Test that the process manager config can be validated
107+
as both a string or an object (i.e. PostgreSQL or TinyDB)
108+
"""
109+
cfg_copy = deepcopy(config)
110+
cfg_copy['server']['manager'] = {
111+
'name': 'TinyDB',
112+
'connection': '/tmp/pygeoapi_test.db',
113+
'output_dir': '/tmp/'
114+
}
115+
assert validate_config(cfg_copy)
116+
117+
with pytest.raises(ValidationError):
118+
# make sure an int is validated as invalid
119+
cfg_copy['server']['manager'] = {
120+
'name': 'TinyDB',
121+
'connection': 12345,
122+
'output_dir': '/tmp/'
123+
}
124+
validate_config(cfg_copy)
125+
126+
cfg_copy['server']['manager'] = {
127+
'name': 'PostgreSQL',
128+
'connection': {
129+
'host': 'localhost',
130+
'port': 5432,
131+
'database': 'pygeoapi',
132+
'user': 'pygeoapi',
133+
'password': 'pygeoapi'
134+
},
135+
'output_dir': '/tmp/'
136+
}
137+
assert validate_config(cfg_copy)

0 commit comments

Comments
 (0)