Skip to content

Commit fa46eee

Browse files
authored
Added 3 new bundle functions with basic unit tests (#72)
1 parent 1838c8f commit fa46eee

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed

crowdin_api/api_resources/bundles/resource.py

+68-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ class BundlesResource(BaseResource):
1414
Link to documentation for enterprise:
1515
https://developer.crowdin.com/enterprise/api/v2/#tag/Bundles
1616
"""
17-
1817
def get_bundles_path(self, projectId: int, bundleId: Optional[int] = None):
1918
if bundleId:
2019
return f"projects/{projectId}/bundles/{bundleId}"
2120

2221
return f"projects/{projectId}/bundles"
2322

23+
def get_bundles_exports_path(self, projectId:int, bundleId:int, exportId: Optional[str] = None):
24+
bundles_path = self.get_bundles_path(projectId, bundleId)
25+
if exportId:
26+
return f"{bundles_path}/exports/{exportId}"
27+
return f"{bundles_path}/exports"
28+
2429
def list_bundles(
2530
self,
2631
projectId: int,
@@ -127,6 +132,68 @@ def edit_bundle(self, projectId: int, bundleId: int, data: Iterable[BundlePatchR
127132
request_data=data,
128133
)
129134

135+
def download_bundle(
136+
self,
137+
projectId: int,
138+
bundleId: int,
139+
exportId: str
140+
):
141+
"""
142+
Download bundle.
143+
144+
Link to documentation:
145+
https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.download.get
146+
147+
Link to documentation for enterprise:
148+
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.download.get
149+
"""
150+
151+
return self.requester.request(
152+
method="get",
153+
path=f"{self.get_bundles_exports_path(projectId=projectId, bundleId=bundleId, exportId=exportId)}/download",
154+
)
155+
156+
def export_bundle(
157+
self,
158+
projectId: int,
159+
bundleId: int
160+
):
161+
"""
162+
Export bundle.
163+
164+
Link to documentation:
165+
https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post
166+
167+
Link to documentation for enterprise:
168+
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.post
169+
"""
170+
171+
return self.requester.request(
172+
method="post",
173+
path=self.get_bundles_exports_path(projectId=projectId, bundleId=bundleId),
174+
)
175+
176+
def check_bundle_export_status(
177+
self,
178+
projectId: int,
179+
bundleId: int,
180+
exportId: str
181+
):
182+
"""
183+
Check Bundle Export Status.
184+
185+
Link to documentation:
186+
https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.get
187+
188+
Link to documentation for enterprise:
189+
https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.get
190+
"""
191+
192+
return self.requester.request(
193+
method="get",
194+
path=self.get_bundles_exports_path(projectId=projectId, bundleId=bundleId, exportId=exportId),
195+
)
196+
130197
def get_bundle_list_files(
131198
self,
132199
projectId: int,

crowdin_api/api_resources/bundles/tests/test_bundles_resources.py

+42-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@ def get_resource(self, base_absolut_url):
2121
({"projectId": 1, "bundleId": 1}, "projects/1/bundles/1"),
2222
),
2323
)
24-
def test_get_reports_path(self, incoming_data, path, base_absolut_url):
25-
24+
def test_get_bundles_path(self, incoming_data, path, base_absolut_url):
2625
resource = self.get_resource(base_absolut_url)
2726
assert resource.get_bundles_path(**incoming_data) == path
2827

28+
@pytest.mark.parametrize(
29+
"incoming_data, path",
30+
(
31+
({"projectId": 1, "bundleId": 2}, "projects/1/bundles/2/exports"),
32+
({"projectId": 1, "bundleId": 2, "exportId": "3"}, "projects/1/bundles/2/exports/3"),
33+
),
34+
)
35+
def test_get_bundles_exports_path(self, incoming_data, path, base_absolut_url):
36+
resource = self.get_resource(base_absolut_url)
37+
assert resource.get_bundles_exports_path(**incoming_data) == path
38+
2939
@mock.patch("crowdin_api.requester.APIRequester.request")
3040
def test_get_bundle(self, m_request, base_absolut_url):
3141
m_request.return_value = "response"
@@ -159,6 +169,36 @@ def test_edit_bundle(self, m_request, base_absolut_url, value):
159169
path=resource.get_bundles_path(projectId=1, bundleId=1),
160170
)
161171

172+
@mock.patch("crowdin_api.requester.APIRequester.request")
173+
def test_download_bundle(self, m_request, base_absolut_url):
174+
m_request.return_value = "response"
175+
176+
resource = self.get_resource(base_absolut_url)
177+
assert resource.download_bundle(projectId=1, bundleId=1, exportId="1") == "response"
178+
m_request.assert_called_once_with(
179+
method="get", path=f"{resource.get_bundles_exports_path(projectId=1, bundleId=1, exportId='1')}/download"
180+
)
181+
182+
@mock.patch("crowdin_api.requester.APIRequester.request")
183+
def test_export_bundle(self, m_request, base_absolut_url):
184+
m_request.return_value = "response"
185+
186+
resource = self.get_resource(base_absolut_url)
187+
assert resource.export_bundle(projectId=1, bundleId=1) == "response"
188+
m_request.assert_called_once_with(
189+
method="post", path=resource.get_bundles_exports_path(projectId=1, bundleId=1)
190+
)
191+
192+
@mock.patch("crowdin_api.requester.APIRequester.request")
193+
def test_check_bundle_export_status(self, m_request, base_absolut_url):
194+
m_request.return_value = "response"
195+
196+
resource = self.get_resource(base_absolut_url)
197+
assert resource.check_bundle_export_status(projectId=1, bundleId=1, exportId="1") == "response"
198+
m_request.assert_called_once_with(
199+
method="get", path=resource.get_bundles_exports_path(projectId=1, bundleId=1, exportId="1")
200+
)
201+
162202
@pytest.mark.parametrize(
163203
"incoming_data, request_params",
164204
(

0 commit comments

Comments
 (0)