55import xml .etree .ElementTree as ET
66
77from tableauserverclient .datetime_helpers import format_datetime
8+ from tableauserverclient .server .endpoint .exceptions import InternalServerError
89from tableauserverclient .server .request_factory import RequestFactory
10+ from ._utils import asset
911
1012TEST_ASSET_DIR = os .path .join (os .path .dirname (__file__ ), 'assets' )
1113
@@ -319,11 +321,11 @@ def test_publish(self):
319321 show_tabs = False ,
320322 project_id = 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760' )
321323
322- sample_workbok = os .path .join (TEST_ASSET_DIR , 'SampleWB.twbx' )
324+ sample_workbook = os .path .join (TEST_ASSET_DIR , 'SampleWB.twbx' )
323325 publish_mode = self .server .PublishMode .CreateNew
324326
325327 new_workbook = self .server .workbooks .publish (new_workbook ,
326- sample_workbok ,
328+ sample_workbook ,
327329 publish_mode )
328330
329331 self .assertEqual ('a8076ca1-e9d8-495e-bae6-c684dbb55836' , new_workbook .id )
@@ -350,11 +352,11 @@ def test_publish_async(self):
350352 show_tabs = False ,
351353 project_id = 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760' )
352354
353- sample_workbok = os .path .join (TEST_ASSET_DIR , 'SampleWB.twbx' )
355+ sample_workbook = os .path .join (TEST_ASSET_DIR , 'SampleWB.twbx' )
354356 publish_mode = self .server .PublishMode .CreateNew
355357
356358 new_job = self .server .workbooks .publish (new_workbook ,
357- sample_workbok ,
359+ sample_workbook ,
358360 publish_mode ,
359361 as_job = True )
360362
@@ -421,3 +423,13 @@ def test_credentials_and_multi_connect_raises_exception(self):
421423 response = RequestFactory .Workbook ._generate_xml (new_workbook ,
422424 connection_credentials = connection_creds ,
423425 connections = [connection1 ])
426+
427+ def test_synchronous_publish_timeout_error (self ):
428+ with requests_mock .mock () as m :
429+ m .register_uri ('POST' , self .baseurl , status_code = 504 )
430+
431+ new_workbook = TSC .WorkbookItem (project_id = '' )
432+ publish_mode = self .server .PublishMode .CreateNew
433+
434+ self .assertRaisesRegexp (InternalServerError , 'Please use asynchronous publishing to avoid timeouts' ,
435+ self .server .workbooks .publish , new_workbook , asset ('SampleWB.twbx' ), publish_mode )
0 commit comments