diff --git a/contributing.md b/contributing.md index fc8502b11..d6f01c4f4 100644 --- a/contributing.md +++ b/contributing.md @@ -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 ``` diff --git a/tableauserverclient/server/endpoint/workbooks_endpoint.py b/tableauserverclient/server/endpoint/workbooks_endpoint.py index 293f2166d..bb8dab461 100644 --- a/tableauserverclient/server/endpoint/workbooks_endpoint.py +++ b/tableauserverclient/server/endpoint/workbooks_endpoint.py @@ -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)) @@ -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])) diff --git a/tableauserverclient/server/request_factory.py b/tableauserverclient/server/request_factory.py index 2a16f5a8f..b17ffd2bf 100644 --- a/tableauserverclient/server/request_factory.py +++ b/tableauserverclient/server/request_factory.py @@ -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") @@ -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: @@ -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 = { @@ -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")} diff --git a/test/test_workbook.py b/test/test_workbook.py index 807168581..73c46f1e5 100644 --- a/test/test_workbook.py +++ b/test/test_workbook.py @@ -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: @@ -598,6 +598,31 @@ def test_publish_with_hidden_view(self) -> None: self.assertTrue(re.search(rb"<\/views>", request_body)) self.assertTrue(re.search(rb"<\/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>", request_body)) + self.assertTrue(re.search(rb"<\/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")