diff --git a/crowdin_api/api_resources/labels/resource.py b/crowdin_api/api_resources/labels/resource.py index 87ce376..2d9f528 100644 --- a/crowdin_api/api_resources/labels/resource.py +++ b/crowdin_api/api_resources/labels/resource.py @@ -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. diff --git a/crowdin_api/api_resources/labels/tests/test_labels_resources.py b/crowdin_api/api_resources/labels/tests/test_labels_resources.py index 2697e0e..239b13f 100644 --- a/crowdin_api/api_resources/labels/tests/test_labels_resources.py +++ b/crowdin_api/api_resources/labels/tests/test_labels_resources.py @@ -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"