8000 Jorwoods/quota tiers allow null (#1015) · tableau/server-client-python@9332c4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9332c4c

Browse files
authored
Jorwoods/quota tiers allow null (#1015)
* Allow setting site user_quota to None if tiered licenses exist
1 parent a240bf6 commit 9332c4c

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

tableauserverclient/models/site_item.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from multiprocessing.sharedctypes import Value
12
import warnings
23
import xml.etree.ElementTree as ET
34

@@ -226,8 +227,14 @@ def user_quota(self) -> Optional[int]:
226227

227228
@user_quota.setter
228229
def user_quota(self, value: Optional[int]) -> None:
229-
if any((self.tier_creator_capacity, self.tier_explorer_capacity, self.tier_viewer_capacity)):
230-
raise ValueError("User quota conflicts with setting tiered license levels. Set those to None first.")
230+
if value is not None and any(
231+
(self.tier_creator_capacity, self.tier_explorer_capacity, self.tier_viewer_capacity)
232+
):
233+
raise ValueError(
234+
"User quota conflicts with setting tiered license levels. "
235+
"Use replace_license_tiers_with_user_quota to set those to None, "
236+
"and set user_quota to the desired value."
237+
)
231238
self._user_quota = value
232239

233240
@property
@@ -561,6 +568,12 @@ def auto_suspend_refresh_enabled(self) -> bool:
561568
def auto_suspend_refresh_enabled(self, value: bool):
562569
self._auto_suspend_refresh_enabled = value
563570

571+
def replace_license_tiers_with_user_quota(self, value: int) -> None:
572+
self.tier_creator_capacity = None
573+
self.tier_explorer_capacity = None
574+
self.tier_viewer_capacity = None
575+
self.user_quota = value
576+
564577
def _parse_common_tags(self, site_xml, ns):
565578
if not isinstance(site_xml, ET.Element):
566579
site_xml = fromstring(site_xml).find(".//t:site", namespaces=ns)
@@ -747,7 +760,11 @@ def _set_values(
747760
if revision_history_enabled is not None:
748761
self._revision_history_enabled = revision_history_enabled
749762
if user_quota:
750-
self.user_quota = user_quota
763+
try:
764+
self.user_quota = user_quota
765+
except ValueError:
766+
warnings.warn("Tiered license level is set. Setting user_quota to None.")
767+
self.user_quota = None
751768
if storage_quota:
752769
self.storage_quota = storage_quota
753770
if revision_limit:

test/test_site.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def test_update(self) -> None:
139139
time_zone="America/Los_Angeles",
140140
auto_suspend_refresh_enabled=True,
141141
auto_suspend_refresh_inactivity_window=55,
142+
tier_creator_capacity=5,
143+
tier_explorer_capacity=5,
144+
tier_viewer_capacity=5,
142145
)
143146
single_site._id = "6b7179ba-b82b-4f0f-91ed-812074ac5da6"
144147
single_site = self.server.sites.update(single_site)
@@ -151,7 +154,10 @@ def test_update(self) -> None:
151154
self.assertEqual(True, single_site.revision_history_enabled)
152155
self.assertEqual(13, single_site.revision_limit)
153156
self.assertEqual(True, single_site.disable_subscriptions)
154-
self.assertEqual(15, single_site.user_quota)
157+
self.assertEqual(None, single_site.user_quota)
158+
self.assertEqual(5, single_site.tier_creator_capacity)
159+
self.assertEqual(5, single_site.tier_explorer_capacity)
160+
self.assertEqual(5, single_site.tier_viewer_capacity)
155161
self.assertEqual("disable", single_site.data_acceleration_mode)
156162
self.assertEqual(True, single_site.flows_enabled)
157163
self.assertEqual(True, single_site.cataloging_enabled)
@@ -179,6 +185,23 @@ def test_update_missing_id(self) -> None:
179185
single_site = TSC.SiteItem("test", "test")
180186
self.assertRaises(TSC.MissingRequiredFieldError, self.server.sites.update, single_site)
181187

188+
def test_null_site_quota(self) -> None:
189+
test_site = TSC.SiteItem("testname", "testcontenturl", tier_explorer_capacity=1, user_quota=None)
190+
assert test_site.tier_explorer_capacity == 1
191+
with self.assertRaises(ValueError):
192+
test_site.user_quota = 1
193+
test_site.tier_explorer_capacity = None
194+
test_site.user_quota = 1
195+
196+
def test_replace_license_tiers_with_user_quota(self) -> None:
197+
test_site = TSC.SiteItem("testname", "testcontenturl", tier_explorer_capacity=1, user_quota=None)
198+
assert test_site.tier_explorer_capacity == 1
199+
with self.assertRaises(ValueError):
200+
test_site.user_quota = 1
201+
test_site.replace_license_tiers_with_user_quota(1)
202+
self.assertEqual(1, test_site.user_quota)
203+
self.assertIsNone(test_site.tier_explorer_capacity)
204+
182205
def test_create(self) -> None:
183206
with open(CREATE_XML, "rb") as f:
184207
response_xml = f.read().decode("utf-8")

0 commit comments

Comments
 (0)
0