8000 Adds skipConnectionCheck to publish workbook (#791) · mericleac/server-client-python@026bca8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 026bca8

Browse files
author
Chris Shin
authored
Adds skipConnectionCheck to publish workbook (tableau#791)
* Adds skipConnectionCheck flag to publish workbook * Removes unnecessary lines * Fixes style error
1 parent 857199b commit 026bca8

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

samples/publish_workbook.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def main():
3131
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
3232
help='desired logging level (set to error by default)')
3333
parser.add_argument('--as-job', '-a', help='Publishing asynchronously', action='store_true')
34+
parser.add_argument('--skip-connection-check', '-c', help='Skip live connection check', action='store_true')
3435
parser.add_argument('--site', '-S', default='', help='id (contentUrl) of site to sign into')
3536

3637
args = parser.parse_args()
@@ -71,11 +72,13 @@ def main():
7172
new_workbook = TSC.WorkbookItem(default_project.id)
7273
if args.as_job:
7374
new_job = server.workbooks.publish(new_workbook, args.filepath, overwrite_true,
74-
connections=all_connections, as_job=args.as_job)
75+
connections=all_connections, as_job=args.as_job,
76+
skip_connection_check=args.skip_connection_check)
7577
print("Workbook published. JOB ID: {0}".format(new_job.id))
7678
else:
7779
new_workbook = server.workbooks.publish(new_workbook, args.filepath, overwrite_true,
78-
connections=all_connections, as_job=args.as_job)
80+
connections=all_connections, as_job=args.as_job,
81+
skip_connection_check=args.skip_connection_check)
7982
print("Workbook published. ID: {0}".format(new_workbook.id))
8083
else:
8184
error = "The default project could not be found."

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def delete_permission(self, item, capability_item):
256256
def publish(
257257
self, workbook_item, file, mode,
258258
connection_credentials=None, connections=None, as_job=False,
259-
hidden_views=None
259+
hidden_views=None, skip_connection_check=False
260260
):
261261

262262
if connection_credentials is not None:
@@ -318,6 +318,9 @@ def publish(
318318
if as_job:
319319
url += '&{0}=true'.format('asJob')
320320

321+
if skip_connection_check:
322+
url += '&{0}=true'.format('skipConnectionCheck')
323+
321324
# Determine if chunking is required (64MB is the limit for single upload method)
322325
if file_size >= FILESIZE_LIMIT:
323326
logger.info('Publishing {0} to server with chunking method (workbook over 64MB)'.format(workbook_item.name))

test/test_workbook.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,28 @@ def test_publish_with_hidden_view(self):
544544
self.assertTrue(re.search(rb'<views><view.*?hidden=\"true\".*?\/><\/views>', request_body))
545545
self.assertTrue(re.search(rb'<views><view.*?name=\"GDP per capita\".*?\/><\/views>', request_body))
546546

547+
def test_publish_with_query_params(self):
548+
with open(PUBLISH_ASYNC_XML, 'rb') as f:
549+
response_xml = f.read().decode('utf-8')
550+
with requests_mock.mock() as m:
551+
m.post(self.baseurl, text=response_xml)
552+
553+
new_workbook = TSC.WorkbookItem(name='Sample',
554+
show_tabs=False,
555+
project_id='ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
556+
557+
sample_workbook = os.path.join(TEST_ASSET_DIR, 'SampleWB.twbx')
558+
publish_mode = self.server.PublishMode.CreateNew
559+
560+
self.server.workbooks.publish(new_workbook, sample_workbook, publish_mode,
561+
as_job=True, skip_connection_check=True)
562+
563+
request_query_params = m._adapter.request_history[0].qs
564+
self.assertTrue('asjob' in request_query_params)
565+
self.assertTrue(request_query_params['asjob'])
566+
self.assertTrue('skipconnectioncheck' in request_query_params)
567+
self.assertTrue(request_query_params['skipconnectioncheck'])
568+
547569
def test_publish_async(self):
548570
self.server.version = '3.0'
549571
baseurl = self.server.workbooks.baseurl

0 commit comments

Comments
 (0)
0