Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tabcmd/commands/site/list_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
90 changes: 90 additions & 0 deletions tests/commands/test_publish_command.py
Original file line number Diff line number Diff line change
@@ -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()
37 changes: 2 additions & 35 deletions tests/commands/test_run_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/commands/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down