UPDATE
This commit is contained in:
@@ -5,6 +5,7 @@ from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
import uuid
|
||||
|
||||
from django.apps import apps
|
||||
from django.test import override_settings
|
||||
|
||||
from crop_simulation.models import SimulationRun, SimulationScenario
|
||||
@@ -206,9 +207,11 @@ class ReportingAndAiJourneyTests(IntegrationAPITestCase):
|
||||
broken_simulation_service = SimpleNamespace(
|
||||
get_water_stress=lambda **_kwargs: (_ for _ in ()).throw(RuntimeError("simulation offline"))
|
||||
)
|
||||
with patch(
|
||||
"irrigation.indicators.apps.get_app_config",
|
||||
return_value=SimpleNamespace(get_water_stress_service=lambda: broken_simulation_service),
|
||||
crop_simulation_app = apps.get_app_config("crop_simulation")
|
||||
with patch.object(
|
||||
crop_simulation_app,
|
||||
"get_water_stress_service",
|
||||
return_value=broken_simulation_service,
|
||||
):
|
||||
water_stress_response = self.client.post(
|
||||
"/api/irrigation/water-stress/",
|
||||
@@ -509,12 +512,22 @@ class ReportingAndAiJourneyTests(IntegrationAPITestCase):
|
||||
"supportingMetrics": {"biomass": 12.1},
|
||||
}
|
||||
)
|
||||
with patch(
|
||||
"crop_simulation.views.apps.get_app_config",
|
||||
return_value=SimpleNamespace(
|
||||
get_current_farm_chart_simulator=lambda: current_chart_service,
|
||||
get_harvest_prediction_service=lambda: harvest_service,
|
||||
get_yield_prediction_service=lambda: yield_service,
|
||||
crop_simulation_app = apps.get_app_config("crop_simulation")
|
||||
with (
|
||||
patch.object(
|
||||
crop_simulation_app,
|
||||
"get_current_farm_chart_simulator",
|
||||
return_value=current_chart_service,
|
||||
),
|
||||
patch.object(
|
||||
crop_simulation_app,
|
||||
"get_harvest_prediction_service",
|
||||
return_value=harvest_service,
|
||||
),
|
||||
patch.object(
|
||||
crop_simulation_app,
|
||||
"get_yield_prediction_service",
|
||||
return_value=yield_service,
|
||||
),
|
||||
):
|
||||
current_chart_response = self.client.post(
|
||||
@@ -539,11 +552,15 @@ class ReportingAndAiJourneyTests(IntegrationAPITestCase):
|
||||
task_state: dict[str, object] = {}
|
||||
|
||||
def growth_delay_stub(payload):
|
||||
serializable_payload = {
|
||||
**payload,
|
||||
"farm_uuid": str(payload["farm_uuid"]) if payload.get("farm_uuid") else None,
|
||||
}
|
||||
scenario = SimulationScenario.objects.create(
|
||||
name=f"integration-{payload['plant_name']}",
|
||||
scenario_type=SimulationScenario.ScenarioType.SINGLE,
|
||||
status=SimulationScenario.Status.SUCCESS,
|
||||
input_payload=payload,
|
||||
input_payload=serializable_payload,
|
||||
result_payload={"engine": "stub"},
|
||||
)
|
||||
SimulationRun.objects.create(
|
||||
|
||||
Reference in New Issue
Block a user