8000 Add all fields for users.get (#713) · cfmayden/server-client-python@c74b95c · GitHub
[go: up one dir, main page]

Skip to content

Commit c74b95c

Browse files
author
Chris Shin
authored
Add all fields for users.get (tableau#713)
* Removes manual query param generation * Fixes v3.5 test issue by using regex matching * Moving all query param verifications to use regex search * Adds back removed method with deprecation warning * Adds private all_fields option to users.get
1 parent ab80907 commit c74b95c

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

tableauserverclient/server/endpoint/users_endpoint.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .endpoint import QuerysetEndpoint, api
22
from .exceptions import MissingRequiredFieldError
3-
from .. import RequestFactory, UserItem, WorkbookItem, PaginationItem
3+
from .. import RequestFactory, RequestOptions, UserItem, WorkbookItem, PaginationItem
44
from ..pager import Pager
55

66
import copy
@@ -18,6 +18,11 @@ def baseurl(self):
1818
@api(version="2.0")
1919
def get(self, req_options=None):
2020
logger.info('Querying all users on site')
21+
22+
if req_options is None:
23+
req_options = RequestOptions()
24+
req_options._all_fields = True
25+
2126
url = self.baseurl
2227
server_response = self.get_request(url, req_options)
2328
pagination_item = PaginationItem.from_response(server_response.content, self.parent_srv.namespace)

tableauserverclient/server/request_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def __init__(self, pagenumber=1, pagesize=100):
6969
self.sort = set()
7070
self.filter = set()
7171

72+
# This is private until we expand all of our parsers to handle the extra fields
73+
self._all_fields = False
74+
7275
def page_size(self, page_size):
7376
self.pagesize = page_size
8000
7477
return self
@@ -91,6 +94,8 @@ def get_query_params(self):
9194
filter_options = (str(filter_item) for filter_item in self.filter)
9295
ordered_filter_options = sorted(filter_options)
9396
params['filter'] = ','.join(ordered_filter_options)
97+
if self._all_fields:
98+
params['fields'] = '_all_'
9499
return params
95100

96101

test/assets/user_get.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<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">
33
<pagination pageNumber="1" pageSize="100" totalAvailable="2" />
44
<users>
5-
<user id="dd2239f6-ddf1-4107-981a-4cf94e415794" name="alice" siteRole="Publisher" lastLogin="2016-08-16T23:17:06Z" externalAuthUserId="" />
6-
<user id="2a47bbf8-8900-4ebb-b0a4-2723bd7c46c3" name="Bob" siteRole="Interactor" externalAuthUserId="" />
5+
<user id="dd2239f6-ddf1-4107-981a-4cf94e415794" name="alice" siteRole="Publisher" lastLogin="2016-08-16T23:17:06Z" externalAuthUserId="" fullName="alice cook" email="alicecook@test.com" />
6+
<user id="2a47bbf8-8900-4ebb-b0a4-2723bd7c46c3" name="Bob" siteRole="Interactor" externalAuthUserId="" fullName="Bob Smith" email="bob@test.com" />
77
</users>
88
</tsResponse>

test/test_request_option.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ def test_vf(self):
176176
self.assertTrue(re.search('vf_name2%24=value2', resp.request.query))
177177
self.assertTrue(re.search('type=tabloid', resp.request.query))
178178

179+
def test_all_fields(self):
180+
with requests_mock.mock() as m:
181+
m.get(requests_mock.ANY)
182+
url = "http://test/api/2.3/sites/123/views/456/data"
183+
opts = TSC.RequestOptions()
184+
opts._all_fields = True
185+
186+
resp = self.server.users._make_request(requests.get,
187+
url,
188+
content=None,
189+
request_object=opts,
190+
auth_token='j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM',
191+
content_type='text/xml')
192+
self.assertTrue(re.search('fields=_all_', resp.request.query))
193+
179194
def test_multiple_filter_options_shorthand(self):
180195
with open(FILTER_MULTIPLE, 'rb') as f:
181196
response_xml = f.read().decode('utf-8')

test/test_user.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_get(self):
2929
with open(GET_XML, 'rb') as f:
3030
response_xml = f.read().decode('utf-8')
3131
with requests_mock.mock() as m:
32-
m.get(self.baseurl, text=response_xml)
32+
m.get(self.baseurl + "?fields=_all_", text=response_xml)
3333
all_users, pagination_item = self.server.users.get()
3434

3535
self.assertEqual(2, pagination_item.total_available)
@@ -40,11 +40,15 @@ def test_get(self):
4040
self.assertEqual('alice', single_user.name)
4141
self.assertEqual('Publisher', single_user.site_role)
4242
self.assertEqual('2016-08-16T23:17:06Z', format_datetime(single_user.last_login))
43+
self.assertEqual('alice cook', single_user.fullname)
44+
self.assertEqual('alicecook@test.com', single_user.email)
4345

4446
self.assertTrue(any(user.id == '2a47bbf8-8900-4ebb-b0a4-2723bd7c46c3' for user in all_users))
4547
single_user = next(user for user in all_users if user.id == '2a47bbf8-8900-4ebb-b0a4-2723bd7c46c3')
4648
self.assertEqual('Bob', single_user.name)
4749
self.assertEqual('Interactor', single_user.site_role)
50+
self.assertEqual('Bob Smith', single_user.fullname)
51+
self.assertEqual('bob@test.com', single_user.email)
4852

4953
def test_get_empty(self):
5054
with open(GET_EMPTY_XML, 'rb') as f:

0 commit comments

Comments
 (0)
0