8000 Fixes maxage to allow 0 as input (#639) · tableau/server-client-python@d9edc55 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9edc55

Browse files
author
Chris Shin
authored
Fixes maxage to allow 0 as input (#639)
1 parent 7f76e71 commit d9edc55

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

tableauserverclient/server/request_options.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _append_view_filters(self, params):
103103

104104

105105
class CSVRequestOptions(_FilterOptionsBase):
106-
def __init__(self, maxage=None):
106+
def __init__(self, maxage=-1):
107107
super(CSVRequestOptions, self).__init__()
108108
self.max_age = maxage
109109

@@ -112,13 +112,13 @@ def max_age(self):
112112
return self._max_age
113113

114114
@max_age.setter
115-
@property_is_int(range=(0, 240))
115+
@property_is_int(range=(0, 240), allowed=[-1])
116116
def max_age(self, value):
117117
self._max_age = value
118118

119119
def apply_query_params(self, url):
120120
params = []
121-
if self.max_age != 0:
121+
10000 if self.max_age != -1:
122122
params.append('maxAge={0}'.format(self.max_age))
123123

124124
self._append_view_filters(params)
@@ -130,7 +130,7 @@ class ImageRequestOptions(_FilterOptionsBase):
130130
class Resolution:
131131
High = 'high'
132132

133-
def __init__(self, imageresolution=None, maxage=None):
133+
def __init__(self, imageresolution=None, maxage=-1):
134134
super(ImageRequestOptions, self).__init__()
135135
self.image_resolution = imageresolution
136136
self.max_age = maxage
@@ -140,15 +140,15 @@ def max_age(self):
140140
return self._max_age
141141

142142
@max_age.setter
143-
@property_is_int(range=(0, 240))
143+
@property_is_int(range=(0, 240), allowed=[-1])
144144
def max_age(self, value):
145145
self._max_age = value
146146

147147
def apply_query_params(self, url):
148148
params = []
149149
if self.image_resolution:
150150
params.append('resolution={0}'.format(self.image_resolution))
151-
if self.max_age != 0:
151+
if self.max_age != -1:
152152
params.append('maxAge={0}'.format(self.max_age))
153153

154154
self._append_view_filters(params)
@@ -176,7 +176,7 @@ class Orientation:
176176
Portrait = "portrait"
177177
Landscape = "landscape"
178178

179-
def __init__(self, page_type=None, orientation=None, maxage=0):
179+
def __init__(self, page_type=None, orientation=None, maxage=-1):
180180
super(PDFRequestOptions, self).__init__()
181181
self.page_type = page_type
182182
self.orientation = orientation
@@ -187,7 +187,7 @@ def max_age(self):
187187
return self._max_age
188188

189189
@max_age.setter
190-
@property_is_int(range=(0, 240))
190+
@property_is_int(range=(0, 240), allowed=[-1])
191191
def max_age(self, value):
192192
self._max_age = value
193193

@@ -199,7 +199,7 @@ def apply_query_params(self, url):
199199
if self.orientation:
200200
params.append('orientation={0}'.format(self.orientation))
201201

202-
if self.max_age != 0:
202+
if self.max_age != -1:
203203
params.append('maxAge={0}'.format(self.max_age))
204204

205205
self._append_view_filters(params)

test/test_view.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ def test_populate_csv(self):
170170
csv_file = b"".join(single_view.csv)
171171
self.assertEqual(response, csv_file)
172172

173+
def test_populate_csv_default_maxage(self):
174+
with open(POPULATE_CSV, 'rb') as f:
175+
response = f.read()
176+
with requests_mock.mock() as m:
177+
m.get(self.baseurl + '/d79634e1-6063-4ec9-95ff-50acbf609ff5/data', content=response)
178+
single_view = TSC.ViewItem()
179+
single_view._id = 'd79634e1-6063-4ec9-95ff-50acbf609ff5'
180+
self.server.views.populate_csv(single_view)
181+
182+
csv_file = b"".join(single_view.csv)
183+
self.assertEqual(response, csv_file)
184+
173185
def test_populate_image_missing_id(self):
174186
single_view = TSC.ViewItem()
175187
single_view._id = None

0 commit comments

Comments
 (0)
0