|
11 | 11 | from rest_framework import status |
12 | 12 |
|
13 | 13 | from api.models import Country, DisasterType, District, Region, RegionName |
| 14 | +from api.utils import get_model_name |
14 | 15 | from deployments.factories.project import SectorFactory |
15 | 16 | from deployments.factories.user import UserFactory |
16 | 17 | from dref.factories.dref import ( |
@@ -999,9 +1000,9 @@ def test_dref_create_and_update_in_local_language( |
999 | 1000 | response = self.client.patch(url, data=data_en, format="json", HTTP_ACCEPT_LANGUAGE="en") |
1000 | 1001 | self.assert_400(response) |
1001 | 1002 |
|
1002 | | - @patch("dref.views.trigger_translation") |
| 1003 | + @patch("dref.views.translate_model_fields.delay") |
1003 | 1004 | @patch("dref.views.is_translation_complete") |
1004 | | - def test_update_and_finalize_dref(self, mock_is_translation_complete, mock_trigger_translation): |
| 1005 | + def test_update_and_finalize_dref(self, mock_is_translation_complete, mock_translation): |
1005 | 1006 | dref = DrefFactory.create( |
1006 | 1007 | title="Título original en español", |
1007 | 1008 | type_of_dref=Dref.DrefType.IMMINENT, |
@@ -1035,13 +1036,13 @@ def test_update_and_finalize_dref(self, mock_is_translation_complete, mock_trigg |
1035 | 1036 | mock_is_translation_complete.return_value = False |
1036 | 1037 | response = self.client.post(finalize_url) |
1037 | 1038 | self.assert_400(response) |
1038 | | - mock_trigger_translation.assert_called_once_with(dref) |
| 1039 | + mock_translation.assert_called_once_with(get_model_name(type(dref)), dref.pk) |
1039 | 1040 | # Test finalize with Translation completion |
1040 | | - mock_trigger_translation.reset_mock() |
| 1041 | + mock_translation.reset_mock() |
1041 | 1042 | mock_is_translation_complete.return_value = True |
1042 | 1043 | response = self.client.post(finalize_url) |
1043 | 1044 | self.assert_200(response) |
1044 | | - mock_trigger_translation.assert_not_called() |
| 1045 | + mock_translation.assert_not_called() |
1045 | 1046 | self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
1046 | 1047 | self.assertEqual(response.data["translation_module_original_language"], "en") |
1047 | 1048 |
|
@@ -1186,9 +1187,9 @@ def test_create_and_update_operational_update(self): |
1186 | 1187 | self.assert_200(response) |
1187 | 1188 | self.assertEqual(response.data["title"], "Titre en français") |
1188 | 1189 |
|
1189 | | - @patch("dref.views.trigger_translation") |
| 1190 | + @patch("dref.views.translate_model_fields.delay") |
1190 | 1191 | @patch("dref.views.is_translation_complete") |
1191 | | - def test_dref_operational_update_finalize(self, mock_is_translation_complete, mock_trigger_translation): |
| 1192 | + def test_dref_operational_update_finalize(self, mock_is_translation_complete, mock_translation): |
1192 | 1193 | # Create users |
1193 | 1194 | user1, user2 = UserFactory.create_batch(2) |
1194 | 1195 | dref = DrefFactory.create( |
@@ -1226,13 +1227,13 @@ def test_dref_operational_update_finalize(self, mock_is_translation_complete, mo |
1226 | 1227 | mock_is_translation_complete.return_value = False |
1227 | 1228 | response = self.client.post(finalize_url) |
1228 | 1229 | self.assert_400(response) |
1229 | | - mock_trigger_translation.assert_called_once_with(op_update) |
| 1230 | + mock_translation.assert_called_once_with(get_model_name(type(op_update)), op_update.pk) |
1230 | 1231 | # Test Finalize with translation complete |
1231 | | - mock_trigger_translation.reset_mock() |
| 1232 | + mock_translation.reset_mock() |
1232 | 1233 | mock_is_translation_complete.return_value = True |
1233 | 1234 | response = self.client.post(finalize_url) |
1234 | 1235 | self.assert_200(response) |
1235 | | - mock_trigger_translation.assert_not_called() |
| 1236 | + mock_translation.assert_not_called() |
1236 | 1237 | self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
1237 | 1238 | self.assertEqual(response.data["translation_module_original_language"], "en") |
1238 | 1239 | # Update in English |
@@ -2245,9 +2246,9 @@ def test_create_and_update_final_report(self): |
2245 | 2246 | self.assertEqual(response.data["translation_module_original_language"], "es") |
2246 | 2247 | self.assertEqual(response.data["title"], "Título en español") |
2247 | 2248 |
|
2248 | | - @patch("dref.views.trigger_translation") |
| 2249 | + @patch("dref.views.translate_model_fields.delay") |
2249 | 2250 | @patch("dref.views.is_translation_complete") |
2250 | | - def test_dref_final_report_finalize(self, mock_is_translation_complete, mock_trigger_translation): |
| 2251 | + def test_dref_final_report_finalize(self, mock_is_translation_complete, mock_translation): |
2251 | 2252 | region = Region.objects.create(name=RegionName.AFRICA) |
2252 | 2253 | country = Country.objects.create(name="Test country12", region=region) |
2253 | 2254 | # Create users |
@@ -2288,13 +2289,13 @@ def test_dref_final_report_finalize(self, mock_is_translation_complete, mock_tri |
2288 | 2289 | mock_is_translation_complete.return_value = False |
2289 | 2290 | response = self.client.post(finalize_url) |
2290 | 2291 | self.assert_400(response) |
2291 | | - mock_trigger_translation.assert_called_once_with(final_report) |
| 2292 | + mock_translation.assert_called_once_with(get_model_name(type(final_report)), final_report.pk) |
2292 | 2293 | # Test finalize with Translation completion |
2293 | | - mock_trigger_translation.reset_mock() |
| 2294 | + mock_translation.reset_mock() |
2294 | 2295 | mock_is_translation_complete.return_value = True |
2295 | 2296 | response = self.client.post(finalize_url) |
2296 | 2297 | self.assert_200(response) |
2297 | | - mock_trigger_translation.assert_not_called() |
| 2298 | + mock_translation.assert_not_called() |
2298 | 2299 | self.assertEqual(response.data["status"], Dref.Status.FINALIZED) |
2299 | 2300 | self.assertEqual(response.data["translation_module_original_language"], "en") |
2300 | 2301 |
|
|
0 commit comments