2424debug_log = "--logging-level=DEBUG"
2525indexing_sleep_time = 1 # wait 1 second to confirm server has indexed updates
2626
27- # object names
27+ # object names: helpful if they are always unique
2828unique = str (time .gmtime ().tm_sec )
29-
30- default_project_name = "default-proj" + unique
3129group_name = "test-ing-group" + unique
3230workbook_name = "wb_1_" + unique
33-
31+ default_project_name = "Personal Work" # "default-proj" + unique
3432parent_location = "parent" + unique
3533project_name = "test-proj-" + unique
3634
35+ # Flags to let us skip tests if we know we don't have the required access
3736server_admin = False
38- site_admin = True
39- project_admin = True
37+ site_admin = False
38+ project_admin = False
4039extract_encryption_enabled = False
4140use_tabcmd_classic = False # toggle between testing using tabcmd 2 or tabcmd classic
4241
4342
4443def _test_command (test_args : list [str ]):
4544 # this will raise an exception if it gets a non-zero return code
46- # that should bubble up and fail the test?
47- # using tabcmd 2
45+ # that will bubble up and fail the test
46+
47+ # default: run tests using tabcmd 2
4848 calling_args = ["python" , "-m" , "tabcmd" ] + test_args + [debug_log ] + ["--no-certcheck" ]
4949
5050 # call the executable directly: lets us drop in classic tabcmd
@@ -93,9 +93,11 @@ def _publish_samples(self, project_name):
9393 arguments = [command , "--name" , project_name ]
9494 _test_command (arguments )
9595
96- def _publish_args (self , file , name ):
96+ def _publish_args (self , file , name , optional_args = None ):
9797 command = "publish"
98- arguments = [command , file , "--name" , name , "--overwrite" ]
98+ arguments = [command , file , "--name" , name , "--project" , default_project_name , "--overwrite" ]
99+ if optional_args :
100+ arguments .append (optional_args )
99101 return arguments
100102
101103 def _publish_creds_args (
@@ -116,31 +118,52 @@ def _publish_creds_args(
116118 arguments .append ("--save-oauth" )
117119 return arguments
118120
119- def _delete_wb (self , file ):
121+ def _delete_wb (self , name ):
120122 command = "delete"
121- arguments = [command , file ]
123+ arguments = [command , "--project" , default_project_name , name ]
122124 _test_command (arguments )
123125
124- def _delete_ds (self , file ):
126+ def _delete_ds (self , name ):
125127 command = "delete"
126- arguments = [command , "--datasource" , file ]
128+ arguments = [command , "--project" , default_project_name , "-- datasource" , name ]
127129 _test_command (arguments )
128130
129- def _get_view (self , wb_name_on_server , sheet_name , filename = None ):
131+ def _get_view (self , wb_name_on_server , sheet_name , filename = None , additional_args = None ):
130132 server_file = "/views/" + wb_name_on_server + "/" + sheet_name
131133 command = "get"
132134 arguments = [command , server_file ]
133135 if filename :
134136 arguments = arguments + ["--filename" , filename ]
137+ if additional_args :
138+ arguments = arguments + additional_args
135139 _test_command (arguments )
136140
137141 def _get_custom_view (self ):
138142 # TODO
139143 command = "get"
140144
141- def _get_view_with_filters (self ):
142- # TODO
143- command = "get"
145+
146+
147+ def _export_wb (self , friendly_name , filename = None , additional_args = None ):
148+ command = "export"
149+ arguments = [command , friendly_name , "--fullpdf" ]
150+
151+ if filename :
152+ arguments = arguments + ["--filename" , filename ]
153+ if additional_args :
154+ arguments = arguments + additional_args
155+ _test_command (arguments )
156+
157+
158+ def _export_view (self , wb_name_on_server , sheet_name , export_type , filename = None , additional_args = None ):
159+ server_file = "/" + wb_name_on_server + "/" + sheet_name
160+ command = "export"
161+ arguments = [command , server_file , export_type ]
162+ if filename :
163+ arguments = arguments + ["--filename" , filename ]
164+ if additional_args :
165+ arguments = arguments + additional_args
166+ _test_command (arguments )
144167
145168 def _get_workbook (self , server_file ):
146169 command = "get"
@@ -157,34 +180,40 @@ def _get_datasource(self, server_file):
157180
158181 def _create_extract (self , type , wb_name ):
159182 command = "createextracts"
160- arguments = [command , type , wb_name ]
183+ arguments = [command , type , wb_name , "--project" , default_project_name ]
161184 if extract_encryption_enabled and not use_tabcmd_classic :
162185 arguments .append ("--encrypt" )
163186 _test_command (arguments )
164187
165188 # variation: url
166189 def _refresh_extract (self , type , wb_name ):
167190 command = "refreshextracts"
168- arguments = [command , wb_name ] # should not need -w
191+ arguments = [command , wb_name , "--project" , default_project_name , "-w" , ] # bug: should not need -w
169192 try :
170193 _test_command (arguments )
171194 except Exception as e :
172195 print (e )
173- print ("expected (tabcmd classic)" )
174- print (" *** Unexpected response from the server: Bad request" )
175- print ("This refresh extracts operation is not allowed for workbook World Indicators (errorCode=80030)" )
196+ if use_tabcmd_classic :
197+ print ("expected (tabcmd classic)" )
198+ print (" *** Unexpected response from the server: Bad request" )
199+ print ("This refresh extracts operation is not allowed for workbook World Indicators (errorCode=80030)" )
200+ else :
201+ raise e
176202
177203 def _delete_extract (self , type , item_name ):
178204 command = "deleteextracts"
179- arguments = [command , type , item_name , "--include-all" ]
205+ arguments = [command , type , item_name , "--include-all" , "--project" , default_project_name ]
180206 try :
181207 _test_command (arguments )
182208 except Exception as e :
183209 print (e )
184- print ("Expected (tabcmd classic:" )
185- print ("*** Unexpected response from the server: Unable to load Data Source" )
186- print ("Remove extract operation failed. (errorCode=310028)" )
187- print ("8530479: Remove Extract is not supported for this Datasources (errorCode=310030)" )
210+ if use_tabcmd_classic :
211+ print ("Expected (tabcmd classic):" )
212+ print ("*** Unexpected response from the server: Unable to load Data Source" )
213+ print ("Remove extract operation failed. (errorCode=310028)" )
214+ print ("8530479: Remove Extract is not supported for this Datasources (errorCode=310030)" )
215+ else :
216+ raise e
188217
189218 def _list (self , item_type : str ):
190219 command = "list"
@@ -421,38 +450,39 @@ def test__delete_ds_live(self):
421450 @pytest .mark .order (19 )
422451 def test_export_wb_pdf (self ):
423452 command = "export"
453+ wb_name_on_server = OnlineCommandTest .TWBX_WITH_EXTRACT_NAME
424454 friendly_name = (
425- OnlineCommandTest . TWBX_WITH_EXTRACT_NAME + "/" + OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET + "?param1=3"
455+ wb_name_on_server + "/" + OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET
426456 )
427- arguments = [ command , friendly_name , "--fullpdf" , "-f" , " exported_wb.pdf"]
428- _test_command ( arguments )
429-
457+ filename = " exported_wb.pdf"
458+ self . _export_wb ( friendly_name , filename )
459+
430460 @pytest .mark .order (19 )
431461 def test_export_data_csv (self ):
432- command = "export"
433- friendly_name = (
434- OnlineCommandTest .TWBX_WITH_EXTRACT_NAME + "/" + OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET + "?param1=3"
435- )
436- arguments = [command , friendly_name , "--csv" , "-f" , "exported_data.csv" ]
437- _test_command (arguments )
462+ wb_name_on_server = OnlineCommandTest .TWBX_WITH_EXTRACT_NAME
463+ sheet_name = OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET
464+ self ._export_view (wb_name_on_server , sheet_name , "--csv" , "exported_data.csv" )
438465
439466 @pytest .mark .order (19 )
440467 def test_export_view_png (self ):
441- command = "export"
442- friendly_name = (
443- OnlineCommandTest .TWBX_WITH_EXTRACT_NAME + "/" + OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET + "?param1=3"
444- )
445- arguments = [command , friendly_name , "--png" , "-f" , "exported_view.png" ]
446- _test_command (arguments )
468+ wb_name_on_server = OnlineCommandTest .TWBX_WITH_EXTRACT_NAME
469+ sheet_name = OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET
470+ self ._export_view (wb_name_on_server , sheet_name , "--png" , "export_view.png" )
447471
448472 @pytest .mark .order (19 )
449473 def test_export_view_pdf (self ):
450- command = "export"
451- friendly_name = (
452- OnlineCommandTest .TWBX_WITH_EXTRACT_NAME + "/" + OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET + "?param1=3"
453- )
454- arguments = [command , friendly_name , "--pdf" , "-f" , "exported_view.pdf" ]
455- _test_command (arguments )
474+ wb_name_on_server = OnlineCommandTest .TWBX_WITH_EXTRACT_NAME
475+ sheet_name = OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET
476+ self ._export_view (wb_name_on_server , sheet_name , "--pdf" , "export_view_pdf.pdf" )
477+
478+ @pytest .mark .order (19 )
479+ def test_export_view_filtered (self ):
480+ wb_name_on_server = OnlineCommandTest .TWBX_WITH_EXTRACT_NAME
481+ sheet_name = OnlineCommandTest .TWBX_WITH_EXTRACT_SHEET
482+ filename = "view_with_filters.pdf"
483+
484+ filters = ["--filter" , "Product Type=Tea" ]
485+ self ._export_view (wb_name_on_server , sheet_name , "--pdf" , filename , filters )
456486
457487 @pytest .mark .order (20 )
458488 def test_delete_site_users (self ):
0 commit comments