This commit is contained in:
2026-05-09 16:55:06 +03:30
parent 1679825ae2
commit cead7dafe2
51 changed files with 7514 additions and 1221 deletions
+1 -21
View File
@@ -7,7 +7,7 @@ import uuid
from django.test import TransactionTestCase
from rest_framework.test import APIClient
from location_data.models import NdviObservation, SoilDepthData, SoilLocation
from location_data.models import NdviObservation, SoilLocation
from weather.models import WeatherForecast
@@ -55,32 +55,12 @@ class IntegrationAPITestCase(TransactionTestCase):
lat: float,
lon: float,
boundary: dict[str, Any] | None = None,
clay_values: tuple[float, float, float] = (22.0, 18.0, 15.0),
nitrogen_values: tuple[float, float, float] = (14.0, 11.0, 8.0),
) -> SoilLocation:
location = SoilLocation.objects.create(
latitude=f"{lat:.6f}",
longitude=f"{lon:.6f}",
farm_boundary=boundary or square_boundary(lat, lon),
)
depth_labels = (
SoilDepthData.DEPTH_0_5,
SoilDepthData.DEPTH_5_15,
SoilDepthData.DEPTH_15_30,
)
for index, depth_label in enumerate(depth_labels):
SoilDepthData.objects.create(
soil_location=location,
depth_label=depth_label,
clay=clay_values[index],
nitrogen=nitrogen_values[index],
sand=40.0 - (index * 2),
silt=25.0 + index,
phh2o=6.6 + (index * 0.1),
wv0010=0.41 - (index * 0.02),
wv0033=0.28 - (index * 0.01),
wv1500=0.12 - (index * 0.01),
)
return location
def seed_weather_forecasts(
@@ -88,36 +88,7 @@ class ReportingAndAiJourneyTests(IntegrationAPITestCase):
)
self.assertEqual(soil_response.status_code, 200)
self.assertEqual(soil_response.json()["data"]["source"], "database")
self.assertEqual(len(soil_response.json()["data"]["depths"]), 3)
queued_location = {}
def soil_delay_stub(lat: float, lon: float):
location = self.create_complete_location(lat=lat, lon=lon)
queued_location["id"] = location.id
return SimpleNamespace(id="soil-task-1")
with patch("location_data.views.fetch_soil_data_task.delay", side_effect=soil_delay_stub):
queued_response = self.client.post(
"/api/soil-data/",
data={"lat": "36.100000", "lon": "52.200000"},
format="json",
)
self.assertEqual(queued_response.status_code, 202)
with patch(
"celery.result.AsyncResult",
return_value=FakeAsyncResult(
state="SUCCESS",
result={"status": "completed", "location_id": queued_location["id"]},
),
):
soil_status_response = self.client.get("/api/soil-data/tasks/soil-task-1/status/")
self.assertEqual(soil_status_response.status_code, 200)
self.assertEqual(
soil_status_response.json()["data"]["result"]["id"],
queued_location["id"],
)
self.assertIn("satellite_snapshots", soil_response.json()["data"])
weather_response = self.client.post(
"/api/weather/farm-card/",