|
1 | 1 | import os |
2 | 2 | from datetime import datetime, timedelta |
3 | 3 | from unittest import mock |
| 4 | +from unittest.mock import patch |
4 | 5 |
|
5 | 6 | from django.conf import settings |
6 | 7 | from django.contrib.auth import get_user_model |
@@ -1028,10 +1029,16 @@ def test_update_and_finalize_dref(self): |
1028 | 1029 |
|
1029 | 1030 | # Finalize DREF |
1030 | 1031 | finalize_url = f"/api/v2/dref/{dref.id}/finalize/" |
1031 | | - response = self.client.post(finalize_url) |
1032 | | - self.assert_200(response) |
1033 | | - self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
1034 | | - self.assertEqual(response.data["translation_module_original_language"], "en") |
| 1032 | + # Finalize without translation |
| 1033 | + with patch("dref.views.is_translation_complete", return_value=False): |
| 1034 | + response = self.client.post(finalize_url) |
| 1035 | + self.assert_400(response) |
| 1036 | + # Finalize with translation complete |
| 1037 | + with patch("dref.views.is_translation_complete", return_value=True): |
| 1038 | + response = self.client.post(finalize_url) |
| 1039 | + self.assert_200(response) |
| 1040 | + self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
| 1041 | + self.assertEqual(response.data["translation_module_original_language"], "en") |
1035 | 1042 |
|
1036 | 1043 | # Update in English |
1037 | 1044 | finalized_dref_id = response.data["id"] |
@@ -1169,10 +1176,16 @@ def test_dref_operational_update_finalize(self): |
1169 | 1176 |
|
1170 | 1177 | # Finalize Operational Update |
1171 | 1178 | finalize_url = f"/api/v2/dref-op-update/{op_update.id}/finalize/" |
1172 | | - response = self.client.post(finalize_url) |
1173 | | - self.assert_200(response) |
1174 | | - self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
1175 | | - self.assertEqual(response.data["translation_module_original_language"], "en") |
| 1179 | + # Finalize without translation |
| 1180 | + with patch("dref.views.is_translation_complete", return_value=False): |
| 1181 | + response = self.client.post(finalize_url) |
| 1182 | + self.assert_400(response) |
| 1183 | + # Finalize with translation complete |
| 1184 | + with patch("dref.views.is_translation_complete", return_value=True): |
| 1185 | + response = self.client.post(finalize_url) |
| 1186 | + self.assert_200(response) |
| 1187 | + self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
| 1188 | + self.assertEqual(response.data["translation_module_original_language"], "en") |
1176 | 1189 | # Update in English |
1177 | 1190 | finalized_op_update_id = response.data["id"] |
1178 | 1191 | url = f"/api/v2/dref-op-update/{finalized_op_update_id}/" |
@@ -2200,10 +2213,16 @@ def test_dref_final_report_finalize(self): |
2200 | 2213 |
|
2201 | 2214 | # Finalize final-report |
2202 | 2215 | finalize_url = f"/api/v2/dref-final-report/{final_report.id}/finalize/" |
2203 | | - response = self.client.post(finalize_url) |
2204 | | - self.assert_200(response) |
2205 | | - self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
2206 | | - self.assertEqual(response.data["translation_module_original_language"], "en") |
| 2216 | + # Finalize without translation |
| 2217 | + with patch("dref.views.is_translation_complete", return_value=False): |
| 2218 | + response = self.client.post(finalize_url) |
| 2219 | + self.assert_400(response) |
| 2220 | + # Finalize with translation complete |
| 2221 | + with patch("dref.views.is_translation_complete", return_value=True): |
| 2222 | + response = self.client.post(finalize_url) |
| 2223 | + self.assert_200(response) |
| 2224 | + self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
| 2225 | + self.assertEqual(response.data["translation_module_original_language"], "en") |
2207 | 2226 | # Update in English |
2208 | 2227 | finalized_final_report_id = response.data["id"] |
2209 | 2228 | data_en = {"title": "Updated title in English", "modified_at": datetime.now()} |
|
0 commit comments