8000 Deterministic order (#131) · miturchi/server-client-python@477366e · GitHub
[go: up one dir, main page]

Skip to content

Commit 477366e

Browse files
author
Russell Hay
authored
Deterministic order (tableau#131)
* Add analytics script * Initial attempt at making the order deterministic * Fix pep8 issues * Right, messing things up when fixing pep8 issues. * xrange doesn't exist in py3.
1 parent aa56523 commit 477366e

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

docs/_includes/analytics.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- Google Tag Manager -->
2+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
3+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
4+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
5+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
6+
})(window,document,'script','dataLayer','GTM-BVCN');</script>
7+
<!-- End Google Tag Manager -->

docs/_includes/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
1515
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
16+
17+
{% if jekyll.environment == "production" %}{% include analytics.html %}{% endif %}

tableauserverclient/server/request_options.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ def apply_query_params(self, url):
4141
if self.page_size:
4242
params.append('pageSize={0}'.format(self.pagesize))
4343
if len(self.sort) > 0:
44-
params.append('sort={}'.format(','.join(str(sort_item) for sort_item in self.sort)))
44+
sort_options = (str(sort_item) for sort_item in self.sort)
45+
ordered_sort_options = sorted(sort_options)
46+
params.append('sort={}'.format(','.join(ordered_sort_options)))
4547
if len(self.filter) > 0:
46-
params.append('filter={}'.format(','.join(str(filter_item) for filter_item in self.filter)))
48+
filter_options = (str(filter_item) for filter_item in self.filter)
49+
ordered_filter_options = sorted(filter_options)
50+
params.append('filter={}'.format(','.join(ordered_filter_options)))
4751

4852
return "{0}?{1}".format(url, '&'.join(params))

test/test_request_option.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
PAGE_SIZE_XML = os.path.join(TEST_ASSET_DIR, 'request_option_page_size.xml')
1111
FILTER_EQUALS = os.path.join(TEST_ASSET_DIR, 'request_option_filter_equals.xml')
1212
FILTER_TAGS_IN = os.path.join(TEST_ASSET_DIR, 'request_option_filter_tags_in.xml')
13+
FILTER_MULTIPLE = os.path.join(TEST_ASSET_DIR, 'request_option_filter_tags_in.xml')
1314

1415

1516
class RequestOptionTests(unittest.TestCase):
@@ -89,3 +90,20 @@ def test_filter_tags_in(self):
8990
self.assertEqual(set(['weather']), matching_workbooks[0].tags)
9091
self.assertEqual(set(['safari']), matching_workbooks[1].tags)
9192
self.assertEqual(set(['sample']), matching_workbooks[2].tags)
93+
94+
def test_multiple_filter_options(self):
95+
with open(FILTER_MULTIPLE, 'rb') as f:
96+
response_xml = f.read().decode('utf-8')
97+
# To ensure that this is deterministic, run this a few times
98+
with requests_mock.mock() as m:
99+
# Sometimes pep8 requires you to do things you might not otherwise do
100+
url = ''.join((self.baseurl, '/workbooks?pageNumber=1&pageSize=100&',
101+
'filter=name:eq:foo,tags:in:[sample,safari,weather]'))
102+
m.get(url, text=response_xml)
103+
req_option = TSC.RequestOptions()
104+
req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Tags, TSC.RequestOptions.Operator.In,
105+
['sample', 'safari', 'weather']))
106+
req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, 'foo'))
107+
for _ in range(100):
108+
matching_workbooks, pagination_item = self.server.workbooks.get(req_option)
109+
self.assertEqual(3, pagination_item.total_available)

0 commit comments

Comments
 (0)
0