[test] lambda_handler: add test rectangle and multi prompts cases
Browse files
src/io/lambda_helpers.py
CHANGED
@@ -116,7 +116,7 @@ def _get_new_prompt_data_rectangle(bbox_ne, bbox_sw, prompt, zoom):
|
|
116 |
]
|
117 |
|
118 |
|
119 |
-
def get_parsed_request_body(event: Dict) -> RawRequestInput:
|
120 |
"""
|
121 |
Validator for the raw input request lambda event
|
122 |
|
|
|
116 |
]
|
117 |
|
118 |
|
119 |
+
def get_parsed_request_body(event: Dict or str) -> RawRequestInput:
|
120 |
"""
|
121 |
Validator for the raw input request lambda event
|
122 |
|
tests/events/get_parsed_bbox_prompts_multi_prompt.json
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input": {
|
3 |
+
"bbox": {
|
4 |
+
"ne": {
|
5 |
+
"lat": 46.28788479194308,
|
6 |
+
"lng": 9.475707775999172
|
7 |
+
},
|
8 |
+
"sw": {
|
9 |
+
"lat": 46.12536667198419,
|
10 |
+
"lng": 9.124145275999172
|
11 |
+
}
|
12 |
+
},
|
13 |
+
"prompt": [
|
14 |
+
{
|
15 |
+
"id": 527,
|
16 |
+
"type": "point",
|
17 |
+
"data": {
|
18 |
+
"lat": 46.18361019327142,
|
19 |
+
"lng": 9.442899846498142
|
20 |
+
},
|
21 |
+
"label": 1
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"id": 861,
|
25 |
+
"type": "rectangle",
|
26 |
+
"data": {
|
27 |
+
"ne": {
|
28 |
+
"lat": 46.19067068237379,
|
29 |
+
"lng": 9.448158649569828
|
30 |
+
},
|
31 |
+
"sw": {
|
32 |
+
"lat": 46.154770662283525,
|
33 |
+
"lng": 9.40386976089288
|
34 |
+
}
|
35 |
+
}
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"id": 869,
|
39 |
+
"type": "point",
|
40 |
+
"data": {
|
41 |
+
"lat": 46.16404509756208,
|
42 |
+
"lng": 9.431335738366943
|
43 |
+
},
|
44 |
+
"label": 0
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"id": 890,
|
48 |
+
"type": "point",
|
49 |
+
"data": {
|
50 |
+
"lat": 46.16975166534373,
|
51 |
+
"lng": 9.414512827164097
|
52 |
+
},
|
53 |
+
"label": 1
|
54 |
+
}
|
55 |
+
],
|
56 |
+
"zoom": 12,
|
57 |
+
"source_type": "Satellite",
|
58 |
+
"url_tile": "http://localhost:8000/lambda_handler/{z}/{x}/{y}.png"
|
59 |
+
},
|
60 |
+
"output": {
|
61 |
+
"bbox": [
|
62 |
+
[
|
63 |
+
46.28788479194308,
|
64 |
+
9.475707775999172
|
65 |
+
],
|
66 |
+
[
|
67 |
+
46.12536667198419,
|
68 |
+
9.124145275999172
|
69 |
+
]
|
70 |
+
],
|
71 |
+
"prompt": [
|
72 |
+
{
|
73 |
+
"type": "point",
|
74 |
+
"label": 1,
|
75 |
+
"data": [
|
76 |
+
929,
|
77 |
+
440
|
78 |
+
]
|
79 |
+
},
|
80 |
+
{
|
81 |
+
"type": "rectangle",
|
82 |
+
"data": [
|
83 |
+
815,
|
84 |
+
410,
|
85 |
+
944,
|
86 |
+
561
|
87 |
+
]
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"type": "point",
|
91 |
+
"label": 0,
|
92 |
+
"data": [
|
93 |
+
895,
|
94 |
+
522
|
95 |
+
]
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"type": "point",
|
99 |
+
"label": 1,
|
100 |
+
"data": [
|
101 |
+
846,
|
102 |
+
498
|
103 |
+
]
|
104 |
+
}
|
105 |
+
],
|
106 |
+
"zoom": 12
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
tests/events/{get_parsed_bbox_points.json → get_parsed_bbox_prompts_single_point.json}
RENAMED
File without changes
|
tests/events/get_parsed_bbox_prompts_single_rectangle.json
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input": {
|
3 |
+
"bbox": {
|
4 |
+
"ne": {
|
5 |
+
"lat": -20.756702460787714,
|
6 |
+
"lng": 156.13847182385842
|
7 |
+
},
|
8 |
+
"sw": {
|
9 |
+
"lat": -45.55296601778451,
|
10 |
+
"lng": 111.13847182385842
|
11 |
+
}
|
12 |
+
},
|
13 |
+
"prompt": [
|
14 |
+
{
|
15 |
+
"id": 665,
|
16 |
+
"type": "rectangle",
|
17 |
+
"data": {
|
18 |
+
"ne": {
|
19 |
+
"lat": -39.71220032784001,
|
20 |
+
"lng": 149.33022207241362
|
21 |
+
},
|
22 |
+
"sw": {
|
23 |
+
"lat": -44.092362655875746,
|
24 |
+
"lng": 143.26567640979061
|
25 |
+
}
|
26 |
+
}
|
27 |
+
}
|
28 |
+
],
|
29 |
+
"zoom": 5,
|
30 |
+
"source_type": "Satellite",
|
31 |
+
"url_tile": "http://localhost:8000/lambda_handler/{z}/{x}/{y}.png"
|
32 |
+
},
|
33 |
+
"output": {
|
34 |
+
"bbox": [
|
35 |
+
[
|
36 |
+
-20.756702460787714,
|
37 |
+
156.13847182385842
|
38 |
+
],
|
39 |
+
[
|
40 |
+
-45.55296601778451,
|
41 |
+
111.13847182385842
|
42 |
+
]
|
43 |
+
],
|
44 |
+
"prompt": [
|
45 |
+
{
|
46 |
+
"data": [
|
47 |
+
731,
|
48 |
+
503,
|
49 |
+
869,
|
50 |
+
637
|
51 |
+
],
|
52 |
+
"type": "rectangle"
|
53 |
+
}
|
54 |
+
],
|
55 |
+
"zoom": 5
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
tests/io/test_lambda_helpers.py
CHANGED
@@ -38,7 +38,7 @@ def test_get_response(time_mocked):
|
|
38 |
|
39 |
|
40 |
def test_get_parsed_bbox_points():
|
41 |
-
with open(TEST_EVENTS_FOLDER / "
|
42 |
inputs_outputs = json.load(tst_json)
|
43 |
for k, input_output in inputs_outputs.items():
|
44 |
print(f"k:{k}.")
|
@@ -47,6 +47,15 @@ def test_get_parsed_bbox_points():
|
|
47 |
assert output == input_output["output"]
|
48 |
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
def test_get_parsed_request_body():
|
51 |
input_event = {
|
52 |
"event": {
|
|
|
38 |
|
39 |
|
40 |
def test_get_parsed_bbox_points():
|
41 |
+
with open(TEST_EVENTS_FOLDER / "get_parsed_bbox_prompts_single_point.json") as tst_json:
|
42 |
inputs_outputs = json.load(tst_json)
|
43 |
for k, input_output in inputs_outputs.items():
|
44 |
print(f"k:{k}.")
|
|
|
47 |
assert output == input_output["output"]
|
48 |
|
49 |
|
50 |
+
def test_get_parsed_bbox_other_inputs():
|
51 |
+
for json_filename in ["single_rectangle", "multi_prompt"]:
|
52 |
+
with open(TEST_EVENTS_FOLDER / f"get_parsed_bbox_prompts_{json_filename}.json") as tst_json:
|
53 |
+
inputs_outputs = json.load(tst_json)
|
54 |
+
parsed_input = RawRequestInput.model_validate(inputs_outputs["input"])
|
55 |
+
output = get_parsed_bbox_points(parsed_input)
|
56 |
+
assert output == inputs_outputs["output"]
|
57 |
+
|
58 |
+
|
59 |
def test_get_parsed_request_body():
|
60 |
input_event = {
|
61 |
"event": {
|