UPDATE
This commit is contained in:
@@ -7,6 +7,7 @@ from rest_framework.test import APIClient
|
||||
|
||||
from location_data.models import SoilDepthData, SoilLocation
|
||||
from farm_data.models import SensorData
|
||||
from irrigation.models import IrrigationMethod
|
||||
from plant.models import Plant
|
||||
from weather.models import WeatherForecast
|
||||
|
||||
@@ -58,11 +59,13 @@ class FarmDetailApiTests(TestCase):
|
||||
)
|
||||
self.plant1 = Plant.objects.create(name="گوجهفرنگی")
|
||||
self.plant2 = Plant.objects.create(name="خیار")
|
||||
self.irrigation_method = IrrigationMethod.objects.create(name="آبیاری قطرهای")
|
||||
self.farm_uuid = uuid.uuid4()
|
||||
self.farm = SensorData.objects.create(
|
||||
farm_uuid=self.farm_uuid,
|
||||
center_location=self.location,
|
||||
weather_forecast=self.weather,
|
||||
irrigation_method=self.irrigation_method,
|
||||
sensor_payload={
|
||||
"sensor-7-1": {
|
||||
"soil_moisture": 33.5,
|
||||
@@ -78,7 +81,7 @@ class FarmDetailApiTests(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
payload = response.json()["data"]
|
||||
|
||||
self.assertEqual(payload["farm_uuid"], str(self.farm_uuid))
|
||||
self.assertNotIn("farm_uuid", payload)
|
||||
self.assertEqual(payload["center_location"]["id"], self.location.id)
|
||||
self.assertEqual(payload["weather"]["id"], self.weather.id)
|
||||
self.assertEqual(
|
||||
@@ -100,6 +103,8 @@ class FarmDetailApiTests(TestCase):
|
||||
self.assertEqual(returned_plants[self.plant1.id]["name"], self.plant1.name)
|
||||
self.assertEqual(returned_plants[self.plant2.id]["name"], self.plant2.name)
|
||||
self.assertIn("light", returned_plants[self.plant1.id])
|
||||
self.assertEqual(payload["irrigation_method_id"], self.irrigation_method.id)
|
||||
self.assertEqual(payload["irrigation_method"]["name"], self.irrigation_method.name)
|
||||
|
||||
def test_returns_404_when_farm_is_missing(self):
|
||||
response = self.client.get(f"/api/farm-data/{uuid.uuid4()}/detail/")
|
||||
@@ -123,6 +128,7 @@ class FarmDataUpsertApiTests(TestCase):
|
||||
temperature_max=24.0,
|
||||
temperature_mean=17.5,
|
||||
)
|
||||
self.irrigation_method = IrrigationMethod.objects.create(name="بارانی")
|
||||
|
||||
def test_post_creates_farm_data_with_explicit_farm_uuid(self):
|
||||
farm_uuid = uuid.uuid4()
|
||||
@@ -138,6 +144,7 @@ class FarmDataUpsertApiTests(TestCase):
|
||||
"nitrogen": 18.0,
|
||||
}
|
||||
},
|
||||
"irrigation_method_id": self.irrigation_method.id,
|
||||
},
|
||||
format="json",
|
||||
)
|
||||
@@ -150,6 +157,7 @@ class FarmDataUpsertApiTests(TestCase):
|
||||
farm = SensorData.objects.get(farm_uuid=farm_uuid)
|
||||
self.assertEqual(farm.center_location_id, self.location.id)
|
||||
self.assertEqual(farm.weather_forecast_id, self.weather.id)
|
||||
self.assertEqual(farm.irrigation_method_id, self.irrigation_method.id)
|
||||
self.assertEqual(
|
||||
farm.sensor_payload["sensor-7-1"]["soil_moisture"],
|
||||
31.2,
|
||||
|
||||
Reference in New Issue
Block a user