Skip to content

Commit 51d165b

Browse files
committed
fix: move count to base provider
This work has been done to move count to the base provider. While doing this work I also added a debug log message to state when the count had been disabled in the SQL provider. Also, I removed some tests that were no longer needed after the introduction of the str2bool function, when getting the count value from the configuration file.
1 parent cc12eed commit 51d165b

File tree

3 files changed

+8
-37
lines changed

3 files changed

+8
-37
lines changed

pygeoapi/provider/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def __init__(self, provider_def):
5757
:returns: pygeoapi.provider.base.BaseProvider
5858
"""
5959

60+
from pygeoapi.util import str2bool
61+
6062
try:
6163
self.name = provider_def['name']
6264
self.type = provider_def['type']
@@ -65,6 +67,7 @@ def __init__(self, provider_def):
6567
raise RuntimeError('name/type/data are required')
6668

6769
self.editable = provider_def.get('editable', False)
70+
self.count = str2bool(provider_def.get('count', 'true'))
6871
self.options = provider_def.get('options')
6972
self.id_field = provider_def.get('id_field')
7073
self.uri_field = provider_def.get('uri_field')

pygeoapi/provider/sql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def __init__(
128128
self.id_field = provider_def['id_field']
129129
self.geom = provider_def.get('geom_field', 'geom')
130130
self.driver_name = driver_name
131-
self.count = str(provider_def.get('count', 'true')).lower() == 'true'
132131

133132
LOGGER.debug(f'Name: {self.name}')
134133
LOGGER.debug(f'Table: {self.table}')
@@ -225,6 +224,8 @@ def query(
225224
matched = results.count()
226225
response['numberMatched'] = matched
227226
LOGGER.debug(f'Found {matched} result(s)')
227+
else:
228+
LOGGER.debug('Count disabled')
228229

229230
if resulttype == 'hits' or not results:
230231
return response

tests/provider/test_postgresql_provider.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def config():
8585
},
8686
'id_field': 'osm_id',
8787
'table': 'hotosm_bdi_waterways',
88-
'geom_field': 'foo_geom',
89-
'count': 'true'
88+
'geom_field': 'foo_geom'
9089
}
9190

9291

@@ -922,29 +921,9 @@ def test_provider_count_default_value(config):
922921
assert results['numberMatched'] == 14776
923922

924923

925-
@pytest.mark.parametrize("count_value", [
926-
('true'),
927-
('TRUE')
928-
])
929-
def test_provider_count_true(config, count_value):
930-
# Arrange
931-
config['count'] = count_value
932-
provider = PostgreSQLProvider(config)
933-
934-
# Act
935-
results = provider.query()
936-
937-
# Assert
938-
assert results['numberMatched'] == 14776
939-
940-
941-
@pytest.mark.parametrize("count_value", [
942-
('false'),
943-
('FALSE')
944-
])
945-
def test_provider_count_false(config, count_value):
924+
def test_provider_count_false(config):
946925
# Arrange
947-
config['count'] = count_value
926+
config['count'] = 'false'
948927
provider = PostgreSQLProvider(config)
949928

950929
# Act
@@ -964,15 +943,3 @@ def test_provider_count_false_with_resulttype_hits(config):
964943

965944
# Assert
966945
assert results['numberMatched'] == 14776
967-
968-
969-
def test_provider_count_number_string(config):
970-
# Arrange
971-
config['count'] = '1'
972-
provider = PostgreSQLProvider(config)
973-
974-
# Act
975-
results = provider.query()
976-
977-
# Assert
978-
assert 'numberMatched' not in results

0 commit comments

Comments
 (0)