diff --git a/tabcmd/commands/datasources_and_workbooks/publish_command.py b/tabcmd/commands/datasources_and_workbooks/publish_command.py index 99c4ea25..cb50be17 100644 --- a/tabcmd/commands/datasources_and_workbooks/publish_command.py +++ b/tabcmd/commands/datasources_and_workbooks/publish_command.py @@ -75,7 +75,7 @@ def run_command(args): new_workbook = TSC.WorkbookItem(project_id, name=args.name, show_tabs=args.tabbed) try: if creds: - logger.debug("Workbook credentials object: " + creds) + logger.debug("Workbook credentials object: " + str(creds)) new_workbook = server.workbooks.publish( new_workbook, args.filename, diff --git a/tabcmd/commands/site/list_command.py b/tabcmd/commands/site/list_command.py index 76c67cbb..64e4fa48 100644 --- a/tabcmd/commands/site/list_command.py +++ b/tabcmd/commands/site/list_command.py @@ -18,7 +18,6 @@ class ListCommand(Server): "tabcmd_content_none": "No content found.", } - name: str = "list" description: str = "List content items of a specified type" diff --git a/tests/commands/test_publish_command.py b/tests/commands/test_publish_command.py new file mode 100644 index 00000000..9f91a02e --- /dev/null +++ b/tests/commands/test_publish_command.py @@ -0,0 +1,90 @@ +import argparse +import unittest +from unittest.mock import * +import tableauserverclient as TSC + +from tabcmd.commands.auth import login_command +from tabcmd.commands.datasources_and_workbooks import delete_command, export_command, get_url_command, publish_command + + +from typing import List, NamedTuple, TextIO, Union +import io + +mock_args = argparse.Namespace() + +fake_item = MagicMock() +fake_item.name = "fake-name" +fake_item.id = "fake-id" +fake_item.pdf = b"/pdf-representation-of-view" +fake_item.extract_encryption_mode = "Disabled" + +fake_job = MagicMock() +fake_job.id = "fake-job-id" + +creator = MagicMock() +getter = MagicMock() +getter.get = MagicMock("get", return_value=([fake_item], 1)) +getter.publish = MagicMock("publish", return_value=fake_item) + + +@patch("tableauserverclient.Server") +@patch("tabcmd.commands.auth.session.Session.create_session") +class RunCommandsTest(unittest.TestCase): + @staticmethod + def _set_up_session(mock_session, mock_server): + mock_session.return_value = mock_server + assert mock_session is not None + mock_session.assert_not_called() + global mock_args + mock_args = argparse.Namespace(logging_level="DEBUG") + # set values for things that should always have a default + # should refactor so this can be automated + mock_args.continue_if_exists = False + mock_args.project_name = None + mock_args.parent_project_path = None + mock_args.parent_path = None + mock_args.timeout = None + mock_args.username = None + + def test_publish(self, mock_session, mock_server): + RunCommandsTest._set_up_session(mock_session, mock_server) + mock_args.overwrite = False + mock_args.filename = "existing_file.twbx" + mock_args.project_name = "project-name" + mock_args.parent_project_path = "projects" + mock_args.name = "" + mock_args.tabbed = True + mock_args.db_username = None + mock_args.oauth_username = None + mock_args.append = False + mock_args.replace = False + mock_args.thumbnail_username = None + mock_args.thumbnail_group = None + mock_server.projects = getter + publish_command.PublishCommand.run_command(mock_args) + mock_session.assert_called() + + def test_publish_with_creds(self, mock_session, mock_server): + RunCommandsTest._set_up_session(mock_session, mock_server) + mock_args.overwrite = False + mock_args.append = True + mock_args.replace = False + + mock_args.filename = "existing_file.twbx" + mock_args.project_name = "project-name" + mock_args.parent_project_path = "projects" + mock_args.name = "" + mock_args.tabbed = True + + mock_args.db_username = "username" + mock_args.db_password = "oauth_u" + mock_args.save_db_password = True + mock_args.oauth_username = None + mock_args.embed = False + + mock_args.thumbnail_username = None + mock_args.thumbnail_group = None + + mock_server.projects = getter + publish_command.PublishCommand.run_command(mock_args) + mock_session.assert_called() diff --git a/tests/commands/test_run_commands.py b/tests/commands/test_run_commands.py index dbb9bf55..2efd4a75 100644 --- a/tests/commands/test_run_commands.py +++ b/tests/commands/test_run_commands.py @@ -4,13 +4,7 @@ import tableauserverclient as TSC from tabcmd.commands.auth import login_command, logout_command -from tabcmd.commands.datasources_and_workbooks import ( - delete_command, - export_command, - get_url_command, - publish_command, - runschedule_command, -) +from tabcmd.commands.datasources_and_workbooks import delete_command, export_command, get_url_command, publish_command from tabcmd.commands.extracts import ( create_extracts_command, delete_extracts_command, @@ -35,7 +29,7 @@ remove_users_command, delete_site_users_command, ) -from typing import List, NamedTuple, TextIO, Union +from typing import NamedTuple, TextIO, Union import io mock_args = argparse.Namespace() @@ -139,33 +133,6 @@ def test_get_workbook(self, mock_session, mock_server): get_url_command.GetUrl.run_command(mock_args) mock_session.assert_called() - def test_publish(self, mock_session, mock_server): - RunCommandsTest._set_up_session(mock_session, mock_server) - mock_args.overwrite = False - mock_args.filename = "existing_file.twbx" - mock_args.project_name = "project-name" - mock_args.parent_project_path = "projects" - mock_args.name = "" - mock_args.tabbed = True - mock_args.db_username = None - mock_args.oauth_username = None - mock_args.append = False - mock_args.replace = False - mock_args.thumbnail_username = None - mock_args.thumbnail_group = None - mock_server.projects = getter - publish_command.PublishCommand.run_command(mock_args) - mock_session.assert_called() - - @unittest.skip("target code not implemented yet") - def test_runschedule(self, mock_session, mock_server): - RunCommandsTest._set_up_session(mock_session, mock_server) - mock_server.schedules = getter - mock_args.schedule = "myschedule" - with self.assertRaises(SystemExit): - runschedule_command.RunSchedule.run_command(mock_args) - # mock_session.assert_called() - # extracts def test_create_extract(self, mock_session, mock_server): RunCommandsTest._set_up_session(mock_session, mock_server) diff --git a/tests/commands/test_session.py b/tests/commands/test_session.py index 44b20a8a..cb60260d 100644 --- a/tests/commands/test_session.py +++ b/tests/commands/test_session.py @@ -74,6 +74,7 @@ def _set_mocks_for_json_file_exists(mock_path, mock_json_lib, does_it_exist=True mock_json_lib.load.return_value = None return path + def _set_mock_file_content(mock_load, expected_content): mock_load.return_value = expected_content return mock_load @@ -120,6 +121,7 @@ def test_json_invalid(self, mock_open, mock_path, mock_json): test_session = Session() assert test_session.username is None + @mock.patch("getpass.getpass") class BuildCredentialsTests(unittest.TestCase): @classmethod