diff --git a/WorldIndicators.tdsx b/WorldIndicators.tdsx new file mode 100644 index 00000000..4e4e0851 Binary files /dev/null and b/WorldIndicators.tdsx differ diff --git a/tests/assets/World Indicators.tds b/tests/assets/WorldIndicators.tds similarity index 100% rename from tests/assets/World Indicators.tds rename to tests/assets/WorldIndicators.tds diff --git a/tests/assets/World Indicators.tdsx b/tests/assets/WorldIndicators.tdsx similarity index 100% rename from tests/assets/World Indicators.tdsx rename to tests/assets/WorldIndicators.tdsx diff --git a/tests/assets/live_mysql.tds b/tests/assets/live_mysql.tds new file mode 100644 index 00000000..83bbec56 --- /dev/null +++ b/tests/assets/live_mysql.tds @@ -0,0 +1,878 @@ + + + + + + + + + + + + + + Item Count + 3 + [Item Count] + [staples] + Item Count + 1 + integer + Sum + 10 + false + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + Ship Priority + 129 + [Ship Priority] + [staples] + Ship Priority + 2 + string + Count + 14 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Order Priority + 129 + [Order Priority] + [staples] + Order Priority + 3 + string + Count + 15 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Order Status + 129 + [Order Status] + [staples] + Order Status + 4 + string + Count + 13 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Order Quantity + 5 + [Order Quantity] + [staples] + Order Quantity + 5 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Sales Total + 5 + [Sales Total] + [staples] + Sales Total + 6 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Discount + 5 + [Discount] + [staples] + Discount + 7 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Tax Rate + 5 + [Tax Rate] + [staples] + Tax Rate + 8 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Ship Mode + 129 + [Ship Mode] + [staples] + Ship Mode + 9 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Fill Time + 5 + [Fill Time] + [staples] + Fill Time + 10 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Gross Profit + 5 + [Gross Profit] + [staples] + Gross Profit + 11 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Price + 131 + [Price] + [staples] + Price + 12 + real + Sum + 18 + 4 + false + + "SQL_DECIMAL" + "SQL_C_NUMERIC" + + + + Ship Handle Cost + 131 + [Ship Handle Cost] + [staples] + Ship Handle Cost + 13 + real + Sum + 18 + 4 + false + + "SQL_DECIMAL" + "SQL_C_NUMERIC" + + + + Employee Name + 129 + [Employee Name] + [staples] + Employee Name + 14 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Employee Dept + 129 + [Employee Dept] + [staples] + Employee Dept + 15 + string + Count + 4 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Manager Name + 129 + [Manager Name] + [staples] + Manager Name + 16 + string + Count + 255 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Employee Yrs Exp + 5 + [Employee Yrs Exp] + [staples] + Employee Yrs Exp + 17 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Employee Salary + 131 + [Employee Salary] + [staples] + Employee Salary + 18 + real + Sum + 18 + 4 + false + + "SQL_DECIMAL" + "SQL_C_NUMERIC" + + + + Customer Name + 129 + [Customer Name] + [staples] + Customer Name + 19 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Customer State + 129 + [Customer State] + [staples] + Customer State + 20 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Call Center Region + 129 + [Call Center Region] + [staples] + Call Center Region + 21 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Customer Balance + 5 + [Customer Balance] + [staples] + Customer Balance + 22 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Customer Segment + 129 + [Customer Segment] + [staples] + Customer Segment + 23 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Prod Type1 + 129 + [Prod Type1] + [staples] + Prod Type1 + 24 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Prod Type2 + 129 + [Prod Type2] + [staples] + Prod Type2 + 25 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Prod Type3 + 129 + [Prod Type3] + [staples] + Prod Type3 + 26 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Prod Type4 + 129 + [Prod Type4] + [staples] + Prod Type4 + 27 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Product Name + 129 + [Product Name] + [staples] + Product Name + 28 + string + Count + 100 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Product Container + 129 + [Product Container] + [staples] + Product Container + 29 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Ship Promo + 129 + [Ship Promo] + [staples] + Ship Promo + 30 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Supplier Name + 129 + [Supplier Name] + [staples] + Supplier Name + 31 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Supplier Balance + 5 + [Supplier Balance] + [staples] + Supplier Balance + 32 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Supplier Region + 129 + [Supplier Region] + [staples] + Supplier Region + 33 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Supplier State + 129 + [Supplier State] + [staples] + Supplier State + 34 + string + Count + 50 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Order ID + 129 + [Order ID] + [staples] + Order ID + 35 + string + Count + 10 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Order Year + 3 + [Order Year] + [staples] + Order Year + 36 + integer + Sum + 10 + false + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + Order Month + 3 + [Order Month] + [staples] + Order Month + 37 + integer + Sum + 10 + false + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + Order Day + 3 + [Order Day] + [staples] + Order Day + 38 + integer + Sum + 10 + false + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + Order Date + 7 + [Order Date] + [staples] + Order Date + 39 + datetime + Year + false + + "SQL_TYPE_TIMESTAMP" + "SQL_C_TYPE_TIMESTAMP" + + + + Order Quarter + 129 + [Order Quarter] + [staples] + Order Quarter + 40 + string + Count + 2 + false + true + + + "SQL_CHAR" + "SQL_C_CHAR" + + + + Product Base Margin + 5 + [Product Base Margin] + [staples] + Product Base Margin + 41 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Product ID + 129 + [Product ID] + [staples] + Product ID + 42 + string + Count + 5 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + Receive Time + 5 + [Receive Time] + [staples] + Receive Time + 43 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Received Date + 7 + [Received Date] + [staples] + Received Date + 44 + datetime + Year + false + + "SQL_TYPE_TIMESTAMP" + "SQL_C_TYPE_TIMESTAMP" + + + + Ship Date + 7 + [Ship Date] + [staples] + Ship Date + 45 + datetime + Year + false + + "SQL_TYPE_TIMESTAMP" + "SQL_C_TYPE_TIMESTAMP" + + + + Ship Charge + 131 + [Ship Charge] + [staples] + Ship Charge + 46 + real + Sum + 18 + 4 + false + + "SQL_DECIMAL" + "SQL_C_NUMERIC" + + + + Total Cycle Time + 5 + [Total Cycle Time] + [staples] + Total Cycle Time + 47 + real + Sum + 15 + false + + "SQL_DOUBLE" + "SQL_C_DOUBLE" + + + + Product In Stock + 129 + [Product In Stock] + [staples] + Product In Stock + 48 + string + Count + 3 + false + true + + + "SQL_CHAR" + "SQL_C_CHAR" + + + + PID + 3 + [PID] + [staples] + PID + 49 + integer + Sum + 10 + false + + "SQL_INTEGER" + "SQL_C_SLONG" + + + + Market Segment + 129 + [Market Segment] + [staples] + Market Segment + 50 + string + Count + 25 + false + + + "SQL_VARCHAR" + "SQL_C_CHAR" + "true" + + + + + + + + + + + + + + + diff --git a/tests/assets/simple-data.twbx b/tests/assets/simple-data.twbx deleted file mode 100644 index bf8ad6df..00000000 Binary files a/tests/assets/simple-data.twbx and /dev/null differ diff --git a/tests/e2e/online_tests.py b/tests/e2e/online_tests.py index 1e1bc9ca..226fbf72 100644 --- a/tests/e2e/online_tests.py +++ b/tests/e2e/online_tests.py @@ -21,17 +21,9 @@ # you can either run setup with a stored credentials file, or simply log in # before running the suite so a session is active +# config variables for test run debug_log = "--logging-level=DEBUG" indexing_sleep_time = 1 # wait 1 second to confirm server has indexed updates - -# object names: helpful if they are always unique -unique = str(time.gmtime().tm_sec) -group_name = "test-ing-group" + unique -workbook_name = "wb_1_" + unique -default_project_name = "Personal Work" # "default-proj" + unique -parent_location = "parent" + unique -project_name = "test-proj-" + unique - # Flags to let us skip tests if we know we don't have the required access server_admin = False site_admin = True @@ -40,6 +32,44 @@ use_tabcmd_classic = False # toggle between testing using tabcmd 2 or tabcmd classic +default_project_name = "Personal Work" # not unique, has to exist already when you run random test cases + + +class TestAssets: + + unique = str(time.gmtime().tm_sec) + + # names unique for each test run + group_name = "test-ing-group" + unique + parent_location = "parent" + unique + + # if we publish something with a name that already exists, it will get a random int appended to the name + # to avoid this, we add our own random int to each name so we actually know what it is + # this is why we have workbook_name+unique everywhere + # BUG: this means you pretty much can't run a random individual test case without giving the already-unique name + @staticmethod + def get_publishable_name(file_value: str) -> str: + return os.path.splitext(os.path.basename(file_value))[0] + TestAssets.unique + + # assets for tests - these files are kept in the repo in tests/assets + TWBX_FILE_WITH_EXTRACT = "WorkbookWithExtract.twbx" + TWBX_WITH_EXTRACT_SHEET = "Sheet1" + + TWBX_FILE_WITHOUT_EXTRACT = "WorkbookWithoutExtract.twbx" + TWBX_WITHOUT_EXTRACT_SHEET = "Testsheet1" + + # problem: 803311: Remove Extract is not supported for this Datasources (errorCode=310030)) + TDSX_FILE_WITH_EXTRACT = "WorldIndicators.tdsx" + # WorldIndicators.tds + + TDS_FILE_LIVE = "live_mysql.tds" + + TWB_FILE_WITH_EMBEDDED_CONNECTION = "EmbeddedCredentials.twb" + + USERS_DETAILS_FILE = "detailed_users.csv" + USERNAMES_FILE = "usernames.csv" + + def _test_command(test_args: list[str]): # this will raise an exception if it gets a non-zero return code # that will bubble up and fail the test @@ -61,18 +91,12 @@ def _test_command(test_args: list[str]): return subprocess.check_call(calling_args) -class OnlineCommandTest(unittest.TestCase): - published = False - gotten = False - - @classmethod - def setup_class(cls): - print("running python -m") - # call this if we are using the built exe setup_e2e.prechecks() +class TabcmdCall: # Individual methods that implement a command - def _create_project(self, project_name, parent_path=None): + @staticmethod + def _create_project(project_name, parent_path=None): command = "createproject" arguments = [command, "--name", project_name] if parent_path: @@ -82,7 +106,8 @@ def _create_project(self, project_name, parent_path=None): arguments.append("--continue-if-exists") _test_command(arguments) - def _delete_project(self, project_name, parent_path=None): + @staticmethod + def _delete_project(project_name, parent_path=None): command = "deleteproject" arguments = [command, project_name] if parent_path: @@ -90,21 +115,22 @@ def _delete_project(self, project_name, parent_path=None): arguments.append(parent_path) _test_command(arguments) - def _publish_samples(self, project_name): + @staticmethod + def _publish_samples(project_name): command = "publishsamples" arguments = [command, "--name", project_name] _test_command(arguments) - def _publish_args(self, file, name, optional_args=None): + @staticmethod + def _publish_args(file, name, optional_args=None): command = "publish" arguments = [command, file, "--name", name, "--project", default_project_name, "--overwrite"] if optional_args: arguments.append(optional_args) return arguments - def _publish_creds_args( - self, arguments, db_user=None, db_pass=None, db_save=None, oauth_user=None, oauth_save=None - ): + @staticmethod + def _publish_creds_args(arguments, db_user=None, db_pass=None, db_save=None, oauth_user=None, oauth_save=None): if db_user: arguments.append("--db-username") arguments.append(db_user) @@ -120,17 +146,20 @@ def _publish_creds_args( arguments.append("--save-oauth") return arguments - def _delete_wb(self, name): + @staticmethod + def _delete_wb(name): command = "delete" arguments = [command, "--project", default_project_name, name] _test_command(arguments) - def _delete_ds(self, name): + @staticmethod + def _delete_ds(name): command = "delete" arguments = [command, "--project", default_project_name, "--datasource", name] _test_command(arguments) - def _get_view(self, wb_name_on_server, sheet_name, filename=None, additional_args=None): + @staticmethod + def _get_view(wb_name_on_server, sheet_name, filename=None, additional_args=None): server_file = "/views/" + wb_name_on_server + "/" + sheet_name command = "get" arguments = [command, server_file] @@ -140,11 +169,14 @@ def _get_view(self, wb_name_on_server, sheet_name, filename=None, additional_arg arguments = arguments + additional_args _test_command(arguments) + @staticmethod def _get_custom_view(self): # TODO command = "get" + raise NotImplementedError("get_custom_view is not implemented") - def _export_wb(self, friendly_name, filename=None, additional_args=None): + @staticmethod + def _export_wb(friendly_name, filename=None, additional_args=None): command = "export" arguments = [command, friendly_name, "--fullpdf"] @@ -154,7 +186,8 @@ def _export_wb(self, friendly_name, filename=None, additional_args=None): arguments = arguments + additional_args _test_command(arguments) - def _export_view(self, wb_name_on_server, sheet_name, export_type, filename=None, additional_args=None): + @staticmethod + def _export_view(wb_name_on_server, sheet_name, export_type, filename=None, additional_args=None): server_file = "/" + wb_name_on_server + "/" + sheet_name command = "export" arguments = [command, server_file, export_type] @@ -164,30 +197,34 @@ def _export_view(self, wb_name_on_server, sheet_name, export_type, filename=None arguments = arguments + additional_args _test_command(arguments) - def _get_workbook(self, server_file): + @staticmethod + def _get_workbook(server_file): command = "get" server_file = "/workbooks/" + server_file arguments = [command, server_file, "-f", "get_workbook.twbx"] _test_command(arguments) os.path.exists("get_workbook.twbx") - def _get_datasource(self, server_file): + @staticmethod + def _get_datasource(server_file): command = "get" server_file = "/datasources/" + server_file arguments = [command, server_file] _test_command(arguments) - def _create_extract(self, type, wb_name): + @staticmethod + def _create_extract(item_name, type="-w"): command = "createextracts" - arguments = [command, type, wb_name, "--project", default_project_name] + arguments = [command, type, item_name, "--project", default_project_name] if extract_encryption_enabled and not use_tabcmd_classic: arguments.append("--encrypt") _test_command(arguments) # variation: url - def _refresh_extract(self, type, wb_name): + @staticmethod + def _refresh_extract(item_name, type="-w"): command = "refreshextracts" - arguments = [command, "-w", wb_name, "--project", default_project_name] # bug: should not need -w + arguments = [command, type, item_name, "--project", default_project_name] # bug: should not need -w try: _test_command(arguments) except Exception as e: @@ -199,41 +236,43 @@ def _refresh_extract(self, type, wb_name): else: raise e - def _delete_extract(self, type, item_name): + @staticmethod + def _delete_extract(item_name, type="-w"): command = "deleteextracts" arguments = [command, type, item_name, "--include-all", "--project", default_project_name] - try: - _test_command(arguments) - except Exception as e: - print(e) - if use_tabcmd_classic: - print("Expected (tabcmd classic):") - print("*** Unexpected response from the server: Unable to load Data Source") - print("Remove extract operation failed. (errorCode=310028)") - print("8530479: Remove Extract is not supported for this Datasources (errorCode=310030)") - else: - raise e + _test_command(arguments) - def _list(self, item_type: str): + @staticmethod + def _list(item_type: str): command = "list" arguments = [command, item_type] _test_command(arguments) - # actual tests - TWBX_FILE_WITH_EXTRACT = "WorkbookWithExtract.twbx" - TWBX_WITH_EXTRACT_NAME = "WorkbookWithExtract" - TWBX_WITH_EXTRACT_SHEET = "Sheet1" - TWBX_FILE_WITHOUT_EXTRACT = "simple-data.twbx" - TWBX_WITHOUT_EXTRACT_NAME = "WorkbookWithoutExtract" - TWBX_WITHOUT_EXTRACT_SHEET = "Testsheet1" - TDSX_WITH_EXTRACT_NAME = "WorldIndicators" - TDSX_FILE_WITH_EXTRACT = "World Indicators.tdsx" - # fill in - TDS_FILE_LIVE_NAME = "SampleDS" - TDS_FILE_LIVE = "SampleDS.tds" - TWB_WITH_EMBEDDED_CONNECTION = "EmbeddedCredentials.twb" - EMBEDDED_TWB_NAME = "EmbeddedCredentials" +# test cases that use the API calls +class OnlineCommandTest(unittest.TestCase): + @classmethod + def setup_class(cls): + print("running python -m") + # call this if we are using the built exe setup_e2e.prechecks() + + # check for the required files in the test assets + @pytest.mark.order(0) + def test_asset_files_exist(self): + assets_dir = os.path.join("tests", "assets") + checks = [ + ("TWBX_FILE_WITH_EXTRACT", TestAssets.TWBX_FILE_WITH_EXTRACT), + ("TWBX_FILE_WITHOUT_EXTRACT", TestAssets.TWBX_FILE_WITHOUT_EXTRACT), + ("TDSX_FILE_WITH_EXTRACT", TestAssets.TDSX_FILE_WITH_EXTRACT), + ("TDS_FILE_LIVE", TestAssets.TDS_FILE_LIVE), + ("TWB_FILE_WITH_EMBEDDED_CONNECTION", TestAssets.TWB_FILE_WITH_EMBEDDED_CONNECTION), + ] + missing = [] + for var_name, filename in checks: + path = os.path.join(assets_dir, filename) + if not os.path.exists(path): + missing.append(f"{var_name} -> {path}") + assert not missing, "Missing asset files: " + ", ".join(missing) @pytest.mark.order(1) def test_login(self): @@ -252,12 +291,19 @@ def test_help(self): arguments = [command] _test_command(arguments) + @pytest.mark.order(1) + def test_publish_simple(self): + file = os.path.join("tests", "assets", TestAssets.TWBX_FILE_WITHOUT_EXTRACT) + name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITHOUT_EXTRACT) + arguments = TabcmdCall._publish_args(file, name_on_server) + _test_command(arguments) + @pytest.mark.order(2) def test_users_create_site_users(self): if not server_admin and not site_admin: pytest.skip("Must be server or site administrator to create site users") command = "createsiteusers" - users = os.path.join("tests", "assets", "detailed_users.csv") + users = os.path.join("tests", "assets", TestAssets.USERS_DETAILS_FILE) arguments = [command, users, "--role", "Publisher"] _test_command(arguments) @@ -265,7 +311,7 @@ def test_users_create_site_users(self): def test_group_creategroup(self): if not server_admin and not site_admin: pytest.skip("Must be server or site administrator to create groups") - groupname = group_name + groupname = TestAssets.group_name command = "creategroup" arguments = [command, groupname] if not use_tabcmd_classic: @@ -277,9 +323,9 @@ def test_users_add_to_group(self): if not server_admin and not site_admin: pytest.skip("Must be server or site administrator to add to groups") - groupname = group_name + groupname = TestAssets.group_name command = "addusers" - filename = os.path.join("tests", "assets", "usernames.csv") + filename = os.path.join("tests", "assets", TestAssets.USERNAMES_FILE) arguments = [command, groupname, "--users", filename] if not use_tabcmd_classic: arguments.append("--continue-if-exists") @@ -290,9 +336,9 @@ def test_users_remove_from_group(self): if not server_admin and not site_admin: pytest.skip("Must be server or site administrator to remove from groups") - groupname = group_name + groupname = TestAssets.group_name command = "removeusers" - filename = os.path.join("tests", "assets", "usernames.csv") + filename = os.path.join("tests", "assets", TestAssets.USERNAMES_FILE) arguments = [command, groupname, "--users", filename] _test_command(arguments) @@ -301,7 +347,7 @@ def test_group_deletegroup(self): if not server_admin and not site_admin: pytest.skip("Must be server or site administrator to delete groups") - groupname = group_name + groupname = TestAssets.group_name command = "deletegroup" arguments = [command, groupname] _test_command(arguments) @@ -312,193 +358,189 @@ def test_create_projects(self): pytest.skip("Must be project administrator to create projects") # project 1 - self._create_project(parent_location) + TabcmdCall._create_project(TestAssets.parent_location) time.sleep(indexing_sleep_time) # project 1 - self._create_project(default_project_name) + TabcmdCall._create_project(default_project_name) time.sleep(indexing_sleep_time) # project 2 - self._create_project("project_name_2", default_project_name) + TabcmdCall._create_project("project_name_2", default_project_name) time.sleep(indexing_sleep_time) # project 3 parent_path = "{0}/{1}".format(default_project_name, "project_name_2") - self._create_project(default_project_name, parent_path) + TabcmdCall._create_project(default_project_name, parent_path) time.sleep(indexing_sleep_time) @pytest.mark.order(8) def test_list_projects(self): if use_tabcmd_classic: pytest.skip("not for tabcmd classic") - self._list("projects") + TabcmdCall._list("projects") @pytest.mark.order(8) def test_list_flows(self): if use_tabcmd_classic: pytest.skip("not for tabcmd classic") - self._list("flows") + TabcmdCall._list("flows") @pytest.mark.order(8) def test_list_workbooks(self): if use_tabcmd_classic: pytest.skip("not for tabcmd classic") - self._list("workbooks") + TabcmdCall._list("workbooks") @pytest.mark.order(8) def test_list_datasources(self): if use_tabcmd_classic: pytest.skip("not for tabcmd classic") - self._list("datasources") + TabcmdCall._list("datasources") @pytest.mark.order(10) def test_delete_projects(self): if not project_admin: pytest.skip("Must be project administrator to create projects") - self._delete_project(parent_location) - self._delete_project("project_name_2", default_project_name) # project 2 - self._delete_project(default_project_name) + TabcmdCall._delete_project(TestAssets.parent_location) + TabcmdCall._delete_project("project_name_2", default_project_name) # project 2 + TabcmdCall._delete_project(default_project_name) @pytest.mark.order(10) def test_wb_publish(self): - file = os.path.join("tests", "assets", OnlineCommandTest.TWBX_FILE_WITH_EXTRACT) - arguments = self._publish_args(file, OnlineCommandTest.TWBX_WITH_EXTRACT_NAME) - val = _test_command(arguments) - if val != 0: - print("publishing failed: cancel test run") - exit(val) + for file in [TestAssets.TWBX_FILE_WITH_EXTRACT, TestAssets.TWBX_FILE_WITHOUT_EXTRACT]: + file = os.path.join("tests", "assets", file) + name_on_server = TestAssets.get_publishable_name(file) + arguments = TabcmdCall._publish_args(file, name_on_server) + val = _test_command(arguments) + if val != 0: + print(f"publishing {file} failed: cancel test run") + exit(val) @pytest.mark.order(11) def test_wb_get(self): # add .twbx to the end to tell the server what we are getting - self._get_workbook(OnlineCommandTest.TWBX_WITH_EXTRACT_NAME + ".twbx") + name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + ".twbx" + TabcmdCall._get_workbook(name_on_server) @pytest.mark.order(11) def test_view_get_pdf(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET # bug in tabcmd classic: doesn't work without download name - self._get_view(wb_name_on_server, sheet_name, "downloaded_file.pdf") + TabcmdCall._get_view(wb_name_on_server, sheet_name, "downloaded_file.pdf") @pytest.mark.order(11) def test_view_get_png_sizes(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET - self._get_view(wb_name_on_server, sheet_name, "get_view_default_size.png") + TabcmdCall._get_view(wb_name_on_server, sheet_name, "get_view_default_size.png") url_params = "?:size=100,200" - self._get_view(wb_name_on_server, sheet_name + url_params, "get_view_sized_sm.png") + TabcmdCall._get_view(wb_name_on_server, sheet_name + url_params, "get_view_sized_sm.png") url_params = "?:size=500,700" - self._get_view(wb_name_on_server, sheet_name + url_params, "get_view_sized_LARGE.png") + TabcmdCall._get_view(wb_name_on_server, sheet_name + url_params, "get_view_sized_LARGE.png") @pytest.mark.order(11) def test_view_get_csv(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET - self._get_view(wb_name_on_server, sheet_name + ".csv") + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET + TabcmdCall._get_view(wb_name_on_server, sheet_name + ".csv") @pytest.mark.order(11) def test_view_get_png(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET - self._get_view(wb_name_on_server, sheet_name + ".png") + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET + TabcmdCall._get_view(wb_name_on_server, sheet_name + ".png") @pytest.mark.order(11) def test_wb_publish_embedded(self): - file = os.path.join("tests", "assets", OnlineCommandTest.TWB_WITH_EMBEDDED_CONNECTION) - arguments = self._publish_args(file, OnlineCommandTest.EMBEDDED_TWB_NAME) - arguments = self._publish_creds_args(arguments, database_user, database_password, True) + file = os.path.join("tests", "assets", TestAssets.TWB_FILE_WITH_EMBEDDED_CONNECTION) + name_on_server = TestAssets.get_publishable_name(TestAssets.TWB_FILE_WITH_EMBEDDED_CONNECTION) + arguments = TabcmdCall._publish_args(file, name_on_server) + arguments = TabcmdCall._publish_creds_args(arguments, database_user, database_password, True) arguments.append("--tabbed") arguments.append("--skip-connection-check") _test_command(arguments) @pytest.mark.order(12) def test_publish_ds(self): - file = os.path.join("tests", "assets", OnlineCommandTest.TDSX_FILE_WITH_EXTRACT) - arguments = self._publish_args(file, OnlineCommandTest.TDSX_WITH_EXTRACT_NAME) + file = os.path.join("tests", "assets", TestAssets.TDSX_FILE_WITH_EXTRACT) + name_on_server = TestAssets.get_publishable_name(TestAssets.TDSX_FILE_WITH_EXTRACT) + arguments = TabcmdCall._publish_args(file, name_on_server) _test_command(arguments) @pytest.mark.order(12) def test_publish_live_ds(self): - file = os.path.join("tests", "assets", OnlineCommandTest.TDS_FILE_LIVE) - arguments = self._publish_args(file, OnlineCommandTest.TDS_FILE_LIVE_NAME) + file = os.path.join("tests", "assets", TestAssets.TDS_FILE_LIVE) + name_on_server = TestAssets.get_publishable_name(TestAssets.TDS_FILE_LIVE) + arguments = TabcmdCall._publish_args(file, name_on_server) _test_command(arguments) @pytest.mark.order(13) def test__get_ds(self): - self._get_datasource(OnlineCommandTest.TDSX_WITH_EXTRACT_NAME + ".tdsx") + name_on_server = TestAssets.get_publishable_name(TestAssets.TDSX_FILE_WITH_EXTRACT) + TabcmdCall._get_datasource(name_on_server + ".tdsx") @pytest.mark.order(13) def test_refresh_ds_extract(self): - self._refresh_extract("-d", OnlineCommandTest.TDSX_WITH_EXTRACT_NAME) + name_on_server = TestAssets.get_publishable_name(TestAssets.TDSX_FILE_WITH_EXTRACT) + TabcmdCall._refresh_extract(name_on_server, "-d") @pytest.mark.order(14) def test_delete_extract(self): - self._delete_extract("-d", OnlineCommandTest.TDSX_WITH_EXTRACT_NAME) + name_on_server = TestAssets.get_publishable_name(TestAssets.TDSX_FILE_WITH_EXTRACT) + TabcmdCall._delete_extract(name_on_server, "-d") @pytest.mark.order(16) def test_create_extract(self): - self._create_extract("-d", OnlineCommandTest.TDS_FILE_LIVE_NAME) + name_on_server = TestAssets.get_publishable_name(TestAssets.TDS_FILE_LIVE) + TabcmdCall._create_extract(name_on_server, "-d") @pytest.mark.order(17) def test_refresh_wb_extract(self): - self._refresh_extract("-w", OnlineCommandTest.TWBX_WITH_EXTRACT_NAME) - - @pytest.mark.order(19) - def test_wb_delete(self): - name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - self._delete_wb(name_on_server) - - @pytest.mark.order(19) - def test__delete_ds(self): - name_on_server = OnlineCommandTest.TDSX_WITH_EXTRACT_NAME - self._delete_ds(name_on_server) - - @pytest.mark.order(19) - def test__delete_ds_live(self): - name_on_server = OnlineCommandTest.TDS_FILE_LIVE_NAME - self._delete_ds(name_on_server) + name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + TabcmdCall._refresh_extract(name_on_server, "-w") @pytest.mark.order(19) def test_export_wb_filters(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET friendly_name = wb_name_on_server + "/" + sheet_name filters = ["--filter", "Product Type=Tea", "--fullpdf", "--pagelayout", "landscape"] - self._export_wb(friendly_name, "filter_a_wb_to_tea_and_two_pages.pdf", filters) + TabcmdCall._export_wb(friendly_name, "filter_a_wb_to_tea_and_two_pages.pdf", filters) # NOTE: this test needs a visual check on the returned pdf to confirm the expected appearance @pytest.mark.order(19) def test_export_wb_pdf(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - friendly_name = wb_name_on_server + "/" + OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + friendly_name = wb_name_on_server + "/" + TestAssets.TWBX_WITH_EXTRACT_SHEET filename = "exported_wb.pdf" - self._export_wb(friendly_name, filename) + TabcmdCall._export_wb(friendly_name, filename) @pytest.mark.order(19) def test_export_data_csv(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET - self._export_view(wb_name_on_server, sheet_name, "--csv", "exported_data.csv") + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET + TabcmdCall._export_view(wb_name_on_server, sheet_name, "--csv", "exported_data.csv") @pytest.mark.order(19) def test_export_view_png(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET - self._export_view(wb_name_on_server, sheet_name, "--png", "export_view.png") + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET + TabcmdCall._export_view(wb_name_on_server, sheet_name, "--png", "export_view.png") @pytest.mark.order(19) def test_export_view_pdf(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET - self._export_view(wb_name_on_server, sheet_name, "--pdf", "export_view_pdf.pdf") + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET + TabcmdCall._export_view(wb_name_on_server, sheet_name, "--pdf", "export_view_pdf.pdf") @pytest.mark.order(19) def test_export_view_filtered(self): - wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME - sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET + wb_name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + sheet_name = TestAssets.TWBX_WITH_EXTRACT_SHEET filename = "view_with_filters.pdf" filters = ["--filter", "Product Type=Tea"] - self._export_view(wb_name_on_server, sheet_name, "--pdf", filename, filters) + TabcmdCall._export_view(wb_name_on_server, sheet_name, "--pdf", filename, filters) @pytest.mark.order(20) def test_delete_site_users(self): @@ -506,7 +548,7 @@ def test_delete_site_users(self): pytest.skip("Must be server or site administrator to delete site users") command = "deletesiteusers" - users = os.path.join("tests", "assets", "usernames.csv") + users = os.path.join("tests", "assets", TestAssets.USERNAMES_FILE) _test_command([command, users]) @pytest.mark.order(21) @@ -521,3 +563,18 @@ def test_list_sites(self): except Exception as E: result = False assert result + + @pytest.mark.order(30) + def test_wb_delete(self): + name_on_server = TestAssets.get_publishable_name(TestAssets.TWBX_FILE_WITH_EXTRACT) + TabcmdCall._delete_wb(name_on_server) + + @pytest.mark.order(30) + def test__delete_ds(self): + name_on_server = TestAssets.get_publishable_name(TestAssets.TDSX_FILE_WITH_EXTRACT) + TabcmdCall._delete_ds(name_on_server) + + @pytest.mark.order(30) + def test__delete_ds_live(self): + name_on_server = TestAssets.get_publishable_name(TestAssets.TDS_FILE_LIVE) + TabcmdCall._delete_ds(name_on_server) diff --git a/tests/e2e/tests_integration.py b/tests/e2e/tests_integration.py index f63588b1..935751ae 100644 --- a/tests/e2e/tests_integration.py +++ b/tests/e2e/tests_integration.py @@ -65,6 +65,7 @@ def test_log_in(): no_cookie=False, ) test_session = Session() + logger = log(__class__.__name__, "info") server = test_session.create_session(args, logger) assert test_session.auth_token is not None assert test_session.site_id is not None @@ -95,6 +96,7 @@ def test_reuse_session(self): timeout=None, no_cookie=False, ) + logger = log(__class__.__name__, "info") test_session = Session() test_session.create_session(args, logger) assert test_session.auth_token is not None