From 8bbc6a6786099a178d829c926bf39291ad1b8650 Mon Sep 17 00:00:00 2001 From: Om Aximani <75031769+OmAximani0@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:51:02 +0530 Subject: [PATCH] feat: Support for `includePreTranslatedStringsOnly` (#124) - Added other missing params - Added missing functions Signed-off-by: OmAxiani0 <75031769+OmAximani0@users.noreply.github.com> --- crowdin_api/api_resources/tasks/enums.py | 28 +++ crowdin_api/api_resources/tasks/resource.py | 116 +++++++++++ .../tasks/tests/test_tasks_resources.py | 185 ++++++++++++++++++ 3 files changed, 329 insertions(+) diff --git a/crowdin_api/api_resources/tasks/enums.py b/crowdin_api/api_resources/tasks/enums.py index 7a9fc8e..5a52c8a 100644 --- a/crowdin_api/api_resources/tasks/enums.py +++ b/crowdin_api/api_resources/tasks/enums.py @@ -44,6 +44,12 @@ class CrowdinTaskStatus(Enum): CLOSED = "closed" +# Language Service +class LanguageServiceTaskType(Enum): + TRANSLATE_BY_VENDOR = 2 + PROOFREAD_BY_VENDOR = 3 + + # Oht class OhtCrowdinTaskType(Enum): TRANSLATE_BY_VENDOR = 2 @@ -153,3 +159,25 @@ class TranslatedCrowdinTaskSubjects(Enum): SOCIAL_SCIENCE = "social_science" TELECOMMUNICATIONS = "telecommunications" TRAVEL_TOURISM = "travel_tourism" + + +# Manual +class ManualCrowdinTaskType(Enum): + TRANSLATE_BY_VENDOR = 2 + PROOFREAD_BY_VENDOR = 3 + + +class ManualCrowdinVendors(Enum): + ALCONOST = "alconost" + BABBLE_ON = "babbleon" + TOMEDES = "tomedes" + E2F = "e2f" + WRITE_PATH = "write_path_admin" + INLINGO = "inlingo" + ACCLARO = "acclaro" + TRANSLATE_BY_HUMANS = "translate_by_humans" + LINGO24 = "lingo24" + ASSERTIO_LANGUAGE_SERVICE = "assertio_language_services" + GTE_LOCALIZE = "gte_localize" + KETTU_SOLUTIONS = "kettu_solutions" + LANGUAGELINE_TRANSLATION_SOLUTIONS = "languageline_solutions" diff --git a/crowdin_api/api_resources/tasks/resource.py b/crowdin_api/api_resources/tasks/resource.py index 1a60ee3..efde67b 100644 --- a/crowdin_api/api_resources/tasks/resource.py +++ b/crowdin_api/api_resources/tasks/resource.py @@ -5,6 +5,7 @@ from crowdin_api.api_resources.tasks.enums import ( CrowdinGeneralTaskType, CrowdinTaskStatus, + LanguageServiceTaskType, GengoCrowdinTaskExpertise, GengoCrowdinTaskPurpose, GengoCrowdinTaskTone, @@ -14,6 +15,8 @@ TranslatedCrowdinTaskExpertise, TranslatedCrowdinTaskSubjects, TranslatedCrowdinTaskType, + ManualCrowdinTaskType, + ManualCrowdinVendors, ) from crowdin_api.api_resources.tasks.types import ( CrowdinTaskAssignee, @@ -209,9 +212,12 @@ def add_general_task( splitFiles: Optional[bool] = None, skipAssignedStrings: Optional[bool] = None, skipUntranslatedStrings: Optional[bool] = None, + includePreTranslatedStringsOnly: Optional[bool] = None, labelIds: Optional[Iterable[int]] = None, + excludeLabelIds: Optional[Iterable[int]] = None, assignees: Optional[Iterable[CrowdinTaskAssignee]] = None, deadline: Optional[datetime] = None, + startedAt: Optional[datetime] = None, dateFrom: Optional[datetime] = None, dateTo: Optional[datetime] = None, ): @@ -234,14 +240,61 @@ def add_general_task( "splitFiles": splitFiles, "skipAssignedStrings": skipAssignedStrings, "skipUntranslatedStrings": skipUntranslatedStrings, + "includePreTranslatedStringsOnly": includePreTranslatedStringsOnly, "labelIds": labelIds, + "excludeLabelIds": excludeLabelIds, "assignees": assignees, "deadline": deadline, + "startedAt": startedAt, "dateFrom": dateFrom, "dateTo": dateTo, }, ) + def add_language_service_task( + self, + projectId: int, + title: str, + languageId: str, + fileIds: Iterable[str], + type: LanguageServiceTaskType, + status: Optional[CrowdinTaskStatus] = None, + description: Optional[str] = None, + labelIds: Optional[Iterable[int]] = None, + excludeLabelIds: Optional[Iterable[int]] = None, + skipUntranslatedStrings: Optional[bool] = None, + includePreTranslatedStringsOnly: Optional[bool] = None, + includeUntranslatedStringsOnly: Optional[bool] = None, + dateFrom: Optional[datetime] = None, + dateTo: Optional[datetime] = None, + ): + """ + Add Task(Crowdin Language Service Task Create Form). + + Link to documentation: + https://developer.crowdin.com/api/v2/#operation/api.projects.tasks.post + """ + + return self.add_task( + projectId=projectId, + request_data={ + "title": title, + "languageId": languageId, + "fileIds": fileIds, + "type": type, + "vendor": "crowdin_language_service", + "status": status, + "description": description, + "labelIds": labelIds, + "excludeLabelIds": excludeLabelIds, + "skipUntranslatedStrings": skipUntranslatedStrings, + "includePreTranslatedStringsOnly": includePreTranslatedStringsOnly, + "includeUntranslatedStringsOnly": includeUntranslatedStringsOnly, + "dateFrom": dateFrom, + "dateTo": dateTo, + } + ) + def add_vendor_oht_task( self, projectId: int, @@ -253,6 +306,10 @@ def add_vendor_oht_task( description: Optional[str] = None, expertise: Optional[OhtCrowdinTaskExpertise] = None, labelIds: Optional[Iterable[int]] = None, + excludeLabelIds: Optional[Iterable[int]] = None, + skipUntranslatedStrings: Optional[bool] = None, + includePreTranslatedStringsOnly: Optional[bool] = None, + includeUntranslatedStringsOnly: Optional[bool] = None, dateFrom: Optional[datetime] = None, dateTo: Optional[datetime] = None, ): @@ -274,6 +331,10 @@ def add_vendor_oht_task( "description": description, "expertise": expertise, "labelIds": labelIds, + "excludeLabelIds": excludeLabelIds, + "skipUntranslatedStrings": skipUntranslatedStrings, + "includePreTranslatedStringsOnly": includePreTranslatedStringsOnly, + "includeUntranslatedStringsOnly": includeUntranslatedStringsOnly, "dateFrom": dateFrom, "dateTo": dateTo, "vendor": "oht", @@ -296,6 +357,7 @@ def add_vendor_gengo_task( usePreferred: Optional[bool] = None, editService: Optional[bool] = None, labelIds: Optional[Iterable[int]] = None, + excludeLabelIds: Optional[Iterable[int]] = None, dateFrom: Optional[datetime] = None, dateTo: Optional[datetime] = None, ): @@ -322,6 +384,7 @@ def add_vendor_gengo_task( "usePreferred": usePreferred, "editService": editService, "labelIds": labelIds, + "excludeLabelIds": excludeLabelIds, "dateFrom": dateFrom, "dateTo": dateTo, "vendor": "gengo", @@ -340,6 +403,7 @@ def add_vendor_translated_task( expertise: Optional[TranslatedCrowdinTaskExpertise] = None, subject: Optional[TranslatedCrowdinTaskSubjects] = None, labelIds: Optional[Iterable[int]] = None, + excludeLabelIds: Optional[Iterable[int]] = None, dateFrom: Optional[datetime] = None, dateTo: Optional[datetime] = None, ): @@ -361,12 +425,64 @@ def add_vendor_translated_task( "expertise": expertise, "subject": subject, "labelIds": labelIds, + "excludeLabelIds": excludeLabelIds, "dateFrom": dateFrom, "dateTo": dateTo, "vender": "translated", }, ) + def add_vendor_manual_task( + self, + projectId: int, + title: str, + languageId: str, + fileIds: Iterable[int], + type: ManualCrowdinTaskType, + vendor: ManualCrowdinVendors, + status: Optional[CrowdinTaskStatus] = None, + description: Optional[str] = None, + skipAssignedStrings: Optional[bool] = None, + skipUntranslatedStrings: Optional[bool] = None, + includePreTranslatedStringsOnly: Optional[bool] = None, + labelIds: Optional[Iterable[int]] = None, + excludeLabelIds: Optional[Iterable[int]] = None, + assignees: Optional[Iterable[CrowdinTaskAssignee]] = None, + deadline: Optional[datetime] = None, + startedAt: Optional[datetime] = None, + dateFrom: Optional[datetime] = None, + dateTo: Optional[datetime] = None, + ): + """ + Add Task(Crowdin Vendor Manual Task Create Form). + + Link to documentation: + https://developer.crowdin.com/api/v2/#operation/api.projects.tasks.post + """ + + return self.add_task( + projectId=projectId, + request_data={ + "title": title, + "languageId": languageId, + "fileIds": fileIds, + "type": type, + "vendor": vendor, + "status": status, + "description": description, + "skipAssignedStrings": skipAssignedStrings, + "skipUntranslatedStrings": skipUntranslatedStrings, + "includePreTranslatedStringsOnly": includePreTranslatedStringsOnly, + "labelIds": labelIds, + "excludeLabelIds": excludeLabelIds, + "assignees": assignees, + "deadline": deadline, + "startedAt": startedAt, + "dateFrom": dateFrom, + "dateTo": dateTo, + } + ) + def export_task_strings(self, projectId: int, taskId: int): """ Export Task Strings. diff --git a/crowdin_api/api_resources/tasks/tests/test_tasks_resources.py b/crowdin_api/api_resources/tasks/tests/test_tasks_resources.py index 88b6adf..f3c98d4 100644 --- a/crowdin_api/api_resources/tasks/tests/test_tasks_resources.py +++ b/crowdin_api/api_resources/tasks/tests/test_tasks_resources.py @@ -17,6 +17,9 @@ TranslatedCrowdinTaskSubjects, TranslatedCrowdinTaskType, ConfigTaskOperationPatchPath, + LanguageServiceTaskType, + ManualCrowdinTaskType, + ManualCrowdinVendors, ) from crowdin_api.api_resources.tasks.resource import TasksResource, EnterpriseTasksResource from crowdin_api.requester import APIRequester @@ -204,9 +207,12 @@ def test_add_task(self, m_request, base_absolut_url): "splitFiles": None, "skipAssignedStrings": None, "skipUntranslatedStrings": None, + "includePreTranslatedStringsOnly": None, "labelIds": None, + "excludeLabelIds": None, "assignees": None, "deadline": None, + "startedAt": None, "dateFrom": None, "dateTo": None, }, @@ -222,9 +228,12 @@ def test_add_task(self, m_request, base_absolut_url): "splitFiles": False, "skipAssignedStrings": False, "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], "assignees": [{"id": 1, "wordsCount": 2}], "deadline": datetime(year=1988, month=9, day=26), + "startedAt": datetime(year=1966, month=2, day=1), "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -238,9 +247,12 @@ def test_add_task(self, m_request, base_absolut_url): "splitFiles": False, "skipAssignedStrings": False, "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], "assignees": [{"id": 1, "wordsCount": 2}], "deadline": datetime(year=1988, month=9, day=26), + "startedAt": datetime(year=1966, month=2, day=1), "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -255,6 +267,78 @@ def test_add_general_task(self, m_add_task, incoming_data, request_data, base_ab assert resource.add_general_task(projectId=1, **incoming_data) == "response" m_add_task.assert_called_once_with(projectId=1, request_data=request_data) + @pytest.mark.parametrize( + "incoming_data, request_data", + ( + ( + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": LanguageServiceTaskType.TRANSLATE_BY_VENDOR, + }, + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": LanguageServiceTaskType.TRANSLATE_BY_VENDOR, + "vendor": "crowdin_language_service", + "status": None, + "description": None, + "labelIds": None, + "excludeLabelIds": None, + "skipUntranslatedStrings": None, + "includePreTranslatedStringsOnly": None, + "includeUntranslatedStringsOnly": None, + "dateFrom": None, + "dateTo": None, + }, + ), + ( + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": LanguageServiceTaskType.TRANSLATE_BY_VENDOR, + "status": CrowdinTaskStatus.TODO, + "description": "description", + "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], + "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, + "includeUntranslatedStringsOnly": False, + "dateFrom": datetime(year=1988, month=1, day=4), + "dateTo": datetime(year=2015, month=10, day=13), + }, + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": LanguageServiceTaskType.TRANSLATE_BY_VENDOR, + "vendor": "crowdin_language_service", + "status": CrowdinTaskStatus.TODO, + "description": "description", + "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], + "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, + "includeUntranslatedStringsOnly": False, + "dateFrom": datetime(year=1988, month=1, day=4), + "dateTo": datetime(year=2015, month=10, day=13), + }, + ), + ), + ) + @mock.patch("crowdin_api.api_resources.tasks.resource.TasksResource.add_task") + def test_add_language_service_task( + self, m_add_task, incoming_data, request_data, base_absolut_url + ): + m_add_task.return_value = "response" + + resource = self.get_resource(base_absolut_url) + assert resource.add_language_service_task(projectId=1, **incoming_data) == "response" + m_add_task.assert_called_once_with(projectId=1, request_data=request_data) + @pytest.mark.parametrize( "incoming_data, request_data", ( @@ -275,6 +359,10 @@ def test_add_general_task(self, m_add_task, incoming_data, request_data, base_ab "description": None, "expertise": None, "labelIds": None, + "excludeLabelIds": None, + "skipUntranslatedStrings": None, + "includePreTranslatedStringsOnly": None, + "includeUntranslatedStringsOnly": None, "dateFrom": None, "dateTo": None, }, @@ -289,6 +377,10 @@ def test_add_general_task(self, m_add_task, incoming_data, request_data, base_ab "description": "description", "expertise": OhtCrowdinTaskExpertise.AD_WORDS_BANNERS, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], + "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, + "includeUntranslatedStringsOnly": False, "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -302,6 +394,10 @@ def test_add_general_task(self, m_add_task, incoming_data, request_data, base_ab "description": "description", "expertise": OhtCrowdinTaskExpertise.AD_WORDS_BANNERS, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], + "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, + "includeUntranslatedStringsOnly": False, "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -341,6 +437,7 @@ def test_add_vendor_oht_task(self, m_add_task, incoming_data, request_data, base "usePreferred": None, "editService": None, "labelIds": None, + "excludeLabelIds": None, "dateFrom": None, "dateTo": None, }, @@ -360,6 +457,7 @@ def test_add_vendor_oht_task(self, m_add_task, incoming_data, request_data, base "usePreferred": True, "editService": True, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -378,6 +476,7 @@ def test_add_vendor_oht_task(self, m_add_task, incoming_data, request_data, base "usePreferred": True, "editService": True, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -413,6 +512,7 @@ def test_add_vendor_gengo_task(self, m_add_task, incoming_data, request_data, ba "expertise": None, "subject": None, "labelIds": None, + "excludeLabelIds": None, "dateFrom": None, "dateTo": None, }, @@ -428,6 +528,7 @@ def test_add_vendor_gengo_task(self, m_add_task, incoming_data, request_data, ba "expertise": TranslatedCrowdinTaskExpertise.ECONOMY, "subject": TranslatedCrowdinTaskSubjects.ART, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -442,6 +543,7 @@ def test_add_vendor_gengo_task(self, m_add_task, incoming_data, request_data, ba "expertise": TranslatedCrowdinTaskExpertise.ECONOMY, "subject": TranslatedCrowdinTaskSubjects.ART, "labelIds": [4, 5, 6], + "excludeLabelIds": [7, 8, 9], "dateFrom": datetime(year=1988, month=1, day=4), "dateTo": datetime(year=2015, month=10, day=13), }, @@ -458,6 +560,89 @@ def test_add_vendor_translated_task( assert resource.add_vendor_translated_task(projectId=1, **incoming_data) == "response" m_add_task.assert_called_once_with(projectId=1, request_data=request_data) + @pytest.mark.parametrize( + "incoming_data, request_data", + ( + ( + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": ManualCrowdinTaskType.TRANSLATE_BY_VENDOR, + "vendor": ManualCrowdinVendors.ACCLARO, + }, + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": ManualCrowdinTaskType.TRANSLATE_BY_VENDOR, + "vendor": ManualCrowdinVendors.ACCLARO, + "status": None, + "description": None, + "skipAssignedStrings": None, + "skipUntranslatedStrings": None, + "includePreTranslatedStringsOnly": None, + "labelIds": None, + "excludeLabelIds": None, + "assignees": None, + "deadline": None, + "startedAt": None, + "dateFrom": None, + "dateTo": None, + }, + ), + ( + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": ManualCrowdinTaskType.TRANSLATE_BY_VENDOR, + "vendor": ManualCrowdinVendors.ACCLARO, + "status": CrowdinTaskStatus.TODO, + "description": "description", + "skipAssignedStrings": False, + "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, + "labelIds": [1, 2, 3], + "excludeLabelIds": [4, 5, 6], + "assignees": [{"id": 1, "wordsCount": 2}], + "deadline": datetime(year=1988, month=9, day=26), + "startedAt": datetime(year=1966, month=2, day=1), + "dateFrom": datetime(year=1988, month=1, day=4), + "dateTo": datetime(year=2015, month=10, day=13), + }, + { + "title": "title", + "languageId": "ua", + "fileIds": [1, 2, 3], + "type": ManualCrowdinTaskType.TRANSLATE_BY_VENDOR, + "vendor": ManualCrowdinVendors.ACCLARO, + "status": CrowdinTaskStatus.TODO, + "description": "description", + "skipAssignedStrings": False, + "skipUntranslatedStrings": False, + "includePreTranslatedStringsOnly": False, + "labelIds": [1, 2, 3], + "excludeLabelIds": [4, 5, 6], + "assignees": [{"id": 1, "wordsCount": 2}], + "deadline": datetime(year=1988, month=9, day=26), + "startedAt": datetime(year=1966, month=2, day=1), + "dateFrom": datetime(year=1988, month=1, day=4), + "dateTo": datetime(year=2015, month=10, day=13), + }, + ), + ), + ) + @mock.patch("crowdin_api.api_resources.tasks.resource.TasksResource.add_task") + def test_add_vendor_manual_task( + self, m_add_task, incoming_data, request_data, base_absolut_url + ): + m_add_task.return_value = "response" + + resource = self.get_resource(base_absolut_url) + assert resource.add_vendor_manual_task(projectId=1, **incoming_data) == "response" + m_add_task.assert_called_once_with(projectId=1, request_data=request_data) + @mock.patch("crowdin_api.requester.APIRequester.request") def test_export_task_strings(self, m_request, base_absolut_url): m_request.return_value = "response"