[refactor] migrate pydantic.parse to pydantic.model_validate
Browse files
src/io/lambda_helpers.py
CHANGED
|
@@ -2,9 +2,7 @@ import json
|
|
| 2 |
import logging
|
| 3 |
import time
|
| 4 |
from typing import Dict
|
| 5 |
-
|
| 6 |
from aws_lambda_powertools.event_handler import content_types
|
| 7 |
-
from aws_lambda_powertools.utilities.parser import parse
|
| 8 |
|
| 9 |
from src import app_logger
|
| 10 |
from src.io.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
|
|
@@ -94,7 +92,7 @@ def get_parsed_request_body(event):
|
|
| 94 |
raw_body = json.loads(body_decoded_str)
|
| 95 |
app_logger.info(f"body, #2: {type(raw_body)}, {raw_body}...")
|
| 96 |
|
| 97 |
-
parsed_body =
|
| 98 |
log_level = "DEBUG" if parsed_body.debug else "INFO"
|
| 99 |
app_logger.setLevel(log_level)
|
| 100 |
app_logger.warning(f"set log level to {logging.getLevelName(app_logger.log_level)}.")
|
|
|
|
| 2 |
import logging
|
| 3 |
import time
|
| 4 |
from typing import Dict
|
|
|
|
| 5 |
from aws_lambda_powertools.event_handler import content_types
|
|
|
|
| 6 |
|
| 7 |
from src import app_logger
|
| 8 |
from src.io.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
|
|
|
|
| 92 |
raw_body = json.loads(body_decoded_str)
|
| 93 |
app_logger.info(f"body, #2: {type(raw_body)}, {raw_body}...")
|
| 94 |
|
| 95 |
+
parsed_body = RawRequestInput.model_validate(raw_body)
|
| 96 |
log_level = "DEBUG" if parsed_body.debug else "INFO"
|
| 97 |
app_logger.setLevel(log_level)
|
| 98 |
app_logger.warning(f"set log level to {logging.getLevelName(app_logger.log_level)}.")
|
tests/io/test_coordinates_pixel_conversion.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
import json
|
| 2 |
|
| 3 |
-
from aws_lambda_powertools.utilities.parser import parse
|
| 4 |
-
|
| 5 |
from src.io.coordinates_pixel_conversion import get_latlng2pixel_projection, get_point_latlng_to_pixel_coordinates, \
|
| 6 |
get_latlng_to_pixel_coordinates
|
| 7 |
from src.utilities.type_hints import LatLngDict
|
|
@@ -16,7 +14,7 @@ def test_get_latlng2pixel_projection():
|
|
| 16 |
for k, input_output in inputs_outputs.items():
|
| 17 |
print(f"k:{k}")
|
| 18 |
current_input = input_output["input"]
|
| 19 |
-
latlng_input =
|
| 20 |
output = get_latlng2pixel_projection(latlng_input)
|
| 21 |
assert output == input_output["output"]
|
| 22 |
|
|
@@ -29,7 +27,7 @@ def test_get_point_latlng_to_pixel_coordinates():
|
|
| 29 |
for k, input_output in inputs_outputs.items():
|
| 30 |
print(f"k:{k}")
|
| 31 |
current_input = input_output["input"]
|
| 32 |
-
latlng_input =
|
| 33 |
output = get_point_latlng_to_pixel_coordinates(latlng=latlng_input, zoom=current_input["zoom"])
|
| 34 |
assert output == input_output["output"]
|
| 35 |
|
|
@@ -43,9 +41,9 @@ def test_get_latlng_to_pixel_coordinates():
|
|
| 43 |
print(f"k:{k}")
|
| 44 |
current_input = input_output["input"]
|
| 45 |
zoom = current_input["zoom"]
|
| 46 |
-
latlng_origin_ne =
|
| 47 |
-
latlng_origin_sw =
|
| 48 |
-
latlng_current_point =
|
| 49 |
output = get_latlng_to_pixel_coordinates(
|
| 50 |
latlng_origin_ne=latlng_origin_ne,
|
| 51 |
latlng_origin_sw=latlng_origin_sw,
|
|
|
|
| 1 |
import json
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from src.io.coordinates_pixel_conversion import get_latlng2pixel_projection, get_point_latlng_to_pixel_coordinates, \
|
| 4 |
get_latlng_to_pixel_coordinates
|
| 5 |
from src.utilities.type_hints import LatLngDict
|
|
|
|
| 14 |
for k, input_output in inputs_outputs.items():
|
| 15 |
print(f"k:{k}")
|
| 16 |
current_input = input_output["input"]
|
| 17 |
+
latlng_input = LatLngDict.model_validate(current_input["latlng"])
|
| 18 |
output = get_latlng2pixel_projection(latlng_input)
|
| 19 |
assert output == input_output["output"]
|
| 20 |
|
|
|
|
| 27 |
for k, input_output in inputs_outputs.items():
|
| 28 |
print(f"k:{k}")
|
| 29 |
current_input = input_output["input"]
|
| 30 |
+
latlng_input = LatLngDict.model_validate(current_input["latlng"])
|
| 31 |
output = get_point_latlng_to_pixel_coordinates(latlng=latlng_input, zoom=current_input["zoom"])
|
| 32 |
assert output == input_output["output"]
|
| 33 |
|
|
|
|
| 41 |
print(f"k:{k}")
|
| 42 |
current_input = input_output["input"]
|
| 43 |
zoom = current_input["zoom"]
|
| 44 |
+
latlng_origin_ne = LatLngDict.model_validate(current_input["latlng_origin_ne"])
|
| 45 |
+
latlng_origin_sw = LatLngDict.model_validate(current_input["latlng_origin_sw"])
|
| 46 |
+
latlng_current_point = LatLngDict.model_validate(current_input["latlng_current_point"])
|
| 47 |
output = get_latlng_to_pixel_coordinates(
|
| 48 |
latlng_origin_ne=latlng_origin_ne,
|
| 49 |
latlng_origin_sw=latlng_origin_sw,
|