Skip to content

Commit 56a366c

Browse files
author
Rodion Yaryy
authored
Merge pull request #134 from Labelbox/rodion/export_issues
Add an ability to export issues in SDK
2 parents bd69cd6 + f1955fb commit 56a366c

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

labelbox/schema/project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,40 @@ def export_labels(self, timeout_seconds=60):
177177
self.uid)
178178
time.sleep(sleep_time)
179179

180+
def export_issues(self, status=None):
181+
""" Calls the server-side Issues exporting that
182+
returns the URL to that payload.
183+
184+
Args:
185+
status (string): valid values: Open, Resolved
186+
Returns:
187+
URL of the data file with this Project's issues.
188+
"""
189+
id_param = "projectId"
190+
status_param = "status"
191+
query_str = """query GetProjectIssuesExportPyApi($%s: ID!, $%s: IssueStatus) {
192+
project(where: { id: $%s }) {
193+
issueExportUrl(where: { status: $%s })
194+
}
195+
}""" % (id_param, status_param, id_param, status_param)
196+
197+
valid_statuses = {None, "Open", "Resolved"}
198+
199+
if status not in valid_statuses:
200+
raise ValueError("status must be in {}. Found {}".format(
201+
valid_statuses, status))
202+
203+
res = self.client.execute(query_str, {
204+
id_param: self.uid,
205+
status_param: status
206+
})
207+
208+
res = res['project']
209+
210+
logger.debug("Project '%s' issues export, link generated", self.uid)
211+
212+
return res.get('issueExportUrl')
213+
180214
def upsert_instructions(self, instructions_file: str):
181215
"""
182216
* Uploads instructions to the UI. Running more than once will replace the instructions

tests/integration/test_issues.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
4+
def test_issues_export(project):
5+
exported_issues_url = project.export_issues()
6+
assert exported_issues_url
7+
8+
exported_issues_url = project.export_issues("Open")
9+
assert exported_issues_url
10+
assert "?status=Open" in exported_issues_url
11+
12+
exported_issues_url = project.export_issues("Resolved")
13+
assert exported_issues_url
14+
assert "?status=Resolved" in exported_issues_url
15+
16+
invalidStatusValue = "Closed"
17+
with pytest.raises(ValueError) as exc_info:
18+
exported_issues_url = project.export_issues(invalidStatusValue)
19+
assert "status must be in" in str(exc_info.value)
20+
assert "Found %s" % (invalidStatusValue) in str(exc_info.value)

0 commit comments

Comments
 (0)