8000 Enable asJob for group update (#1276) · jorwoods/server-client-python@81af54a · GitHub
[go: up one dir, main page]

Skip to content

Commit 81af54a

Browse files
authored
Enable asJob for group update (tableau#1276)
1 parent 9afc0b3 commit 81af54a

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

tableauserverclient/server/endpoint/groups_endpoint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,17 @@ def update(
8282
)
8383
group_item.minimum_site_role = default_site_role
8484

85+
url = "{0}/{1}".format(self.baseurl, group_item.id)
86+
8587
if not group_item.id:
8688
error = "Group item missing ID."
8789
raise MissingRequiredFieldError(error)
8890
if as_job and (group_item.domain_name is None or group_item.domain_name == "local"):
8991
error = "Local groups cannot be updated asynchronously."
9092
raise ValueError(error)
93+
elif as_job:
94+
url = "?".join([url, "asJob=True"])
9195

92-
url = "{0}/{1}".format(self.baseurl, group_item.id)
9396
update_req = RequestFactory.Group.update_req(group_item, None)
9497
server_response = self.put_request(url, update_req)
9598
logger.info("Updated group item (ID: {0})".format(group_item.id))

test/assets/group_update_async.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<tsResponse xmlns="http://tableau.com/api"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.3.xsd">
5+
<job id="c2566efc-0767-4f15-89cb-56acb4349c1b"
6+
mode="Asynchronous"
7+
type="GroupSync"
8+
progress="0"
9+
createdAt="time-job-created" />
10+
</tsResponse>

test/test_group.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# encoding=utf-8
2+
from pathlib import Path
23
import unittest
34
import os
45
import requests_mock
56
import tableauserverclient as TSC
67
from tableauserverclient.datetime_helpers import format_datetime
78

8-
TEST_ASSET_DIR = os.path.join(os.path.dirname(__file__), "assets")
9+
TEST_ASSET_DIR = Path(__file__).absolute().parent / "assets"
10+
11+
# TEST_ASSET_DIR = os.path.join(os.path.dirname(__file__), "assets")
912

1013
GET_XML = os.path.join(TEST_ASSET_DIR, "group_get.xml")
1114
POPULATE_USERS = os.path.join(TEST_ASSET_DIR, "group_populate_users.xml")
@@ -16,6 +19,7 @@
1619
CREATE_GROUP_AD = os.path.join(TEST_ASSET_DIR, "group_create_ad.xml")
1720
CREATE_GROUP_ASYNC = os.path.join(TEST_ASSET_DIR, "group_create_async.xml")
1821
UPDATE_XML = os.path.join(TEST_ASSET_DIR, "group_update.xml")
22+
UPDATE_ASYNC_XML = TEST_ASSET_DIR / "group_update_async.xml"
1923

2024

2125
class GroupTests(unittest.TestCase):
@@ -245,3 +249,16 @@ def test_update_local_async(self) -> None:
245249
# mimic group returned from server where domain name is set to 'local'
246250
group.domain_name = "local"
247251
self.assertRaises(ValueError, self.server.groups.update, group, as_job=True)
252+
253+
def test_update_ad_async(self) -> None:
254+
group = TSC.GroupItem("myGroup", "example.com")
255+
group._id = "ef8b19c0-43b6-11e6-af50-63f5805dbe3c"
256+
group.minimum_site_role = TSC.UserItem.Roles.Viewer
257+
258+
with requests_mock.mock() as m:
259+
m.put(f"{self.baseurl}/{group.id}?asJob=True", text=UPDATE_ASYNC_XML.read_bytes().decode("utf8"))
260+
job = self.server.groups.update(group, as_job=True)
261+
262+
self.assertEqual(job.id, "c2566efc-0767-4f15-89cb-56acb4349c1b")
263+
self.assertEqual(job.mode, "Asynchronous")
264+
self.assertEqual(job.type, "GroupSync")

0 commit comments

Comments
 (0)
0