@@ -91,3 +91,55 @@ def test_get_report_endpoint_success(self):
9191 response = self .client .get (f"{ TestReportAPI .BASE_URL } /123/" , headers = {"X-Token" : "OK" },
9292 params = {"token" : TestReportAPI .CORRECT_TOKEN })
9393 assert response .status_code == 200
94+
95+
96+
97+ def test_generate_irrigation_report_success (self ):
98+ from api .api_v1 .endpoints import report
99+
100+ mock_bg_task = self .patch (report , "process_irrigation_fertilization_data" )
101+ params = {
102+ "token" : TestReportAPI .CORRECT_TOKEN ,
103+ "irrigation_id" : "test_irrigation_id" ,
104+ "from_date" : "2023-01-01" ,
105+ "to_date" : "2023-01-31" ,
106+ "parcel_id" : "test_parcel_id"
107+ }
108+
109+ response = self .client .post (
110+ f"{ TestReportAPI .BASE_URL } /irrigation-report/" ,
111+ headers = {"X-Token" : "OK" },
112+ params = params
113+ )
114+
115+ assert response .status_code == 200
116+ response_json = response .json ()
117+ assert "uuid" in response_json
118+ assert len (response_json ["uuid" ]) == 36
119+
120+ mock_bg_task .assert_called_once ()
121+
122+ args , kwargs = mock_bg_task .call_args
123+ assert "123/" in kwargs ['pdf_file_name' ]
124+
125+ def test_generate_irrigation_report_with_file_upload (self ):
126+ from api .api_v1 .endpoints import report
127+ mock_bg_task = self .patch (report , "process_irrigation_fertilization_data" )
128+
129+ file_content = b'{"some": "json_data"}'
130+ files = {
131+ 'data' : ('test_data.json' , file_content , 'application/json' )
132+ }
133+
134+ response = self .client .post (
135+ f"{ TestReportAPI .BASE_URL } /irrigation-report/" ,
136+ headers = {"X-Token" : "OK" },
137+ params = {"token" : TestReportAPI .CORRECT_TOKEN },
138+ files = files
139+ )
140+
141+ assert response .status_code == 200
142+ mock_bg_task .assert_called_once ()
143+
144+ _ , kwargs = mock_bg_task .call_args
145+ assert kwargs ['data' ] == file_content
0 commit comments