Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(labels): add the Screenshot Labels management APIs #134

Merged
merged 1 commit into from
Oct 24, 2023
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
36 changes: 36 additions & 0 deletions crowdin_api/api_resources/labels/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,42 @@ def edit_label(self, projectId: int, labelId: int, data: Iterable[LabelsPatchReq
request_data=data,
)

def get_screenshots_path(self, project_id: int, label_id: int):
return f"projects/{project_id}/labels/{label_id}/screenshots"

def assign_label_to_screenshots(self, project_id: int, label_id: int, screenshot_ids: Iterable[int]):
"""
Assign Label to Screenshots

Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.labels.screenshots.post
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.screenshots.post
"""

return self.requester.request(
method="post",
path=self.get_screenshots_path(project_id, label_id),
request_data={
"screenshotIds": screenshot_ids
}
)

def unassign_label_from_screenshots(self, project_id: int, label_id: int, screenshot_ids: Iterable[int]):
"""
Unassign Label from Screenshots

Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.labels.screenshots.deleteMany
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.screenshots.deleteMany
"""

query = ",".join(str(screenshot_id) for screenshot_id in screenshot_ids)

return self.requester.request(
method="delete",
path=f"{self.get_screenshots_path(project_id, label_id)}?screenshotIds={query}"
)

def assign_label_to_strings(self, projectId: int, labelId: int, stringIds: Iterable[int]):
"""
Assign Label to Strings.
Expand Down
47 changes: 47 additions & 0 deletions crowdin_api/api_resources/labels/tests/test_labels_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,53 @@ def test_edit_edit_label(self, m_request, base_absolut_url):
path=resource.get_labels_path(projectId=1, labelId=2),
)

@pytest.mark.parametrize(
"in_params, body",
[
(
[1, 2, 3],
{
"screenshotIds": [1, 2, 3]
}
)
]
)
@mock.patch("crowdin_api.requester.APIRequester.request")
def test_assign_label_to_screenshots(self, m_request, in_params, body, base_absolut_url):
m_request.return_value = "response"

resource = self.get_resource(base_absolut_url)
assert (
resource.assign_label_to_screenshots(project_id=1, label_id=2, screenshot_ids=in_params)
)
m_request.assert_called_once_with(
request_data=body,
method="post",
path=resource.get_screenshots_path(1, 2)
)

@pytest.mark.parametrize(
"in_params, query_string",
[
(
[1, 2, 3],
"1,2,3"
)
]
)
@mock.patch("crowdin_api.requester.APIRequester.request")
def test_unassign_label_to_screenshots(self, m_request, in_params, query_string, base_absolut_url):
m_request.return_value = "response"

resource = self.get_resource(base_absolut_url)
assert (
resource.unassign_label_from_screenshots(project_id=1, label_id=2, screenshot_ids=in_params)
)
m_request.assert_called_once_with(
method="delete",
path=f"{resource.get_screenshots_path(1, 2)}?screenshotIds={query_string}"
)

@mock.patch("crowdin_api.requester.APIRequester.request")
def test_assign_label_to_strings(self, m_request, base_absolut_url):
m_request.return_value = "response"
Expand Down