Skip to content

Commit

Permalink
fix: Add AOI for testing, add test case for SQL and JOSN output
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Sep 6, 2023
1 parent 9071f27 commit 846ce94
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/AOI.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "FeatureCollection",
"name": "AOI",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "Name": null, "descriptio": null, "timestamp": null, "begin": null, "end": null, "altitudeMo": null, "tessellate": -1, "extrude": 0, "visibility": -1, "drawOrder": null, "icon": null, "id": 1.0, "StudyZone": "1" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 29.626306465742701, -1.62394262192732 ], [ 29.627355727523963, -1.6150820934917 ], [ 29.627375950252805, -1.60207887883816 ], [ 29.630793591429246, -1.59255397354762 ], [ 29.631003402241028, -1.589705096620216 ], [ 29.632156097785742, -1.589553426153807 ], [ 29.63302567512649, -1.590079217104027 ], [ 29.633425074021368, -1.590306722803642 ], [ 29.63420870476449, -1.590433114858984 ], [ 29.634289595679878, -1.590984184220273 ], [ 29.635659685559776, -1.591535253581562 ], [ 29.636711267460207, -1.590584785325394 ], [ 29.636974162935328, -1.588077166947417 ], [ 29.638045967564626, -1.585620105391577 ], [ 29.638844765354385, -1.584265182558315 ], [ 29.639893819413825, -1.583372854647607 ], [ 29.641878174682518, -1.581097797651455 ], [ 29.643940893025693, -1.581502252228548 ], [ 29.645477820418645, -1.583362743283176 ], [ 29.647419202388694, -1.584131206979652 ], [ 29.652414216415796, -1.583726752402559 ], [ 29.653314127849828, -1.585476018448487 ], [ 29.652181655034006, -1.586669159450911 ], [ 29.647773100143688, -1.587174727672278 ], [ 29.642907006013168, -1.585920918483293 ], [ 29.639630923938718, -1.590026132440788 ], [ 29.63779065561295, -1.59312020995555 ], [ 29.637285087391586, -1.596942305709079 ], [ 29.635970610016031, -1.597690546676701 ], [ 29.63750753740899, -1.60064306508948 ], [ 29.63530325996383, -1.607013224678695 ], [ 29.633827000757442, -1.616558352698089 ], [ 29.634499406491933, -1.623803145310269 ], [ 29.634115174643693, -1.629121722999042 ], [ 29.636157670258012, -1.632054018682966 ], [ 29.633650051880036, -1.639131973782094 ], [ 29.634691522416055, -1.643095628637605 ], [ 29.634529740585211, -1.649748906430785 ], [ 29.636713795301514, -1.653024988505238 ], [ 29.638978740933226, -1.658282898007447 ], [ 29.640596559241605, -1.672964599155923 ], [ 29.640030322833674, -1.683116409040957 ], [ 29.637502481726838, -1.69221663702555 ], [ 29.637178918065164, -1.694845591776654 ], [ 29.634347736025514, -1.695128709980619 ], [ 29.632740029081557, -1.697019535128528 ], [ 29.632861365454687, -1.697777887460578 ], [ 29.632810808632549, -1.698799135267737 ], [ 29.634216288287945, -1.699335037582385 ], [ 29.634686466733804, -1.699805216028256 ], [ 29.634716800827086, -1.700563568360305 ], [ 29.634474128080832, -1.701079247946098 ], [ 29.635030253124324, -1.706418048363726 ], [ 29.634605575818377, -1.708602103080028 ], [ 29.634605575818377, -1.709936803184435 ], [ 29.635272925870577, -1.711332171475406 ], [ 29.634898805386765, -1.714031905777501 ], [ 29.636031278202626, -1.716943978732571 ], [ 29.63586696853061, -1.719390928923981 ], [ 29.637970132331493, -1.720280728993586 ], [ 29.638859932401097, -1.722505229167597 ], [ 29.636635432227084, -1.722626565540725 ], [ 29.634451377510782, -1.723880374729714 ], [ 29.633359350152631, -1.725619529411213 ], [ 29.631458413640296, -1.725093738460993 ], [ 29.630002377162761, -1.726428438565399 ], [ 29.627818322446458, -1.726752002227074 ], [ 29.626968967834564, -1.726307102192272 ], [ 29.626443176884344, -1.725053293003283 ], [ 29.628869904346899, -1.722667010998435 ], [ 29.630773368700417, -1.718925806160326 ], [ 29.629335027110525, -1.707328071162181 ], [ 29.629456363483655, -1.702595952610193 ], [ 29.630123713535863, -1.691979019961502 ], [ 29.631842645488508, -1.690179197093439 ], [ 29.629840595331896, -1.683424805655986 ], [ 29.624582685829687, -1.671210277427777 ], [ 29.626766740545989, -1.657620603637453 ], [ 29.626685849630579, -1.652484030508372 ], [ 29.628098580278301, -1.64137211766171 ], [ 29.627994969165002, -1.63053200945648 ], [ 29.626306465742701, -1.62394262192732 ] ] ] ] } }
]
}
58 changes: 58 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/python3

# Copyright (c) 2023 Humanitarian OpenStreetMap Team
#
# This file is part of osm_fieldwork.
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Underpass is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with osm_fieldwork. If not, see <https:#www.gnu.org/licenses/>.
#

import os
import sys
from osm_rawdata.postgres import DatabaseAccess
import geojson
from osm_rawdata.config import QueryConfig


# Find the other files for this project
import osm_rawdata as rw
rootdir = rw.__path__[0]
if os.path.basename(rootdir) == 'osm_rawdata':
rootdir = f"./tests/"


def test_yaml():
hits = 0
db = DatabaseAccess('underpass')
infile = open(f"{rootdir}/AOI.geojson", 'r')
poly = geojson.load(infile)
qc = QueryConfig()
result = qc.parseYaml(f"{rootdir}/buildings.yaml")
sql = db.createSQL(qc, True)
out = "SELECT ST_AsText(geom), osm_id, version, tags->>'building', tags->>'amenity', tags->>'building:material', tags->>'roof:material' FROM nodes WHERE tags->>'building' ='yes' OR tags->>'amenity' ='not null' OR tags->>'building:material' ='wood' AND tags->>'roof:material' ='metal'"
if sql[0] == out:
hits += 1

json = db.createJson(qc, True)
out = '{"geometry": true, "geometryType": ["point", "polygon"], "filters": {"tags": {"point": {"join_or": {"building": ["yes"], "amenity": ["not null"], "building:material": ["wood"], "roof:material": ["metal"]}, "join_and": {"building": ["yes"], "amenity": ["not null"], "building:material": ["wood"], "roof:material": ["metal"]}}, "polygon": {"join_or": {"building": ["yes"], "amenity": ["not null"], "building:material": ["wood"], "roof:material": ["metal"]}, "join_and": {"building": ["yes"], "amenity": ["not null"], "building:material": ["wood"], "roof:material": ["metal"]}}, "line": {"join_or": {}, "join_and": {}}}}}'
if json == out:
hits += 1

assert hits == 2

if __name__ == "__main__":
print("--- test_yaml() ---")
test_yaml()


0 comments on commit 846ce94

Please sign in to comment.