Skip to content
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
4 changes: 4 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ black --line-length 120 tableauserverclient --check

# this will format the directory and code for you
black --line-length 120 tableauserverclient

# this will run type checking
pip install mypy
mypy --show-error-codes --disable-error-code misc --disable-error-code import tableauserverclient test
```
2 changes: 2 additions & 0 deletions tableauserverclient/server/endpoint/workbooks_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def publish(
workbook_item,
connection_credentials=conn_creds,
connections=connections,
hidden_views=hidden_views,
)
else:
logger.info("Publishing {0} to server".format(filename))
Expand All @@ -410,6 +411,7 @@ def publish(
file_contents,
connection_credentials=conn_creds,
connections=connections,
hidden_views=hidden_views,
)
logger.debug("Request xml: {0} ".format(xml_request[:1000]))

Expand Down
16 changes: 16 additions & 0 deletions tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def _generate_xml(
workbook_item,
connection_credentials=None,
connections=None,
hidden_views=None,
):
xml_request = ET.Element("tsRequest")
workbook_element = ET.SubElement(xml_request, "workbook")
Expand All @@ -856,6 +857,17 @@ def _generate_xml(
for connection in connections:
_add_connections_element(connections_element, connection)

if hidden_views is not None:
import warnings

warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
"the hidden_views parameter should now be set on the workbook directly",
DeprecationWarning,
)
if workbook_item.hidden_views is None:
workbook_item.hidden_views = hidden_views

if workbook_item.hidden_views is not None:
views_element = ET.SubElement(workbook_element, "views")
for view_name in workbook_item.hidden_views:
Expand Down Expand Up @@ -896,11 +908,13 @@ def publish_req(
file_contents,
connection_credentials=None,
connections=None,
hidden_views=None,
):
xml_request = self._generate_xml(
workbook_item,
connection_credentials=connection_credentials,
connections=connections,
hidden_views=hidden_views,
)

parts = {
Expand All @@ -914,11 +928,13 @@ def publish_req_chunked(
workbook_item,
connection_credentials=None,
connections=None,
hidden_views=None,
):
xml_request = self._generate_xml(
workbook_item,
connection_credentials=connection_credentials,
connections=connections,
hidden_views=hidden_views,
)

parts = {"request_payload": ("", xml_request, "text/xml")}
Expand Down
27 changes: 26 additions & 1 deletion test/test_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def test_publish_path_object(self) -> None:
self.assertEqual("GDP per capita", new_workbook.views[0].name)
self.assertEqual("RESTAPISample_0/sheets/GDPpercapita", new_workbook.views[0].content_url)

def test_publish_with_hidden_view(self) -> None:
def test_publish_with_hidden_views_on_workbook(self) -> None:
with open(PUBLISH_XML, "rb") as f:
response_xml = f.read().decode("utf-8")
with requests_mock.mock() as m:
Expand All @@ -598,6 +598,31 @@ def test_publish_with_hidden_view(self) -> None:
self.assertTrue(re.search(rb"<views><view.*?hidden=\"true\".*?\/><\/views>", request_body))
self.assertTrue(re.search(rb"<views><view.*?name=\"GDP per capita\".*?\/><\/views>", request_body))

# this tests the old method of including workbook views as a parameter for publishing
# should be removed when that functionality is removed
# see https://github.com/tableau/server-client-python/pull/617
def test_publish_with_hidden_view(self) -> None:
with open(PUBLISH_XML, "rb") as f:
response_xml = f.read().decode("utf-8")
with requests_mock.mock() as m:
m.post(self.baseurl, text=response_xml)

new_workbook = TSC.WorkbookItem(
name="Sample", show_tabs=False, project_id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760"
)

sample_workbook = os.path.join(TEST_ASSET_DIR, "SampleWB.twbx")
publish_mode = self.server.PublishMode.CreateNew

new_workbook = self.server.workbooks.publish(
new_workbook, sample_workbook, publish_mode, hidden_views=["GDP per capita"]
)

request_body = m._adapter.request_history[0]._request.body
# order of attributes in xml is unspecified
self.assertTrue(re.search(rb"<views><view.*?hidden=\"true\".*?\/><\/views>", request_body))
self.assertTrue(re.search(rb"<views><view.*?name=\"GDP per capita\".*?\/><\/views>", request_body))

def test_publish_with_query_params(self) -> None:
with open(PUBLISH_ASYNC_XML, "rb") as f:
response_xml = f.read().decode("utf-8")
Expand Down