8000 Add all fields for users.get by shinchris · Pull Request #713 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Add all fields for users.get 8000 #713

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 8 commits into from
Nov 6, 2020
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
7 changes: 6 additions & 1 deletion tableauserverclient/server/endpoint/users_endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .endpoint import QuerysetEndpoint, api
from .exceptions import MissingRequiredFieldError
from .. import RequestFactory, UserItem, WorkbookItem, PaginationItem
from .. import RequestFactory, RequestOptions, UserItem, WorkbookItem, PaginationItem
from ..pager import Pager

import copy
Expand All @@ -18,6 +18,11 @@ def baseurl(self):
8000 @api(version="2.0")
def get(self, req_options=None):
logger.info('Querying all users on site')

if req_options is None:
req_options = RequestOptions()
req_options._all_fields = True

url = self.baseurl
server_response = self.get_request(url, req_options)
pagination_item = PaginationItem.from_response(server_response.content, self.parent_srv.namespace)
Expand Down
5 changes: 5 additions & 0 deletions tableauserverclient/server/request_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def __init__(self, pagenumber=1, pagesize=100):
self.sort = set()
self.filter = set()

# This is private until we expand all of our parsers to handle the extra fields
self._all_fields = False

def page_size(self, page_size):
self.pagesize = page_size
return self
Expand All @@ -91,6 +94,8 @@ def get_query_params(self):
filter_options = (str(filter_item) for filter_item in self.filter)
ordered_filter_options = sorted(filter_op 8000 tions)
params['filter'] = ','.join(ordered_filter_options)
if self._all_fields:
params['fields'] = '_all_'
return params


Expand Down
4 changes: 2 additions & 2 deletions test/assets/user_get.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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">
<pagination pageNumber="1" pageSize="100" totalAvailable="2" />
<users>
<user id="dd2239f6-ddf1-4107-981a-4cf94e415794" name="alice" siteRole="Publisher" lastLogin="2016-08-16T23:17:06Z" externalAuthUserId="" />
<user id="2a47bbf8-8900-4ebb-b0a4-2723bd7c46c3" name="Bob" siteRole="Interactor" externalAuthUserId="" />
<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" />
<user id="2a47bbf8-8900-4ebb-b0a4-2723bd7c46c3" name="Bob" siteRole="Interactor" externalAuthUserId="" fullName="Bob Smith" email="bob@test.com" />
</users>
</tsResponse>
15 changes: 15 additions & 0 deletions test/test_request_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ def test_vf(self):
self.assertTrue(re.search('vf_name2%24=value2', resp.request.query))
self.assertTrue(re.search('type=tabloid', resp.request.query))

def test_all_fields(self):
with requests_mock.mock() as m:
m.get(requests_mock.ANY)
url = "http://test/api/2.3/sites/123/views/456/data"
opts = TSC.RequestOptions()
opts._all_fields = True

resp = self.server.users._make_request(requests.get,
url,
content=None,
request_object=opts,
auth_token='j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM',
content_type='text/xml')
self.assertTrue(re.search('fields=_all_', resp.request.query))

def test_multiple_filter_options_shorthand(self):
with open(FILTER_MULTIPLE, 'rb') as f:
response_xml = f.read().decode('utf-8')
Expand Down
6 changes: 5 additions & 1 deletion test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_get(self):
with open(GET_XML, 'rb') as f:
response_xml = f.read().decode('utf-8')
with requests_mock.mock() as m:
m.get(self.baseurl, text=response_xml)
m.get(self.baseurl + "?fields=_all_", text=response_xml)
all_users, pagination_item = self.server.users.get()

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

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

def test_get_empty(self):
with open(GET_EMPTY_XML, 'rb') as f:
Expand Down
0