Skip to content

Commit 40dda5b

Browse files
authored
feat: add pre_translation_batch_operations method (#249)
1 parent e698cd5 commit 40dda5b

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

crowdin_api/api_resources/translations/resource.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ def edit_pre_translation(
172172
request_data=data,
173173
)
174174

175+
def pre_translation_batch_operations(
176+
self,
177+
data: Iterable[EditPreTranslationScheme],
178+
projectId: Optional[int] = None,
179+
):
180+
"""
181+
Pre-Translation Batch Operations.
182+
183+
Link to documentation:
184+
https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.patchBatch
185+
"""
186+
projectId = projectId or self.get_project_id()
187+
188+
return self.requester.request(
189+
method="patch",
190+
path=f"projects/{projectId}/pre-translations",
191+
request_data=data,
192+
)
193+
175194
def build_project_directory_translation(
176195
self,
177196
directoryId: int,

crowdin_api/api_resources/translations/tests/test_translations_resources.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,31 @@ def test_edit_bundle(self, m_request, base_absolut_url):
277277
request_data=data,
278278
)
279279

280+
@mock.patch("crowdin_api.requester.APIRequester.request")
281+
def test_pre_translation_batch_operations(self, m_request, base_absolut_url):
282+
m_request.return_value = "response"
283+
284+
data = [
285+
{
286+
"op": PreTranslationEditOperation.REPLACE,
287+
"path": "/9e7de270-4f83-41cb-b606-2f90631f26e2/status",
288+
"value": "canceled",
289+
},
290+
{
291+
"op": PreTranslationEditOperation.REPLACE,
292+
"path": "/9e7de270-4f83-41cb-b606-2f90631f26e2/priority",
293+
"value": "high",
294+
},
295+
]
296+
297+
resource = self.get_resource(base_absolut_url)
298+
assert resource.pre_translation_batch_operations(projectId=1, data=data) == "response"
299+
m_request.assert_called_once_with(
300+
method="patch",
301+
path="projects/1/pre-translations",
302+
request_data=data,
303+
)
304+
280305
@pytest.mark.parametrize(
281306
"in_params, request_data, headers",
282307
(

0 commit comments

Comments
 (0)