Skip to content

Commit

Permalink
test: for parsing query config with all_geometry set
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Feb 14, 2024
1 parent ff2aa3e commit 0615d18
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/all_geometry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select:
where:
tags:
- join_or:
- building:
highway:
waterway:
2 changes: 2 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,6 @@ def test_everything():
test_filters()
print("--- test_yaml_no_joins ---")
test_yaml_no_joins()
print("--- test_yaml_no_joins_bytesio ---")
test_yaml_no_joins_bytesio()
print("--- done() ---")
45 changes: 45 additions & 0 deletions tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
#
"""Tests for data extract generation."""

import json
import logging
import os
import time
from io import BytesIO

import geojson
import requests

import osm_rawdata as rw
from osm_rawdata.config import QueryConfig
from osm_rawdata.postgres import PostgresClient

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,3 +71,45 @@ def test_fgb_data_extract():
assert response.status_code == 200
assert response.headers["Content-Type"] == "binary/octet-stream"
assert response.headers["Content-Length"] == "10640"


def test_all_geometry():
"""Test using the all_geometry flag."""
expected_config = {
"select": {"nodes": [], "ways_poly": [], "ways_line": []},
"tables": [],
"where": {
"nodes": [{"building": [], "op": "or"}, {"highway": [], "op": "or"}, {"waterway": [], "op": "or"}],
"ways_poly": [{"building": [], "op": "or"}, {"highway": [], "op": "or"}, {"waterway": [], "op": "or"}],
"ways_line": [{"building": [], "op": "or"}, {"highway": [], "op": "or"}, {"waterway": [], "op": "or"}],
},
"keep": [],
}

# Test JSON
json_config = BytesIO(
json.dumps(
{
"filters": {"tags": {"all_geometry": {"join_or": {"building": [], "highway": [], "waterway": []}}}},
}
).encode()
)
json_config_parsed = QueryConfig().parseJson(json_config)
assert json_config_parsed == expected_config

pg = PostgresClient(
"underpass",
json_config,
)
assert pg.qc.config == expected_config

# Test YAML
yaml_config_parsed = QueryConfig().parseYaml(f"{rootdir}/all_geometry.yaml")
log.warning(yaml_config_parsed)
assert yaml_config_parsed == expected_config

pg = PostgresClient(
"underpass",
f"{rootdir}/all_geometry.yaml",
)
assert pg.qc.config == expected_config

0 comments on commit 0615d18

Please sign in to comment.