diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ddc78a..fb55ea5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,9 +75,7 @@ jobs: with: mongodb-version: 4.4 - name: Install and run SensorThingsAPI - run: | - wget https://raw.githubusercontent.com/webb-ben/data/main/docker-compose.yaml - docker-compose up -d + uses: cgs-earth/sensorthings-action@v0.0.2 - name: Install requirements 📦 run: | pip3 install -r requirements.txt @@ -93,7 +91,6 @@ jobs: python3 tests/load_es_data.py tests/cite/ogcapi-features/canada-hydat-daily-mean-02HC003.geojson IDENTIFIER python3 tests/load_mongo_data.py tests/data/ne_110m_populated_places_simple.geojson gunzip < tests/data/hotosm_bdi_waterways.sql.gz | psql postgresql://postgres:${{ secrets.DatabasePassword || 'postgres' }}@localhost:5432/test - python3 tests/load_sta_data.py tests/data/sta_iow_datastreams.json - name: run unit tests ⚙️ env: POSTGRESQL_PASSWORD: ${{ secrets.DatabasePassword || 'postgres' }} diff --git a/tests/load_sta_data.py b/tests/load_sta_data.py deleted file mode 100644 index 397e3c3..0000000 --- a/tests/load_sta_data.py +++ /dev/null @@ -1,73 +0,0 @@ -# ================================================================= -# -# Authors: Benjamin Webb -# Authors: Tom Kralidis -# -# Copyright (c) 2021 Benjamin Webb -# Copyright (c) 2022 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. -# -# ================================================================= - -from pathlib import Path -import requests -import sys -import json - -url = 'http://localhost:8080/FROST-Server/v1.1/Datastreams' -data_url = 'https://raw.githubusercontent.com/webb-ben/data/main/' - - -def main(path_: Path): - filename = path_.name - r = requests.get(f'{data_url}{filename}') - data = r.json().get('value') - for v in data: - clean(v) - requests.post(url, json.dumps(v)) - print(f"Added {len(requests.get(url).json()['value'])} entities") - - -def clean(dirty_dict): - if isinstance(dirty_dict, dict): - keys = [] - for (k, v) in dirty_dict.items(): - if '@' in k and k != '@iot.id': - keys.append(k) - elif isinstance(v, dict): - clean(v) - elif isinstance(v, list): - for _v in v: - if isinstance(_v, dict): - clean(_v) - - for k in keys: - dirty_dict.pop(k) - - -if __name__ == "__main__": - if len(sys.argv) == 1: - print(f'Usage: {sys.argv[0]} ') - sys.exit(1) - - main(Path(sys.argv[1])) diff --git a/tests/test_sensorthings_provider.py b/tests/test_sensorthings_provider.py index 046decf..a221efb 100644 --- a/tests/test_sensorthings_provider.py +++ b/tests/test_sensorthings_provider.py @@ -1,8 +1,8 @@ # ================================================================= # -# Authors: Benjamin Webb +# Authors: Benjamin Webb # -# Copyright (c) 2021 Benjamin Webb +# Copyright (c) 2022 Benjamin Webb # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation @@ -37,7 +37,7 @@ def config(): return { 'name': 'SensorThings', 'type': 'feature', - 'data': 'http://localhost:8080/FROST-Server/v1.1/', + 'data': 'http://localhost:8888/FROST-Server/v1.1/', 'rel_link': 'http://localhost:5000', 'entity': 'Datastreams', 'intralink': True, @@ -47,7 +47,6 @@ def config(): def test_query_datastreams(config): p = SensorThingsProvider(config) - fields = p.get_fields() assert len(fields) == 15 assert fields['Thing']['type'] == 'number' @@ -58,23 +57,23 @@ def test_query_datastreams(config): results = p.query() assert len(results['features']) == 10 assert results['numberReturned'] == 10 - assert len(results['features'][0]['properties']['Observations']) == 18 + assert len(results['features'][0]['properties']['Observations']) == 17 - assert results['features'][0]['geometry']['coordinates'][0] == -105.581 - assert results['features'][0]['geometry']['coordinates'][1] == 36.713 + assert results['features'][0]['geometry']['coordinates'][0] == -108.7483 + assert results['features'][0]['geometry']['coordinates'][1] == 35.6711 results = p.query(limit=1) assert len(results['features']) == 1 - assert results['features'][0]['id'] == '9' + assert results['features'][0]['id'] == '1' results = p.query(offset=2, limit=1) assert len(results['features']) == 1 - assert results['features'][0]['id'] == '11' + assert results['features'][0]['id'] == '3' assert len(results['features'][0]['properties']) == 17 results = p.query(bbox=[-109, 36, -106, 37]) - assert results['numberReturned'] == 2 + assert results['numberReturned'] == 8 results = p.query(select_properties=['Thing']) assert len(results['features'][0]['properties']) == 1 @@ -93,13 +92,13 @@ def test_query_observations(config): p = SensorThingsProvider(config) results = p.query(limit=10, resulttype='hits') - assert results['numberMatched'] == 2752 + assert results['numberMatched'] == 5298 r = p.query(bbox=[-109, 36, -106, 37], resulttype='hits') - assert r['numberMatched'] == 44 + assert r['numberMatched'] == 222 results = p.query(limit=10001, resulttype='hits') - assert results['numberMatched'] == 2752 + assert results['numberMatched'] == 5298 results = p.query(properties=[('result', 7475), ]) assert results['features'][0]['properties']['result'] == 7475 @@ -109,11 +108,11 @@ def test_query_observations(config): results = p.query(sortby=[{'property': 'phenomenonTime', 'order': '+'}]) assert results['features'][0]['properties'][ - 'phenomenonTime'] == '1944-10-14T12:00:00.000Z' + 'phenomenonTime'] == '1944-10-14T12:00:00Z' results = p.query(sortby=[{'property': 'phenomenonTime', 'order': '-'}]) assert results['features'][0]['properties'][ - 'phenomenonTime'] == '2021-02-09T15:55:01.000Z' + 'phenomenonTime'] == '2021-02-09T15:55:01Z' results = p.query(sortby=[{'property': 'result', 'order': '+'}]) assert results['features'][0]['properties']['result'] == 0.0091 @@ -121,15 +120,15 @@ def test_query_observations(config): results = p.query(sortby=[{'property': 'result', 'order': '-'}]) assert results['features'][0]['properties']['result'] == 7476 - results = p.query(datetime_='../2000-01-01T00:00:00.00Z', + results = p.query(datetime_='../2000-01-01T00:00:00Z', sortby=[{'property': 'phenomenonTime', 'order': '-'}]) assert results['features'][0]['properties'][ - 'phenomenonTime'] == '1999-10-15T17:45:00.000Z' + 'phenomenonTime'] == '1999-12-29T00:00:00Z' results = p.query(datetime_='2000-01-01T00:00:00.00Z/..', sortby=[{'property': 'phenomenonTime', 'order': '+'}]) assert results['features'][0]['properties'][ - 'phenomenonTime'] == '2000-02-07T22:45:00.000Z' + 'phenomenonTime'] == '2000-02-07T22:45:00Z' def test_get(config):