[test] update test cases to handle input source as xyzservices.TileProvider
Browse files- events/payload_multiprompt_api_request_body.json +1 -1
- tests/events/get_parsed_bbox_prompts_multi_prompt.json +8 -2
- tests/events/get_parsed_bbox_prompts_single_point.json +30 -6
- tests/events/get_parsed_bbox_prompts_single_rectangle.json +8 -2
- tests/io/test_lambda_helpers.py +45 -7
- tests/io/test_tms2geotiff.py +51 -2
- tests/test_app.py +40 -17
events/payload_multiprompt_api_request_body.json
CHANGED
|
@@ -44,5 +44,5 @@
|
|
| 44 |
}
|
| 45 |
],
|
| 46 |
"zoom": 17,
|
| 47 |
-
"source_type": "OpenStreetMap"
|
| 48 |
}
|
|
|
|
| 44 |
}
|
| 45 |
],
|
| 46 |
"zoom": 17,
|
| 47 |
+
"source_type": "OpenStreetMap.Mapnik"
|
| 48 |
}
|
tests/events/get_parsed_bbox_prompts_multi_prompt.json
CHANGED
|
@@ -54,7 +54,7 @@
|
|
| 54 |
}
|
| 55 |
],
|
| 56 |
"zoom": 12,
|
| 57 |
-
"source_type": "OpenStreetMap"
|
| 58 |
},
|
| 59 |
"output": {
|
| 60 |
"bbox": [
|
|
@@ -102,7 +102,13 @@
|
|
| 102 |
]
|
| 103 |
}
|
| 104 |
],
|
| 105 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
"zoom": 12
|
| 107 |
}
|
| 108 |
}
|
|
|
|
| 54 |
}
|
| 55 |
],
|
| 56 |
"zoom": 12,
|
| 57 |
+
"source_type": "OpenStreetMap.Mapnik"
|
| 58 |
},
|
| 59 |
"output": {
|
| 60 |
"bbox": [
|
|
|
|
| 102 |
]
|
| 103 |
}
|
| 104 |
],
|
| 105 |
+
"source": {
|
| 106 |
+
"url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
| 107 |
+
"max_zoom": 19,
|
| 108 |
+
"html_attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
| 109 |
+
"attribution": "(C) OpenStreetMap contributors",
|
| 110 |
+
"name": "OpenStreetMap.Mapnik"
|
| 111 |
+
},
|
| 112 |
"zoom": 12
|
| 113 |
}
|
| 114 |
}
|
tests/events/get_parsed_bbox_prompts_single_point.json
CHANGED
|
@@ -48,7 +48,13 @@
|
|
| 48 |
"label": 0
|
| 49 |
}
|
| 50 |
],
|
| 51 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
"zoom": 10
|
| 53 |
}
|
| 54 |
},
|
|
@@ -100,7 +106,13 @@
|
|
| 100 |
"label": 0
|
| 101 |
}
|
| 102 |
],
|
| 103 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
"zoom": 7
|
| 105 |
}
|
| 106 |
},
|
|
@@ -128,7 +140,7 @@
|
|
| 128 |
}
|
| 129 |
],
|
| 130 |
"zoom": 4,
|
| 131 |
-
"source_type": "OpenStreetMap"
|
| 132 |
}
|
| 133 |
},
|
| 134 |
"output": {
|
|
@@ -152,7 +164,13 @@
|
|
| 152 |
"label": 0
|
| 153 |
}
|
| 154 |
],
|
| 155 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
"zoom": 4
|
| 157 |
}
|
| 158 |
},
|
|
@@ -180,7 +198,7 @@
|
|
| 180 |
}
|
| 181 |
],
|
| 182 |
"zoom": 7,
|
| 183 |
-
"source_type": "OpenStreetMap"
|
| 184 |
}
|
| 185 |
},
|
| 186 |
"output": {
|
|
@@ -204,7 +222,13 @@
|
|
| 204 |
"label": 0
|
| 205 |
}
|
| 206 |
],
|
| 207 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
"zoom": 7
|
| 209 |
}
|
| 210 |
}
|
|
|
|
| 48 |
"label": 0
|
| 49 |
}
|
| 50 |
],
|
| 51 |
+
"source": {
|
| 52 |
+
"url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
| 53 |
+
"max_zoom": 19,
|
| 54 |
+
"html_attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
| 55 |
+
"attribution": "(C) OpenStreetMap contributors",
|
| 56 |
+
"name": "OpenStreetMap.Mapnik"
|
| 57 |
+
},
|
| 58 |
"zoom": 10
|
| 59 |
}
|
| 60 |
},
|
|
|
|
| 106 |
"label": 0
|
| 107 |
}
|
| 108 |
],
|
| 109 |
+
"source": {
|
| 110 |
+
"url": "https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png",
|
| 111 |
+
"max_zoom": 19,
|
| 112 |
+
"html_attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, Tiles style by <a href=\"https://www.hotosm.org/\" target=\"_blank\">Humanitarian OpenStreetMap Team</a> hosted by <a href=\"https://openstreetmap.fr/\" target=\"_blank\">OpenStreetMap France</a>",
|
| 113 |
+
"attribution": "(C) OpenStreetMap contributors, Tiles style by Humanitarian OpenStreetMap Team hosted by OpenStreetMap France",
|
| 114 |
+
"name": "OpenStreetMap.HOT"
|
| 115 |
+
},
|
| 116 |
"zoom": 7
|
| 117 |
}
|
| 118 |
},
|
|
|
|
| 140 |
}
|
| 141 |
],
|
| 142 |
"zoom": 4,
|
| 143 |
+
"source_type": "OpenStreetMap.Mapnik"
|
| 144 |
}
|
| 145 |
},
|
| 146 |
"output": {
|
|
|
|
| 164 |
"label": 0
|
| 165 |
}
|
| 166 |
],
|
| 167 |
+
"source": {
|
| 168 |
+
"url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
| 169 |
+
"max_zoom": 19,
|
| 170 |
+
"html_attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
| 171 |
+
"attribution": "(C) OpenStreetMap contributors",
|
| 172 |
+
"name": "OpenStreetMap.Mapnik"
|
| 173 |
+
},
|
| 174 |
"zoom": 4
|
| 175 |
}
|
| 176 |
},
|
|
|
|
| 198 |
}
|
| 199 |
],
|
| 200 |
"zoom": 7,
|
| 201 |
+
"source_type": "OpenStreetMap.Mapnik"
|
| 202 |
}
|
| 203 |
},
|
| 204 |
"output": {
|
|
|
|
| 222 |
"label": 0
|
| 223 |
}
|
| 224 |
],
|
| 225 |
+
"source": {
|
| 226 |
+
"url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
| 227 |
+
"max_zoom": 19,
|
| 228 |
+
"html_attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
| 229 |
+
"attribution": "(C) OpenStreetMap contributors",
|
| 230 |
+
"name": "OpenStreetMap.Mapnik"
|
| 231 |
+
},
|
| 232 |
"zoom": 7
|
| 233 |
}
|
| 234 |
}
|
tests/events/get_parsed_bbox_prompts_single_rectangle.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
| 27 |
}
|
| 28 |
],
|
| 29 |
"zoom": 5,
|
| 30 |
-
"source_type": "OpenStreetMap"
|
| 31 |
},
|
| 32 |
"output": {
|
| 33 |
"bbox": [
|
|
@@ -51,7 +51,13 @@
|
|
| 51 |
"type": "rectangle"
|
| 52 |
}
|
| 53 |
],
|
| 54 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
"zoom": 5
|
| 56 |
}
|
| 57 |
}
|
|
|
|
| 27 |
}
|
| 28 |
],
|
| 29 |
"zoom": 5,
|
| 30 |
+
"source_type": "OpenStreetMap.Mapnik"
|
| 31 |
},
|
| 32 |
"output": {
|
| 33 |
"bbox": [
|
|
|
|
| 51 |
"type": "rectangle"
|
| 52 |
}
|
| 53 |
],
|
| 54 |
+
"source": {
|
| 55 |
+
"url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
| 56 |
+
"max_zoom": 19,
|
| 57 |
+
"html_attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
|
| 58 |
+
"attribution": "(C) OpenStreetMap contributors",
|
| 59 |
+
"name": "OpenStreetMap.Mapnik"
|
| 60 |
+
},
|
| 61 |
"zoom": 5
|
| 62 |
}
|
| 63 |
}
|
tests/io/test_lambda_helpers.py
CHANGED
|
@@ -2,6 +2,8 @@ import json
|
|
| 2 |
import time
|
| 3 |
from http import HTTPStatus
|
| 4 |
from unittest.mock import patch
|
|
|
|
|
|
|
| 5 |
from src.io.lambda_helpers import get_parsed_bbox_points, get_parsed_request_body, get_response
|
| 6 |
from src.utilities.type_hints import ApiRequestBody
|
| 7 |
from src.utilities import utilities
|
|
@@ -13,7 +15,7 @@ def test_get_response(time_mocked):
|
|
| 13 |
time_diff = 108
|
| 14 |
end_run = 1000
|
| 15 |
time_mocked.return_value = end_run
|
| 16 |
-
start_time = end_run-time_diff
|
| 17 |
aws_request_id = "test_invoke_id"
|
| 18 |
|
| 19 |
with open(TEST_EVENTS_FOLDER / "get_response.json") as tst_json:
|
|
@@ -64,7 +66,7 @@ def test_get_parsed_request_body():
|
|
| 64 |
"sw": {"lat": 37.455509218936974, "lng": 14.632807441554068}
|
| 65 |
},
|
| 66 |
"prompt": [{"type": "point", "data": {"lat": 37.0, "lng": 15.0}, "label": 0}],
|
| 67 |
-
"zoom": 10, "source_type": "
|
| 68 |
}
|
| 69 |
}
|
| 70 |
expected_output_dict = {
|
|
@@ -73,7 +75,7 @@ def test_get_parsed_request_body():
|
|
| 73 |
"sw": {"lat": 37.455509218936974, "lng": 14.632807441554068}
|
| 74 |
},
|
| 75 |
"prompt": [{"type": "point", "data": {"lat": 37.0, "lng": 15.0}, "label": 0}],
|
| 76 |
-
"zoom": 10, "source_type": "
|
| 77 |
}
|
| 78 |
output = get_parsed_request_body(input_event["event"])
|
| 79 |
assert output == ApiRequestBody.model_validate(input_event["event"])
|
|
@@ -87,9 +89,45 @@ def test_get_parsed_request_body():
|
|
| 87 |
assert output == ApiRequestBody.model_validate(expected_output_dict)
|
| 88 |
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
from src.io.lambda_helpers import get_url_tile
|
| 92 |
-
from src.utilities.constants import DEFAULT_TMS
|
| 93 |
|
| 94 |
-
assert get_url_tile("OpenStreetMap") ==
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import time
|
| 3 |
from http import HTTPStatus
|
| 4 |
from unittest.mock import patch
|
| 5 |
+
|
| 6 |
+
from src.io import lambda_helpers
|
| 7 |
from src.io.lambda_helpers import get_parsed_bbox_points, get_parsed_request_body, get_response
|
| 8 |
from src.utilities.type_hints import ApiRequestBody
|
| 9 |
from src.utilities import utilities
|
|
|
|
| 15 |
time_diff = 108
|
| 16 |
end_run = 1000
|
| 17 |
time_mocked.return_value = end_run
|
| 18 |
+
start_time = end_run - time_diff
|
| 19 |
aws_request_id = "test_invoke_id"
|
| 20 |
|
| 21 |
with open(TEST_EVENTS_FOLDER / "get_response.json") as tst_json:
|
|
|
|
| 66 |
"sw": {"lat": 37.455509218936974, "lng": 14.632807441554068}
|
| 67 |
},
|
| 68 |
"prompt": [{"type": "point", "data": {"lat": 37.0, "lng": 15.0}, "label": 0}],
|
| 69 |
+
"zoom": 10, "source_type": "OpenStreetMap.Mapnik", "debug": True
|
| 70 |
}
|
| 71 |
}
|
| 72 |
expected_output_dict = {
|
|
|
|
| 75 |
"sw": {"lat": 37.455509218936974, "lng": 14.632807441554068}
|
| 76 |
},
|
| 77 |
"prompt": [{"type": "point", "data": {"lat": 37.0, "lng": 15.0}, "label": 0}],
|
| 78 |
+
"zoom": 10, "source_type": "OpenStreetMap.Mapnik", "debug": True
|
| 79 |
}
|
| 80 |
output = get_parsed_request_body(input_event["event"])
|
| 81 |
assert output == ApiRequestBody.model_validate(input_event["event"])
|
|
|
|
| 89 |
assert output == ApiRequestBody.model_validate(expected_output_dict)
|
| 90 |
|
| 91 |
|
| 92 |
+
@patch.object(lambda_helpers, "providers")
|
| 93 |
+
def test_get_url_tile(providers_mocked):
|
| 94 |
+
import xyzservices
|
| 95 |
+
from src.io.lambda_helpers import get_url_tile
|
| 96 |
+
|
| 97 |
+
from tests import LOCAL_URL_TILE
|
| 98 |
+
|
| 99 |
+
local_tile_provider = xyzservices.TileProvider(name="local_tile_provider", url=LOCAL_URL_TILE, attribution="")
|
| 100 |
+
expected_output = {'name': 'local_tile_provider', 'url': LOCAL_URL_TILE, 'attribution': ''}
|
| 101 |
+
providers_mocked.query_name.return_value = local_tile_provider
|
| 102 |
+
assert get_url_tile("OpenStreetMap") == expected_output
|
| 103 |
+
|
| 104 |
+
local_url = 'http://localhost:8000/{parameter}/{z}/{x}/{y}.png'
|
| 105 |
+
local_tile_provider = xyzservices.TileProvider(
|
| 106 |
+
name="local_tile_provider_param", url=local_url, attribution="", parameter="lamda_handler"
|
| 107 |
+
)
|
| 108 |
+
providers_mocked.query_name.return_value = local_tile_provider
|
| 109 |
+
assert get_url_tile("OpenStreetMap.HOT") == {
|
| 110 |
+
"parameter": "lamda_handler", 'name': 'local_tile_provider_param', 'url': local_url, 'attribution': ''
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def test_get_url_tile_real():
|
| 115 |
from src.io.lambda_helpers import get_url_tile
|
|
|
|
| 116 |
|
| 117 |
+
assert get_url_tile("OpenStreetMap") == {
|
| 118 |
+
'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19,
|
| 119 |
+
'html_attribution': '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
| 120 |
+
'attribution': '(C) OpenStreetMap contributors',
|
| 121 |
+
'name': 'OpenStreetMap.Mapnik'}
|
| 122 |
+
|
| 123 |
+
html_attribution_hot = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, '
|
| 124 |
+
html_attribution_hot += 'Tiles style by <a href="https://www.hotosm.org/" target="_blank">Humanitarian '
|
| 125 |
+
html_attribution_hot += 'OpenStreetMap Team</a> hosted by <a href="https://openstreetmap.fr/" target="_blank">'
|
| 126 |
+
html_attribution_hot += 'OpenStreetMap France</a>'
|
| 127 |
+
attribution_hot = '(C) OpenStreetMap contributors, Tiles style by Humanitarian OpenStreetMap Team hosted by '
|
| 128 |
+
attribution_hot += 'OpenStreetMap France'
|
| 129 |
+
assert get_url_tile("OpenStreetMap.HOT") == {
|
| 130 |
+
'url': 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', 'max_zoom': 19,
|
| 131 |
+
'html_attribution': html_attribution_hot, 'attribution': attribution_hot, 'name': 'OpenStreetMap.HOT'
|
| 132 |
+
}
|
| 133 |
+
|
tests/io/test_tms2geotiff.py
CHANGED
|
@@ -11,8 +11,9 @@ input_bbox = [[39.036252959636606, 15.040283203125002], [38.302869955150044, 13.
|
|
| 11 |
|
| 12 |
|
| 13 |
class TestTms2geotiff(unittest.TestCase):
|
| 14 |
-
def
|
| 15 |
from rasterio import Affine
|
|
|
|
| 16 |
from tests.local_tiles_http_server import LocalTilesHttpServer
|
| 17 |
|
| 18 |
listen_port = 8000
|
|
@@ -26,7 +27,8 @@ class TestTms2geotiff(unittest.TestCase):
|
|
| 26 |
s_lat = pt1[0]
|
| 27 |
w_lng = pt1[1]
|
| 28 |
|
| 29 |
-
|
|
|
|
| 30 |
app_logger.info(f"# DOWNLOAD ENDED, shape: {img.shape} #")
|
| 31 |
np_img = np.ascontiguousarray(img)
|
| 32 |
output_hash = hash_calculate(np_img)
|
|
@@ -34,6 +36,53 @@ class TestTms2geotiff(unittest.TestCase):
|
|
| 34 |
assert Affine.to_gdal(matrix) == (
|
| 35 |
1517657.1966021745, 152.8740565703525, 0.0, 4726942.266183584, 0.0, -152.87405657034955)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def test_download_extent_io_error1(self):
|
| 38 |
|
| 39 |
with self.assertRaises(Exception):
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
class TestTms2geotiff(unittest.TestCase):
|
| 14 |
+
def test_download_extent_simple_source(self):
|
| 15 |
from rasterio import Affine
|
| 16 |
+
from xyzservices import TileProvider
|
| 17 |
from tests.local_tiles_http_server import LocalTilesHttpServer
|
| 18 |
|
| 19 |
listen_port = 8000
|
|
|
|
| 27 |
s_lat = pt1[0]
|
| 28 |
w_lng = pt1[1]
|
| 29 |
|
| 30 |
+
source = TileProvider(name="local_tile_provider", url=LOCAL_URL_TILE, attribution="")
|
| 31 |
+
img, matrix = download_extent(w=w_lng, s=s_lat, e=e_lng, n=n_lat, zoom=zoom, source=source)
|
| 32 |
app_logger.info(f"# DOWNLOAD ENDED, shape: {img.shape} #")
|
| 33 |
np_img = np.ascontiguousarray(img)
|
| 34 |
output_hash = hash_calculate(np_img)
|
|
|
|
| 36 |
assert Affine.to_gdal(matrix) == (
|
| 37 |
1517657.1966021745, 152.8740565703525, 0.0, 4726942.266183584, 0.0, -152.87405657034955)
|
| 38 |
|
| 39 |
+
def test_download_extent_source_with_parameter(self):
|
| 40 |
+
from rasterio import Affine
|
| 41 |
+
from xyzservices import TileProvider
|
| 42 |
+
from tests.local_tiles_http_server import LocalTilesHttpServer
|
| 43 |
+
|
| 44 |
+
listen_port = 8000
|
| 45 |
+
|
| 46 |
+
with LocalTilesHttpServer.http_server("localhost", listen_port, directory=TEST_EVENTS_FOLDER):
|
| 47 |
+
pt0, pt1 = input_bbox
|
| 48 |
+
zoom = 10
|
| 49 |
+
|
| 50 |
+
n_lat = pt0[0]
|
| 51 |
+
e_lng = pt0[1]
|
| 52 |
+
s_lat = pt1[0]
|
| 53 |
+
w_lng = pt1[1]
|
| 54 |
+
|
| 55 |
+
local_url_tile2 = "http://localhost:8000/{parameter}/{z}/{x}/{y}.png"
|
| 56 |
+
source = TileProvider(
|
| 57 |
+
name="local_tile_provider", url=local_url_tile2, attribution="", parameter="lambda_handler")
|
| 58 |
+
img, matrix = download_extent(w=w_lng, s=s_lat, e=e_lng, n=n_lat, zoom=zoom, source=source)
|
| 59 |
+
app_logger.info(f"# DOWNLOAD ENDED, shape: {img.shape} #")
|
| 60 |
+
np_img = np.ascontiguousarray(img)
|
| 61 |
+
output_hash = hash_calculate(np_img)
|
| 62 |
+
assert output_hash == b'UmbkwbPJpRT1XXcLnLUapUDP320w7YhS/AmT3H7u+b4='
|
| 63 |
+
assert Affine.to_gdal(matrix) == (
|
| 64 |
+
1517657.1966021745, 152.8740565703525, 0.0, 4726942.266183584, 0.0, -152.87405657034955)
|
| 65 |
+
|
| 66 |
+
def test_download_extent_source_with_parameter_key_error(self):
|
| 67 |
+
from xyzservices import TileProvider
|
| 68 |
+
|
| 69 |
+
with self.assertRaises(KeyError):
|
| 70 |
+
try:
|
| 71 |
+
pt0, pt1 = input_bbox
|
| 72 |
+
zoom = 10
|
| 73 |
+
|
| 74 |
+
n_lat = pt0[0]
|
| 75 |
+
e_lng = pt0[1]
|
| 76 |
+
s_lat = pt1[0]
|
| 77 |
+
w_lng = pt1[1]
|
| 78 |
+
|
| 79 |
+
local_url_tile2 = "http://localhost:8000/{parameter}/{z}/{x}/{y}.png"
|
| 80 |
+
source = TileProvider(name="local_tile_provider", url=local_url_tile2, attribution="")
|
| 81 |
+
download_extent(w=w_lng, s=s_lat, e=e_lng, n=n_lat, zoom=zoom, source=source)
|
| 82 |
+
except KeyError as ke:
|
| 83 |
+
assert str(ke) == "'parameter'"
|
| 84 |
+
raise ke
|
| 85 |
+
|
| 86 |
def test_download_extent_io_error1(self):
|
| 87 |
|
| 88 |
with self.assertRaises(Exception):
|
tests/test_app.py
CHANGED
|
@@ -108,18 +108,18 @@ class TestAppFailures(unittest.TestCase):
|
|
| 108 |
get_response_io = json.load(tst_json_get_response)
|
| 109 |
|
| 110 |
input_200 = {
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
}
|
| 124 |
|
| 125 |
samexporter_predict_output = get_response_io[response_type]["input"]
|
|
@@ -143,20 +143,22 @@ class TestAppFailures(unittest.TestCase):
|
|
| 143 |
|
| 144 |
@patch.object(lambda_helpers, "get_url_tile")
|
| 145 |
def test_lambda_handler_200_real_single_multi_point(self, get_url_tile_mocked):
|
|
|
|
| 146 |
import shapely
|
| 147 |
|
| 148 |
from src.app import lambda_handler
|
| 149 |
from tests import LOCAL_URL_TILE, TEST_EVENTS_FOLDER
|
| 150 |
|
| 151 |
-
|
|
|
|
| 152 |
fn_name = "lambda_handler"
|
| 153 |
invoke_id = "test_invoke_id"
|
| 154 |
|
| 155 |
for json_filename in [
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
with open(TEST_EVENTS_FOLDER / f"{fn_name}_{json_filename}.json") as tst_json:
|
| 161 |
inputs_outputs = json.load(tst_json)
|
| 162 |
lambda_context = LambdaContext(
|
|
@@ -187,3 +189,24 @@ class TestAppFailures(unittest.TestCase):
|
|
| 187 |
print("output_geojson::", type(output_geojson))
|
| 188 |
assert isinstance(output_geojson, shapely.GeometryCollection)
|
| 189 |
assert len(output_geojson.geoms) == expected_response_body["n_shapes_geojson"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
get_response_io = json.load(tst_json_get_response)
|
| 109 |
|
| 110 |
input_200 = {
|
| 111 |
+
"bbox": {
|
| 112 |
+
"ne": {"lat": 38.03932961278458, "lng": 15.36808069832851},
|
| 113 |
+
"sw": {"lat": 37.455509218936974, "lng": 14.632807441554068}
|
| 114 |
+
},
|
| 115 |
+
"prompt": [{
|
| 116 |
+
"type": "point",
|
| 117 |
+
"data": {"lat": 37.0, "lng": 15.0},
|
| 118 |
+
"label": 0
|
| 119 |
+
}],
|
| 120 |
+
"zoom": 10,
|
| 121 |
+
"source_type": "OpenStreetMap.Mapnik",
|
| 122 |
+
"debug": True
|
| 123 |
}
|
| 124 |
|
| 125 |
samexporter_predict_output = get_response_io[response_type]["input"]
|
|
|
|
| 143 |
|
| 144 |
@patch.object(lambda_helpers, "get_url_tile")
|
| 145 |
def test_lambda_handler_200_real_single_multi_point(self, get_url_tile_mocked):
|
| 146 |
+
import xyzservices
|
| 147 |
import shapely
|
| 148 |
|
| 149 |
from src.app import lambda_handler
|
| 150 |
from tests import LOCAL_URL_TILE, TEST_EVENTS_FOLDER
|
| 151 |
|
| 152 |
+
local_tile_provider = xyzservices.TileProvider(name="local_tile_provider", url=LOCAL_URL_TILE, attribution="")
|
| 153 |
+
get_url_tile_mocked.return_value = local_tile_provider
|
| 154 |
fn_name = "lambda_handler"
|
| 155 |
invoke_id = "test_invoke_id"
|
| 156 |
|
| 157 |
for json_filename in [
|
| 158 |
+
"single_point",
|
| 159 |
+
"multi_prompt",
|
| 160 |
+
"single_rectangle"
|
| 161 |
+
]:
|
| 162 |
with open(TEST_EVENTS_FOLDER / f"{fn_name}_{json_filename}.json") as tst_json:
|
| 163 |
inputs_outputs = json.load(tst_json)
|
| 164 |
lambda_context = LambdaContext(
|
|
|
|
| 189 |
print("output_geojson::", type(output_geojson))
|
| 190 |
assert isinstance(output_geojson, shapely.GeometryCollection)
|
| 191 |
assert len(output_geojson.geoms) == expected_response_body["n_shapes_geojson"]
|
| 192 |
+
|
| 193 |
+
def test_debug(self):
|
| 194 |
+
from src.app import lambda_handler
|
| 195 |
+
|
| 196 |
+
input_event = {
|
| 197 |
+
'bbox': {
|
| 198 |
+
'ne': {'lat': 46.302592089330524, 'lng': 9.49493408203125},
|
| 199 |
+
'sw': {'lat': 46.14011755129237, 'lng': 9.143371582031252}},
|
| 200 |
+
'prompt': [
|
| 201 |
+
{'id': 166, 'type': 'point', 'data': {'lat': 46.18244521829928, 'lng': 9.418544769287111}, 'label': 1}
|
| 202 |
+
],
|
| 203 |
+
'zoom': 12, 'source_type': 'OpenStreetMap'
|
| 204 |
+
}
|
| 205 |
+
lambda_context = LambdaContext(
|
| 206 |
+
invoke_id="test_invoke_id",
|
| 207 |
+
client_context=None,
|
| 208 |
+
cognito_identity=None,
|
| 209 |
+
epoch_deadline_time_in_ms=time.time()
|
| 210 |
+
)
|
| 211 |
+
response = lambda_handler(event=input_event, context=lambda_context)
|
| 212 |
+
print(response)
|