import json import unittest from unittest.mock import patch from samgis_lisa_on_zero.io_package import wrappers_helpers from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_dictlist_prompt from samgis_lisa_on_zero.utilities.type_hints import ApiRequestBody from tests import TEST_EVENTS_FOLDER class WrappersHelpersTest(unittest.TestCase): @staticmethod def test_get_parsed_bbox_other_inputs(): for json_filename in ["single_rectangle", "multi_prompt"]: with open(TEST_EVENTS_FOLDER / f"get_parsed_bbox_prompts_{json_filename}.json") as tst_json: inputs_outputs = json.load(tst_json) parsed_input = ApiRequestBody.model_validate(inputs_outputs["input"]) output = get_parsed_bbox_points_with_dictlist_prompt(parsed_input) assert output == inputs_outputs["output"] def test_get_parsed_bbox_points_with_string_prompt(self): from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_string_prompt req = { "bbox":{ "ne":{"lat":46.17271333276639,"lng":10.079505443573},"sw":{"lat":46.1677724417049,"lng":10.068830251693727} }, "string_prompt":"You are a ...", "zoom":17, "source_type":"Esri.WorldImagery" } print(req) out = get_parsed_bbox_points_with_string_prompt(json.dumps(req)) assert isinstance(out, dict) for out_k, req_k in zip(out.keys(), req.keys()): assert isinstance(out_k, str) assert isinstance(req_k, str) @patch.object(wrappers_helpers, "providers") def test_get_url_tile(self, providers_mocked): import xyzservices from samgis_lisa_on_zero.io_package.wrappers_helpers import get_url_tile from tests import LOCAL_URL_TILE local_tile_provider = xyzservices.TileProvider(name="local_tile_provider", url=LOCAL_URL_TILE, attribution="") expected_output = {'name': 'local_tile_provider', 'url': LOCAL_URL_TILE, 'attribution': ''} providers_mocked.query_name.return_value = local_tile_provider assert get_url_tile("OpenStreetMap") == expected_output local_url = 'http://localhost:8000/{parameter}/{z}/{x}/{y}.png' local_tile_provider = xyzservices.TileProvider( name="local_tile_provider_param", url=local_url, attribution="", parameter="lamda_handler" ) providers_mocked.query_name.return_value = local_tile_provider assert get_url_tile("OpenStreetMap.HOT") == { "parameter": "lamda_handler", 'name': 'local_tile_provider_param', 'url': local_url, 'attribution': '' } @staticmethod def test_get_url_tile_real(): from samgis_lisa_on_zero.io_package.wrappers_helpers import get_url_tile assert get_url_tile("OpenStreetMap") == { 'url': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'max_zoom': 19, 'html_attribution': '© OpenStreetMap contributors', 'attribution': '(C) OpenStreetMap contributors', 'name': 'OpenStreetMap.Mapnik'} html_attribution_hot = '© OpenStreetMap contributors, ' html_attribution_hot += 'Tiles style by Humanitarian ' html_attribution_hot += 'OpenStreetMap Team hosted by ' html_attribution_hot += 'OpenStreetMap France' attribution_hot = '(C) OpenStreetMap contributors, Tiles style by Humanitarian OpenStreetMap Team hosted by ' attribution_hot += 'OpenStreetMap France' assert get_url_tile("OpenStreetMap.HOT") == { 'url': 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', 'max_zoom': 19, 'html_attribution': html_attribution_hot, 'attribution': attribution_hot, 'name': 'OpenStreetMap.HOT' }