8000 Add revision settings to Update Site by t8y8 · Pull Request #187 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Add revision settings to Update Site #187

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2017
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
18 changes: 13 additions & 5 deletions tableauserverclient/models/property_decorators.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,18 @@ def wrapper(self, value):
return wrapper


def property_is_int(range):
def property_is_int(range, allowed=None):
'''Takes a range of ints and a list of exemptions to check against
when setting a property on a model. The range is a tuple of (min, max) and the
allowed list (empty by default) allows values outside that range.
This is useful for when we use sentinel values.

Example: Revisions allow a range of 2-10000, but use -1 as a sentinel for 'unlimited'.
'''

if allowed is None:
allowed = () # Empty tuple for fast no-op testing.

def property_type_decorator(func):
@wraps(func)
def wrapper(self, value):
Expand All @@ -83,14 +94,11 @@ def wrapper(self, value):

min, max = range

if value < min or value > max:

if (value < min or value > max) and (value not in allowed):
raise ValueError(error)

return func(self, value)

return wrapper

return property_type_decorator


Expand Down
16 changes: 13 additions & 3 deletions tableauserverclient/models/site_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import xml.etree.ElementTree as ET
from .property_decorators import (property_is_enum, property_is_boolean, property_matches,
property_not_empty, property_not_nullable)< 8000 /span>
property_not_empty, property_not_nullable, property_is_int)
from .. import NAMESPACE


Expand All @@ -17,14 +17,15 @@ class State:
Suspended = 'Suspended'

def __init__(self, name, content_url, admin_mode=None, user_quota=None, storage_quota=None,
disable_subscriptions=False, subscribe_others_enabled=True, revision_history_enabled=False):
disable_subscriptions=False, subscribe_others_enabled=True, revision_history_enabled=False,
revision_limit=None):
self._admin_mode = None
self._id = None
self._num_users = None
self._state = None
self._status_reason = None
self._storage = None
self.revision_limit = None
self._revision_limit = None
self.user_quota = user_quota
self.storage_quota = storage_quota
self.content_url = content_url
Expand Down Expand Up @@ -88,6 +89,15 @@ def revision_history_enabled(self):
def revision_history_enabled(self, value):
self._revision_history_enabled = value

@property
def revision_limit(self):
return self._revision_limit

@revision_limit.setter
@property_is_int((2, 10000), allowed=[-1])
def revision_limit(self, value):
self._revision_limit = value

@property
def state(self):
return self._state
Expand Down
4 changes: 4 additions & 0 deletions tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def update_req(self, site_item):
site_element.attrib['disableSubscriptions'] = str(site_item.disable_subscriptions).lower()
if site_item.subscribe_others_enabled:
site_element.attrib['subscribeOthersEnabled'] = str(site_item.subscribe_others_enabled).lower()
if site_item.revision_limit:
site_element.attrib['revisionLimit'] = str(site_item.revision_limit)
if site_item.subscribe_others_enabled:
site_element.attrib['revisionHistoryEnabled'] = str(site_item.revision_history_enabled).lower()
return ET.tostring(xml_request)

def create_req(self, site_item):
Expand Down
2 changes: 1 addition & 1 deletion test/assets/site_update.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd">
<site id="6b7179ba-b82b-4f0f-91ed-812074ac5da6" name="Tableau" contentUrl="tableau" adminMode="ContentAndUsers" userQuota="15" disableSubscriptions="true" state="Suspended" revisionHistoryEnabled="false" subscribeOthersEnabled="true" />
<site id="6b7179ba-b82b-4f0f-91ed-812074ac5da6" name="Tableau" contentUrl="tableau" adminMode="ContentAndUsers" userQuota="15" disableSubscriptions="true" state="Suspended" revisionHistoryEnabled="true" subscribeOthersEnabled="true" revisionLimit="13"/>
</tsResponse>
4 changes: 3 additions & 1 deletion test/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_update(self):
single_site = TSC.SiteItem(name='Tableau', content_url='tableau',
admin_mode=TSC.SiteItem.AdminMode.ContentAndUsers,
user_quota=15, storage_quota=1000,
disable_subscriptions=True)
disable_subscriptions=True, revision_history_enabled=False)
single_site._id = '6b7179ba-b82b-4f0f-91ed-812074ac5da6'
single_site = self.server.sites.update(single_site)

Expand All @@ -100,6 +100,8 @@ def test_update(self):
self.assertEqual('Suspended', single_site.state)
self.assertEqual('Tableau', single_site.name)
self.assertEqual('ContentAndUsers', single_site.admin_mode)
self.assertEqual(True, single_site.revision_history_enabled)
self.assertEqual(13, single_site.revision_limit)
self.assertEqual(True, single_site.disable_subscriptions)
self.assertEqual(15, single_site.user_quota)

Expand Down
0