Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion crowdin_api/api_resources/string_comments/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
StringCommentIssueType,
StringCommentType,
)
from crowdin_api.api_resources.string_comments.types import StringCommentPatchRequest
from crowdin_api.api_resources.string_comments.types import StringCommentPatchRequest, StringCommentBatchOpPatchRequest
from crowdin_api.sorting import Sorting


Expand Down Expand Up @@ -149,3 +149,24 @@ def edit_string_comment(
projectId=projectId, stringCommentId=stringCommentId
),
)

def string_comment_batch_operations(
self,
project_id: int,
data: Iterable[StringCommentBatchOpPatchRequest]
):
"""
String Comment Batch Operations.

Link to documentation:
https://support.crowdin.com/developer/api/v2/#tag/String-Comments/operation/api.projects.comments.batchPatch

Link to documentation for enterprise:
https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Comments/operation/api.projects.comments.batchPatch
"""

return self.requester.request(
method="patch",
path=f"projects/{project_id}/comments",
request_data=data,
)
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,78 @@ def test_edit_string_comment(self, m_request, base_absolut_url):
request_data=data,
path=resource.get_string_comments_path(projectId=1, stringCommentId=2),
)

@pytest.mark.parametrize(
"in_params, request_data",
(
(
[
{
"op": PatchOperation.REPLACE.value,
"path": "/2814/text",
"value": "some issue edited"
},
{
"op": PatchOperation.REPLACE.value,
"path": "/2814/issueStatus",
"value": "resolved"
},
{
"op": PatchOperation.ADD.value,
"path": "/-",
"value": {
"text": "some issue",
"stringId": 1,
"type": "issue",
"targetLanguageId": "en",
"issueType": "translation_mistake"
}
},
{
"op": PatchOperation.REMOVE.value,
"path": "/2815"
}
],
[
{
"op": "replace",
"path": "/2814/text",
"value": "some issue edited"
},
{
"op": "replace",
"path": "/2814/issueStatus",
"value": "resolved"
},
{
"op": "add",
"path": "/-",
"value": {
"text": "some issue",
"stringId": 1,
"type": "issue",
"targetLanguageId": "en",
"issueType": "translation_mistake"
}
},
{
"op": "remove",
"path": "/2815"
}
],
),
),
)
@mock.patch("crowdin_api.requester.APIRequester.request")
def test_string_comment_batch_operations(self, m_request, in_params, request_data, base_absolut_url):
m_request.return_value = "response"

project_id = 1

resource = self.get_resource(base_absolut_url)
assert resource.string_comment_batch_operations(project_id, in_params) == "response"
m_request.assert_called_once_with(
method="patch",
path=f"projects/{project_id}/comments",
request_data=request_data,
)
6 changes: 6 additions & 0 deletions crowdin_api/api_resources/string_comments/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ class StringCommentPatchRequest(TypedDict):
value: Any
op: PatchOperation
path: StringCommentPatchPath


class StringCommentBatchOpPatchRequest(TypedDict):
op: PatchOperation
path: str
value: Any
46 changes: 46 additions & 0 deletions crowdin_api/api_resources/string_translations/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from crowdin_api.api_resources.abstract.resources import BaseResource
from crowdin_api.api_resources.enums import DenormalizePlaceholders, PluralCategoryName
from crowdin_api.api_resources.string_translations.enums import VoteMark
from crowdin_api.api_resources.string_translations.types import (
ApprovalBatchOpPatchRequest,
TranslationBatchOpPatchRequest
)
from crowdin_api.sorting import Sorting


Expand Down Expand Up @@ -429,3 +433,45 @@ def cancel_vote(self, voteId: int, projectId: Optional[int] = None):
method="delete",
path=self.get_translation_votes_path(projectId=projectId, voteId=voteId),
)

def approval_batch_operations(
self,
project_id: int,
data: Iterable[ApprovalBatchOpPatchRequest]
):
"""
Approval Batch Operations

Link to documentation:
https://support.crowdin.com/developer/api/v2/#tag/String-Translations/operation/api.projects.approvals.patch

Link to documentation for enterprise:
https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Translations/operation/api.projects.approvals.patch
"""

return self.requester.request(
method="patch",
path=f"projects/{project_id}/approvals",
request_data=data,
)

def translation_batch_operations(
self,
project_id: int,
data: Iterable[TranslationBatchOpPatchRequest]
):
"""
Translation Batch Operations

Link to documentation:
https://support.crowdin.com/developer/api/v2/#tag/String-Translations/operation/api.projects.translations.patch

Link to documentation for enterprise:
https://support.crowdin.com/developer/enterprise/api/v2/#tag/String-Translations/operation/api.projects.translations.patch
"""

return self.requester.request(
method="patch",
path=f"projects/{project_id}/translations",
request_data=data,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import mock

import pytest
from crowdin_api.api_resources.enums import DenormalizePlaceholders
from crowdin_api.api_resources.enums import DenormalizePlaceholders, PatchOperation
from crowdin_api.api_resources.string_translations.enums import (
ListLanguageTranslationsOrderBy,
ListStringTranslationsOrderBy,
Expand Down Expand Up @@ -522,3 +522,105 @@ def test_cancel_vote(self, m_request, base_absolut_url):
method="delete",
path=resource.get_translation_votes_path(projectId=1, voteId=2),
)

@pytest.mark.parametrize(
"in_params, request_params",
(
(
[
{
"op": PatchOperation.ADD.value,
"path": "/-",
"value": {
"translationId": 200
}
},
{
"op": PatchOperation.REMOVE.value,
"path": "/2815"
}
],
[
{
"op": "add",
"path": "/-",
"value": {
"translationId": 200
}
},
{
"op": "remove",
"path": "/2815"
}
]
),
),
)
@mock.patch("crowdin_api.requester.APIRequester.request")
def test_approvals_batch_operations(self, m_request, in_params, request_params, base_absolut_url):
m_request.return_value = "response"

project_id = 1

resource = self.get_resource(base_absolut_url)
assert resource.approval_batch_operations(project_id, in_params) == "response"
m_request.assert_called_once_with(
method="patch",
path=f"projects/{project_id}/approvals",
request_data=request_params,
)

@pytest.mark.parametrize(
"in_params, request_params",
(
(
[
{
"op": PatchOperation.ADD.value,
"path": "/-",
"value": {
"stringId": 35434,
"languageId": "fr",
"text": "Цю стрічку перекладено",
"pluralCategoryName": "few",
"addToTm": False
}
},
{
"op": PatchOperation.REMOVE.value,
"path": "/2815"
}
],
[
{
"op": "add",
"path": "/-",
"value": {
"stringId": 35434,
"languageId": "fr",
"text": "Цю стрічку перекладено",
"pluralCategoryName": "few",
"addToTm": False
}
},
{
"op": "remove",
"path": "/2815"
}
]
),
),
)
@mock.patch("crowdin_api.requester.APIRequester.request")
def test_translation_batch_operations(self, m_request, in_params, request_params, base_absolut_url):
m_request.return_value = "response"

project_id = 1

resource = self.get_resource(base_absolut_url)
assert resource.translation_batch_operations(project_id, in_params) == "response"
m_request.assert_called_once_with(
method="patch",
path=f"projects/{project_id}/translations",
request_data=request_params,
)
15 changes: 15 additions & 0 deletions crowdin_api/api_resources/string_translations/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import TypedDict, Any

from crowdin_api.api_resources.enums import PatchOperation


class ApprovalBatchOpPatchRequest(TypedDict):
op: PatchOperation
path: str
value: Any


class TranslationBatchOpPatchRequest(TypedDict):
op: PatchOperation
path: str
value: Any