This commit is contained in:
2026-05-13 22:28:56 +03:30
parent 46fe62fa04
commit 45fee1dfd3
26 changed files with 2329 additions and 878 deletions
@@ -279,3 +279,37 @@ class RemoteSensingClusterRecommendationApiTests(TestCase):
response.json()["msg"],
"برای این مزرعه هنوز هیچ گیاهی در farm_data ثبت نشده است.",
)
@patch("location_data.cluster_recommendation._simulate_candidate")
def test_cluster_recommendations_use_cached_payload_for_same_farm_assignments(self, simulate_mock):
simulate_mock.return_value = (
{
"engine": "pcse",
"model_name": "Wofost81_NWLP_CWB_CNB",
"metrics": {
"yield_estimate": 100.0,
"biomass": 200.0,
"max_lai": 3.1,
},
},
None,
)
first_response = self.client.get(
"/remote-sensing/cluster-recommendations/",
data={"farm_uuid": str(self.farm.farm_uuid)},
)
self.assertEqual(first_response.status_code, 200)
self.assertGreater(simulate_mock.call_count, 0)
simulate_mock.reset_mock()
simulate_mock.side_effect = AssertionError("cached recommendations should skip simulation")
second_response = self.client.get(
"/remote-sensing/cluster-recommendations/",
data={"farm_uuid": str(self.farm.farm_uuid)},
)
self.assertEqual(second_response.status_code, 200)
self.assertEqual(first_response.json()["data"], second_response.json()["data"])
simulate_mock.assert_not_called()