Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaraphael committed Dec 20, 2024
1 parent e5c65d9 commit fceaf30
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stack/cloud_function_scene_relevancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
construct_name("queue-cr-orchestrator"),
location=pulumi.Config("gcp").require("region"),
rate_limits=cloudtasks.QueueRateLimitsArgs(
max_concurrent_dispatches=50,
max_concurrent_dispatches=40,
max_dispatches_per_second=1,
),
retry_config=cloudtasks.QueueRetryConfigArgs(
Expand Down
114 changes: 114 additions & 0 deletions test/test_cerulean_cloud/test_cloud_function_scene_relevancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,117 @@ def test_make_logs():
"timeRange=2022-07-15T11:13:12.183229Z%2F2022-07-15T11:15:12.183229Z;"
"cursorTimestamp=2022-07-15T11:13:12.183229Z?project=cerulean-338116"
)


def test_handle_notification_filters():
ocean_poly = load_ocean_poly(
"cerulean_cloud/cloud_function_scene_relevancy/OceanGeoJSON_lowres.geojson"
)

# Valid scene/polygon (should produce a non-empty result if it normally does)
valid_scene_id = (
"S1A_IW_GRDH_1SDV_20240730T001806_20240730T001831_054983_06B2B8_3CE1"
)
valid_event = {
"Records": [
{
"Sns": {
"Message": json.dumps(
{
"id": valid_scene_id,
"footprint": {
"type": "Polygon",
"coordinates": [
[
[
[0.0, 0.0],
[0.0, 1.0],
[1.0, 1.0],
[1.0, 0.0],
[0.0, 0.0],
]
]
],
},
}
)
}
}
]
}
valid_res = handle_notification(valid_event, ocean_poly=ocean_poly)
# Depending on logic, this should be non-empty if it meets the criteria for relevancy
# If the function currently filters on ocean/intersection, adjust the polygon or expectations accordingly.
# For now we assume it should return something. If it doesn't, adjust your logic or polygon.
assert len(valid_res) > 0, "Expected at least one result for a valid scene/polygon"

# Invalid scene IDs (should all be rejected)
invalid_scene_ids = [
"S1A_S3_GRDH_1SDV_20",
"S1A_IW_GRDM_1SDV_20",
"S1A_IW_GRDH_1SDH_20",
]

for scene_id in invalid_scene_ids:
invalid_event = {
"Records": [
{
"Sns": {
"Message": json.dumps(
{
"id": scene_id,
"footprint": {
"type": "Polygon",
"coordinates": [
[
[
[0.0, 0.0],
[0.0, 1.0],
[1.0, 1.0],
[1.0, 0.0],
[0.0, 0.0],
]
]
],
},
}
)
}
}
]
}
invalid_res = handle_notification(invalid_event, ocean_poly=ocean_poly)
assert (
len(invalid_res) == 0
), f"Expected no results for invalid scene_id {scene_id}"

# Invalid polygon (should be rejected)
invalid_polygon_event = {
"Records": [
{
"Sns": {
"Message": json.dumps(
{
"id": valid_scene_id,
"footprint": {
"type": "Polygon",
"coordinates": [
[
[
[10.0, 10.0],
[10.0, 11.0],
[11.0, 11.0],
[11.0, 10.0],
[10.0, 10.0],
]
]
],
},
}
)
}
}
]
}
invalid_poly_res = handle_notification(invalid_polygon_event, ocean_poly=ocean_poly)
assert len(invalid_poly_res) == 0, "Expected no results for invalid polygon"

0 comments on commit fceaf30

Please sign in to comment.