Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,24 @@ def work_schedule_update(

return self._call_rpc("work_schedule_update", params)

def export_page(self, format, page_id):
"""
Export the specified page to the given format.
This method allows you to export a page to a specific format such as CSV.
>>> sg.export_page("csv", 12345)
"ID,Name,Status\n1,Shot 001,ip\n2,Shot 002,rev\n"
:param str format: The format to export the page to. Supported formats are ``"csv"``
:param int page_id: The ID of the page to export.
:returns: string containing data of the given page.
:rtype: string
"""

params = dict(
format=format, page_id=page_id
)

return self._call_rpc("export_page", params)

def follow(self, user, entity):
"""
Add the entity to the user's followed entities.
Expand Down
29 changes: 29 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,35 @@ def test_include_archived_projects(self):
# unarchive project
self.sg.update("Project", self.project["id"], {"archived": False})

class TestExportPage(base.LiveTestBase):

def test_export_page_unavailable(self):
"""Test export_page raises when report does not exist."""
if not self.sg.server_caps.version or self.sg.server_caps.version < (5, 1, 22):
return

page_entity = self.sg.create("Page", {"entity_type": "Shot"})
with self.assertRaises(Exception) as cm:
self.sg.export_page('csv', page_entity["id"])
self.assertIn(f"Report for Page id={page_entity['id']} does not exist", str(cm.exception))

def test_export_page_format_missing(self):
"""Test export_page raises for invalid format."""
if not self.sg.server_caps.version or self.sg.server_caps.version < (5, 1, 22):
return

with self.assertRaises(Exception) as cm:
self.sg.export_page(None, 11)
self.assertIn("\'format\' missing", str(cm.exception))

def test_export_page_missing_page_id(self):
"""Test export_page raises for missing page id."""
if not self.sg.server_caps.version or self.sg.server_caps.version < (5, 1, 22):
return

with self.assertRaises(Exception) as cm:
self.sg.export_page('csv', None)
self.assertIn("\'page_id\' missing", str(cm.exception))

class TestFollow(base.LiveTestBase):

Expand Down
Loading