Skip to content

Commit

Permalink
Update: test for difference map
Browse files Browse the repository at this point in the history
  • Loading branch information
KarineGEO6 committed Jul 12, 2024
1 parent a5f3c6f commit 0b8cba4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 19 deletions.
8 changes: 4 additions & 4 deletions geosyspy/services/map_product_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,21 @@ def get_product(
return df

def get_zipped_tiff_difference_map(
self, field_id: str, image_id_before: str, image_id_after: str
self, field_id: str, image_id_earliest: str, image_id_latest: str
):
"""
Retrieves tiff resulting of a difference between 2 in-season images for a given season field from MP API.
Args:
season_field_id (str): The identifier for the season field.
image_id_before (str): The image reference from the satellite coverage before.
image_id_after (str): The image reference from the satellite coverage after.
image_id_earliest (str): The earliest image reference from the satellite coverage.
image_id_latest (str): The latest image reference from the satellite coverage.
Returns:
zipped tiff
"""

parameters = f"/{image_id_before}/base-reference-map/DIFFERENCE_INSEASON_NDVI/difference-with/{image_id_after}/image.tiff.zip?$epsg-out=3857"
parameters = f"/{image_id_latest}/base-reference-map/DIFFERENCE_INSEASON_NDVI/difference-with/{image_id_earliest}/image.tiff.zip?$epsg-out=3857"
download_tiff_url: str = urljoin(
self.base_url,
GeosysApiEndpoints.FLM_BASE_REFERENCE_MAP.value.format(field_id)
Expand Down
73 changes: 58 additions & 15 deletions tests/test_unit_map_product_service.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,80 @@
import datetime as dt
import numpy as np
from unittest.mock import patch

import numpy as np

from geosyspy.services.map_product_service import MapProductService
from geosyspy.utils.constants import *
from geosyspy.utils.http_client import *
from tests.test_helper import *
from geosyspy.utils.constants import *


class TestMapProductService:
url = "https://testurl.com"
http_client = HttpClient("client_id_123",
"client_secret_123456",
"username_123",
"password_123",
"preprod",
"na")
http_client = HttpClient(
"client_id_123",
"client_secret_123456",
"username_123",
"password_123",
"preprod",
"na",
)
priority_queue = "realtime"

service = MapProductService(base_url=url, http_client=http_client,priority_queue=priority_queue)
service = MapProductService(
base_url=url, http_client=http_client, priority_queue=priority_queue
)

@patch('geosyspy.utils.http_client.HttpClient.post')
@patch("geosyspy.utils.http_client.HttpClient.post")
def test_get_satellite_coverage(self, get_response):
get_response.return_value = mock_http_response_text_content("GET", load_data_from_textfile(
"satellite_coverage_image_references_mock_http_response"))
get_response.return_value = mock_http_response_text_content(
"GET",
load_data_from_textfile(
"satellite_coverage_image_references_mock_http_response"
),
)
start_date = dt.datetime.strptime("2022-01-01", "%Y-%m-%d")
end_date = dt.datetime.strptime("2023-01-01", "%Y-%m-%d")
info = self.service.get_satellite_coverage(
"fakeSeasonFieldId", None, start_date, end_date, "NDVI", [SatelliteImageryCollection.SENTINEL_2]
"fakeSeasonFieldId",
None,
start_date,
end_date,
"NDVI",
[SatelliteImageryCollection.SENTINEL_2],
)

assert {"coveragePercent", "image.id", "image.availableBands", "image.sensor",
"image.spatialResolution", "image.date", "seasonField.id"}.issubset(set(info.columns))
assert {
"coveragePercent",
"image.id",
"image.availableBands",
"image.sensor",
"image.spatialResolution",
"image.date",
"seasonField.id",
}.issubset(set(info.columns))

@patch("geosyspy.utils.http_client.HttpClient.post")
def test_get_difference_map(self, get_response):
get_response.return_value = mock_http_response_text_content(
"GET",
load_data_from_textfile(
"satellite_coverage_image_references_mock_http_response"
),
)
image_id_earliest = "sentinel-2-l2a%7CS2B_13SGC_20230520_0_L2A"
image_id_latest = "sentinel-2-l2a%7CS2B_13SGC_20230530_0_L2A"
field_id = "bgbrzez"
response = self.service.get_zipped_tiff_difference_map(
field_id, image_id_earliest, image_id_latest
)

assert response.status_code == 200, "Expected status code to be 200"

# Assert that the content type is 'image/tiff'
assert (
response.headers["Content-Type"] == "image/tiff+zip"
), "Expected content type to be 'image/tiff+zip'"

# Assert that the content is not empty
assert response.content, "Expected non-empty response content"

0 comments on commit 0b8cba4

Please sign in to comment.