1414from tableauserverclient .server .endpoint .exceptions import InternalServerError
1515from tableauserverclient .server .endpoint .fileuploads_endpoint import Fileuploads
1616from tableauserverclient .server .request_factory import RequestFactory
17- from ._utils import read_xml_asset , read_xml_assets , asset
17+ from ._utils import data_asset_path , read_xml_asset , read_xml_assets , xml_asset_path
1818
1919ADD_TAGS_XML = "datasource_add_tags.xml"
2020GET_XML = "datasource_get.xml"
@@ -135,7 +135,7 @@ def test_update(self) -> None:
135135 self .assertEqual (updated_datasource .certification_note , single_datasource .certification_note )
136136
137137 def test_update_copy_fields (self ) -> None :
138- with open (asset (UPDATE_XML ), "rb" ) as f :
138+ with open (xml_asset_path (UPDATE_XML ), "rb" ) as f :
139139 response_xml = f .read ().decode ("utf-8" )
140140 with requests_mock .mock () as m :
141141 m .put (self .baseurl + "/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb" , text = response_xml )
@@ -218,7 +218,7 @@ def test_update_connection(self) -> None:
218218 self .assertEqual ("foo" , new_connection .username )
219219
220220 def test_populate_permissions (self ) -> None :
221- with open (asset (POPULATE_PERMISSIONS_XML ), "rb" ) as f :
221+ with open (xml_asset_path (POPULATE_PERMISSIONS_XML ), "rb" ) as f :
222222 response_xml = f .read ().decode ("utf-8" )
223223 with requests_mock .mock () as m :
224224 m .get (self .baseurl + "/0448d2ed-590d-4fa0-b272-a2a8a24555b5/permissions" , text = response_xml )
@@ -256,7 +256,9 @@ def test_publish(self) -> None:
256256 new_datasource = TSC .DatasourceItem ("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" , "SampleDS" )
257257 publish_mode = self .server .PublishMode .CreateNew
258258
259- new_datasource = self .server .datasources .publish (new_datasource , asset ("SampleDS.tds" ), mode = publish_mode )
259+ new_datasource = self .server .datasources .publish (
260+ new_datasource , data_asset_path ("SampleDS.tds" ), mode = publish_mode
261+ )
260262
261263 self .assertEqual ("e76a1461-3b1d-4588-bf1b-17551a879ad9" , new_datasource .id )
262264 self .assertEqual ("SampleDS" , new_datasource .name )
@@ -275,7 +277,7 @@ def test_publish_a_non_packaged_file_object(self) -> None:
275277 new_datasource = TSC .DatasourceItem ("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" , "SampleDS" )
276278 publish_mode = self .server .PublishMode .CreateNew
277279
278- with open (asset ("SampleDS.tds" ), "rb" ) as file_object :
280+ with open (data_asset_path ("SampleDS.tds" ), "rb" ) as file_object :
279281 new_datasource = self .server .datasources .publish (new_datasource , file_object , mode = publish_mode )
280282
281283 self .assertEqual ("e76a1461-3b1d-4588-bf1b-17551a879ad9" , new_datasource .id )
@@ -298,7 +300,7 @@ def test_publish_a_packaged_file_object(self) -> None:
298300 # Create a dummy tdsx file in memory
299301 with BytesIO () as zip_archive :
300302 with ZipFile (zip_archive , "w" ) as zf :
301- zf .write (asset ("SampleDS.tds" ))
303+ zf .write (data_asset_path ("SampleDS.tds" ))
302304
303305 zip_archive .seek (0 )
304306
@@ -324,7 +326,7 @@ def test_publish_async(self) -> None:
324326 publish_mode = self .server .PublishMode .CreateNew
325327
326328 new_job = self .server .datasources .publish (
327- new_datasource , asset ("SampleDS.tds" ), mode = publish_mode , as_job = True
329+ new_datasource , data_asset_path ("SampleDS.tds" ), mode = publish_mode , as_job = True
328330 )
329331
330332 self .assertEqual ("9a373058-af5f-4f83-8662-98b3e0228a73" , new_job .id )
@@ -337,7 +339,7 @@ def test_publish_unnamed_file_object(self) -> None:
337339 new_datasource = TSC .DatasourceItem ("test" )
338340 publish_mode = self .server .PublishMode .CreateNew
339341
340- with open (asset ("SampleDS.tds" ), "rb" ) as file_object :
342+ with open (data_asset_path ("SampleDS.tds" ), "rb" ) as file_object :
341343 self .assertRaises (ValueError , self .server .datasources .publish , new_datasource , file_object , publish_mode )
342344
343345 def test_refresh_id (self ) -> None :
@@ -466,7 +468,7 @@ def test_update_hyper_data_datasource_payload_file(self) -> None:
466468 text = response_xml ,
467469 )
468470 new_job = self .server .datasources .update_hyper_data (
469- datasource_id , request_id = "test_id" , actions = [], payload = asset ("World Indicators.hyper" )
471+ datasource_id , request_id = "test_id" , actions = [], payload = data_asset_path ("World Indicators.hyper" )
470472 )
471473
472474 # We only check the `id`; remaining fields are already tested in `test_update_hyper_data_datasource_object`
@@ -551,28 +553,30 @@ def test_publish_missing_path(self) -> None:
551553
552554 def test_publish_missing_mode (self ) -> None :
553555 new_datasource = TSC .DatasourceItem ("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" , "test" )
554- self .assertRaises (ValueError , self .server .datasources .publish , new_datasource , asset ("SampleDS.tds" ), None )
556+ self .assertRaises (
557+ ValueError , self .server .datasources .publish , new_datasource , data_asset_path ("SampleDS.tds" ), None
558+ )
555559
556560 def test_publish_invalid_file_type (self ) -> None :
557561 new_datasource = TSC .DatasourceItem ("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" , "test" )
558562 self .assertRaises (
559563 ValueError ,
560564 self .server .datasources .publish ,
561565 new_datasource ,
562- asset ("SampleWB.twbx" ),
566+ data_asset_path ("SampleWB.twbx" ),
563567 self .server .PublishMode .Append ,
564568 )
565569
566570 def test_publish_hyper_file_object_raises_exception (self ) -> None :
567571 new_datasource = TSC .DatasourceItem ("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" , "test" )
568- with open (asset ("World Indicators.hyper" ), "rb" ) as file_object :
572+ with open (data_asset_path ("World Indicators.hyper" ), "rb" ) as file_object :
569573 self .assertRaises (
570574 ValueError , self .server .datasources .publish , new_datasource , file_object , self .server .PublishMode .Append
571575 )
572576
573577 def test_publish_tde_file_object_raises_exception (self ) -> None :
574578 new_datasource = TSC .DatasourceItem ("ee8c6e70-43b6-11e6-af4f-f7b0d8e20760" , "test" )
575- tds_asset = asset ( os . path . join ( "Data" , "Tableau Samples" , " World Indicators.tde") )
579+ tds_asset = data_asset_path ( " World Indicators.tde" )
576580 with open (tds_asset , "rb" ) as file_object :
577581 self .assertRaises (
578582 ValueError , self .server .datasources .publish , new_datasource , file_object , self .server .PublishMode .Append
@@ -645,7 +649,7 @@ def test_synchronous_publish_timeout_error(self) -> None:
645649 "Please use asynchronous publishing to avoid timeouts." ,
646650 self .server .datasources .publish ,
647651 new_datasource ,
648- asset ("SampleDS.tds" ),
652+ data_asset_path ("SampleDS.tds" ),
649653 publish_mode ,
650654 )
651655
0 commit comments