Skip to content

Commit 72ad81f

Browse files
authored
feat(string-comments): add attachments support and delete attachment (#225)
1 parent b6d9323 commit 72ad81f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

crowdin_api/api_resources/string_comments/resource.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def add_string_comment(
6969
type: StringCommentType,
7070
projectId: Optional[int] = None,
7171
issueType: Optional[StringCommentIssueType] = None,
72+
attachments: Optional[Iterable[int]] = None,
7273
):
7374
"""
7475
Add String Comment.
@@ -88,6 +89,7 @@ def add_string_comment(
8889
"targetLanguageId": targetLanguageId,
8990
"type": type,
9091
"issueType": issueType,
92+
"attachments": attachments,
9193
},
9294
)
9395

@@ -127,6 +129,26 @@ def delete_string_comment(
127129
),
128130
)
129131

132+
def delete_string_comment_attachment(
133+
self, stringCommentId: int, attachmentId: int, projectId: Optional[int] = None
134+
):
135+
"""
136+
Delete String Comment Attachment.
137+
138+
Link to documentation:
139+
https://developer.crowdin.com/api/v2/#operation/api.projects.comments.attachments.delete
140+
"""
141+
142+
projectId = projectId or self.get_project_id()
143+
144+
return self.requester.request(
145+
method="delete",
146+
path=(
147+
f"{self.get_string_comments_path(projectId=projectId, stringCommentId=stringCommentId)}"
148+
f"/attachments/{attachmentId}"
149+
),
150+
)
151+
130152
def edit_string_comment(
131153
self,
132154
stringCommentId: int,

crowdin_api/api_resources/string_comments/tests/test_string_comments_resources.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def test_list_string_comments(self, m_request, in_params, request_params, base_a
110110
"targetLanguageId": "ua",
111111
"type": StringCommentType.COMMENT,
112112
"issueType": None,
113+
"attachments": None,
113114
},
114115
),
115116
(
@@ -119,13 +120,15 @@ def test_list_string_comments(self, m_request, in_params, request_params, base_a
119120
"targetLanguageId": "ua",
120121
"type": StringCommentType.COMMENT,
121122
"issueType": StringCommentIssueType.CONTEXT_REQUEST,
123+
"attachments": [1, 2, 3],
122124
},
123125
{
124126
"text": "text",
125127
"stringId": 1,
126128
"targetLanguageId": "ua",
127129
"type": StringCommentType.COMMENT,
128130
"issueType": StringCommentIssueType.CONTEXT_REQUEST,
131+
"attachments": [1, 2, 3],
129132
},
130133
),
131134
),
@@ -142,6 +145,17 @@ def test_add_string_comment(self, m_request, in_params, request_data, base_absol
142145
request_data=request_data,
143146
)
144147

148+
@mock.patch("crowdin_api.requester.APIRequester.request")
149+
def test_delete_string_comment_attachment(self, m_request, base_absolut_url):
150+
m_request.return_value = "response"
151+
152+
resource = self.get_resource(base_absolut_url)
153+
assert resource.delete_string_comment_attachment(projectId=1, stringCommentId=2, attachmentId=3) == "response"
154+
m_request.assert_called_once_with(
155+
method="delete",
156+
path=resource.get_string_comments_path(projectId=1, stringCommentId=2) + "/attachments/3",
157+
)
158+
145159
@mock.patch("crowdin_api.requester.APIRequester.request")
146160
def test_get_string_comment(self, m_request, base_absolut_url):
147161
m_request.return_value = "response"

0 commit comments

Comments
 (0)