Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_invalid_name(self):
self.assertRaises(ValueError, TSC.ProjectItem, None)
self.assertRaises(ValueError, TSC.ProjectItem, "")
project = TSC.ProjectItem("proj")
with self.assertRaises(ValueError):
project.name = None
with self.assertRaises(ValueError):
project.name = ""
def test_update_missing_id(self):
single_project = TSC.ProjectItem('test')
self.assertRaises(TSC.MissingRequiredFieldError, self.server.projects.update, single_project)
def test_invalid_content_permissions(self):
project = TSC.ProjectItem("proj")
with self.assertRaises(ValueError):
project.content_permissions = "Hello"
def test_parent_id(self):
project = TSC.ProjectItem("proj")
project.parent_id = "foo"
self.assertEqual(project.parent_id, "foo")
def test_invalid_name(self):
self.assertRaises(ValueError, TSC.ProjectItem, None)
self.assertRaises(ValueError, TSC.ProjectItem, "")
project = TSC.ProjectItem("proj")
with self.assertRaises(ValueError):
project.name = None
with self.assertRaises(ValueError):
project.name = ""
def test_update(self):
with open(UPDATE_XML, 'rb') as f:
response_xml = f.read().decode('utf-8')
with requests_mock.mock() as m:
m.put(self.baseurl + '/1d0304cd-3796-429f-b815-7258370b9b74', text=response_xml)
single_project = TSC.ProjectItem(name='Test Project',
content_permissions='LockedToProject',
description='Project created for testing',
parent_id='9a8f2265-70f3-4494-96c5-e5949d7a1120')
single_project._id = '1d0304cd-3796-429f-b815-7258370b9b74'
single_project = self.server.projects.update(single_project)
self.assertEqual('1d0304cd-3796-429f-b815-7258370b9b74', single_project.id)
self.assertEqual('Test Project', single_project.name)
self.assertEqual('Project created for testing', single_project.description)
self.assertEqual('LockedToProject', single_project.content_permissions)
self.assertEqual('9a8f2265-70f3-4494-96c5-e5949d7a1120', single_project.parent_id)
def test_populate_workbooks(self):
response_xml = read_xml_asset(POPULATE_WORKBOOK_DEFAULT_PERMISSIONS_XML)
with requests_mock.mock() as m:
m.get(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/default-permissions/workbooks',
text=response_xml)
single_project = TSC.ProjectItem('test', '1d0304cd-3796-429f-b815-7258370b9b74')
single_project.owner_id = 'dd2239f6-ddf1-4107-981a-4cf94e415794'
single_project._id = '9dbd2263-16b5-46e1-9c43-a76bb8ab65fb'
self.server.projects.populate_workbook_default_permissions(single_project)
permissions = single_project.default_workbook_permissions
rule1 = permissions.pop()
self.assertEqual('c8f2773a-c83a-11e8-8c8f-33e6d787b506', rule1.grantee.id)
self.assertEqual('group', rule1.grantee.tag_name)
self.assertDictEqual(rule1.capabilities, {
TSC.Permission.Capability.Write: TSC.Permission.Mode.Allow,
TSC.Permission.Capability.Read: TSC.Permission.Mode.Allow,
TSC.Permission.Capability.Filter: TSC.Permission.Mode.Allow,
TSC.Permission.Capability.ChangePermissions: TSC.Permission.Mode.Allow,
TSC.Permission.Capability.WebAuthoring: TSC.Permission.Mode.Allow,
server = TSC.Server(args.server)
with server.auth.sign_in(tableau_auth):
# Use highest Server REST API version available
server.use_server_version()
# Without parent_id specified, projects are created at the top level.
top_level_project = TSC.ProjectItem(name='Top Level Project')
top_level_project = create_project(server, top_level_project)
# Specifying parent_id creates a nested projects.
child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id)
child_project = create_project(server, child_project)
# Projects can be nested at any level.
grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id)
grand_child_project = create_project(server, grand_child_project)
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)
tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)
with server.auth.sign_in(tableau_auth):
# Use highest Server REST API version available
server.use_server_version()
# Without parent_id specified, projects are created at the top level.
top_level_project = TSC.ProjectItem(name='Top Level Project')
top_level_project = create_project(server, top_level_project)
# Specifying parent_id creates a nested projects.
child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id)
child_project = create_project(server, child_project)
# Projects can be nested at any level.
grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id)
grand_child_project = create_project(server, grand_child_project)