From 9e2b5d20b033678d8d4c46b747043868e841fcfe Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 29 Apr 2018 09:15:34 -0400 Subject: [PATCH] add tests for ES backend (#38) --- .travis.yml | 1 + ..._csv_provider.py => test_csv__provider.py} | 0 tests/test_elastisearch__provider.py | 67 +++++++++++++++++++ 3 files changed, 68 insertions(+) rename tests/{test_csv_provider.py => test_csv__provider.py} (100%) create mode 100644 tests/test_elastisearch__provider.py diff --git a/.travis.yml b/.travis.yml index d873f6b..936d971 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: python dist: xenial +sudo: false python: - "3.5" diff --git a/tests/test_csv_provider.py b/tests/test_csv__provider.py similarity index 100% rename from tests/test_csv_provider.py rename to tests/test_csv__provider.py diff --git a/tests/test_elastisearch__provider.py b/tests/test_elastisearch__provider.py new file mode 100644 index 0000000..cb54da4 --- /dev/null +++ b/tests/test_elastisearch__provider.py @@ -0,0 +1,67 @@ +# ================================================================= +# +# Authors: Tom Kralidis +# +# Copyright (c) 2018 Tom Kralidis +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# ================================================================= + +import pytest + +from pygeoapi.provider.elasticsearch_ import ElasticsearchProvider + + +@pytest.fixture() +def config(): + return { + 'name': 'Elasticsearch', + 'data': 'http://localhost:9200/ne_110m_populated_places_simple/FeatureCollection', # noqa + 'id_field': 'geonameid' + } + + +def test_query(config): + p = ElasticsearchProvider(config) + results = p.query() + assert len(results['features']) == 10 + assert results['features'][0]['ID'] == 6691831 + assert results['features'][0]['properties']['nameascii'] == 'Vatican City' + + results = p.query(limit=1) + assert len(results['features']) == 1 + assert results['features'][0]['ID'] == 6691831 + + results = p.query(startindex=2, limit=1) + assert len(results['features']) == 1 + assert results['features'][0]['ID'] == 1559804 + + +def test_get(config): + p = ElasticsearchProvider(config) + results = p.get('404') + assert results is None + + result = p.get('3413829') + assert result['ID'] == 3413829 + assert result['properties']['ls_name'] == 'Reykjavik'