UPDATE
This commit is contained in:
@@ -7,6 +7,7 @@ import uuid
|
||||
from django.test import TransactionTestCase
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from farm_data.models import PlantCatalogSnapshot
|
||||
from location_data.models import NdviObservation, SoilLocation
|
||||
from weather.models import WeatherForecast
|
||||
|
||||
@@ -40,6 +41,7 @@ class IntegrationAPITestCase(TransactionTestCase):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.client = APIClient()
|
||||
self._next_backend_plant_id = 100
|
||||
self.primary_boundary = square_boundary(self.primary_lat, self.primary_lon)
|
||||
self.primary_location = self.create_complete_location(
|
||||
lat=self.primary_lat,
|
||||
@@ -55,6 +57,7 @@ class IntegrationAPITestCase(TransactionTestCase):
|
||||
lat: float,
|
||||
lon: float,
|
||||
boundary: dict[str, Any] | None = None,
|
||||
**_ignored: Any,
|
||||
) -> SoilLocation:
|
||||
location = SoilLocation.objects.create(
|
||||
latitude=f"{lat:.6f}",
|
||||
@@ -126,22 +129,46 @@ class IntegrationAPITestCase(TransactionTestCase):
|
||||
return response.json()["data"]
|
||||
|
||||
def create_plant_via_api(self, name: str, **overrides: Any) -> dict[str, Any]:
|
||||
backend_plant_id = int(overrides.pop("id", self._next_backend_plant_id))
|
||||
self._next_backend_plant_id = max(self._next_backend_plant_id, backend_plant_id + 1)
|
||||
payload = {
|
||||
"id": backend_plant_id,
|
||||
"name": name,
|
||||
"icon": "leaf",
|
||||
"light": "full sun",
|
||||
"watering": "every 2 days",
|
||||
"soil": "loamy",
|
||||
"temperature": "20-28C",
|
||||
"growth_stage": "vegetative",
|
||||
"growth_stages": ["vegetative"],
|
||||
"planting_season": "spring",
|
||||
"harvest_time": "90 days",
|
||||
"spacing": "50 cm",
|
||||
"fertilizer": "balanced NPK",
|
||||
}
|
||||
payload.update(overrides)
|
||||
response = self.client.post("/api/plants/", data=payload, format="json")
|
||||
self.assertEqual(response.status_code, 201, response.json())
|
||||
return response.json()["data"]
|
||||
if "growth_stages" not in overrides:
|
||||
payload["growth_stages"] = [payload["growth_stage"]] if payload.get("growth_stage") else []
|
||||
response = self.client.post("/api/farm-data/plants/sync/", data=[payload], format="json")
|
||||
self.assertEqual(response.status_code, 200, response.json())
|
||||
|
||||
snapshot = PlantCatalogSnapshot.objects.get(backend_plant_id=backend_plant_id)
|
||||
return {
|
||||
"id": snapshot.backend_plant_id,
|
||||
"backend_plant_id": snapshot.backend_plant_id,
|
||||
"name": snapshot.name,
|
||||
"icon": snapshot.icon,
|
||||
"light": snapshot.light,
|
||||
"watering": snapshot.watering,
|
||||
"soil": snapshot.soil,
|
||||
"temperature": snapshot.temperature,
|
||||
"growth_stage": snapshot.growth_stage,
|
||||
"growth_stages": list(snapshot.growth_stages or []),
|
||||
"planting_season": snapshot.planting_season,
|
||||
"harvest_time": snapshot.harvest_time,
|
||||
"spacing": snapshot.spacing,
|
||||
"fertilizer": snapshot.fertilizer,
|
||||
}
|
||||
|
||||
def create_sensor_parameter_via_api(self, **overrides: Any) -> dict[str, Any]:
|
||||
payload = {
|
||||
|
||||
Reference in New Issue
Block a user