8000 Jac/small things (#1215) · tableau/server-client-python@830a3a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 830a3a6

Browse files
committed
Jac/small things (#1215)
#1210 #1087 #1058 #456 #1209
1 parent 3cc28be commit 830a3a6

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

tableauserverclient/models/datasource_item.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __repr__(self):
3232
self.project_id,
3333
)
3434

35-
def __init__(self, project_id: str, name: Optional[str] = None) -> None:
35+
def __init__(self, project_id: Optional[str] = None, name: Optional[str] = None) -> None:
3636
self._ask_data_enablement = None
3737
self._certified = None
3838
self._certification_note = None
@@ -135,12 +135,11 @@ def id(self) -> Optional[str]:
135135
return self._id
136136

137137
@property
138-
def project_id(self) -> str:
138+
def project_id(self) -> Optional[str]:
139139
return self._project_id
140140

141141
@project_id.setter
142-
@property_not_nullable
143-
def project_id(self, value: str):
142+
def project_id(self, value: Optional[str]):
144143
self._project_id = value
145144

146145
@property

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def publish(
310310
as_job: bool = False,
311311
hidden_views: Optional[Sequence[str]] = None,
312312
skip_connection_check: bool = False,
313+
parameters=None,
313314
):
314315
if connection_credentials is not None:
315316
import warnings
@@ -413,7 +414,7 @@ def publish(
413414

414415
# Send the publishing request to server
415416
try:
416-
server_response = self.post_request(url, xml_request, content_type)
417+
server_response = self.post_request(url, xml_request, content_type, parameters)
417418
except InternalServerError as err:
418419
if err.code == 504 and not as_job:
419420
err.content = "Timeout error while publishing. Please use asynchronous publishing to avoid timeouts."

tableauserverclient/server/request_factory.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
if TYPE_CHECKING:
1010
from tableauserverclient.server import Server
1111

12+
# this file could be largely replaced if we were willing to import the huge file from generateDS
13+
1214

1315
def _add_multipart(parts: Dict) -> Tuple[Any, str]:
1416
mime_multipart_parts = list()
@@ -146,21 +148,28 @@ def update_req(self, database_item):
146148

147149

148150
class DatasourceRequest(object):
149-
def _generate_xml(self, datasource_item, connection_credentials=None, connections=None):
151+
def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials=None, connections=None):
150152
xml_request = ET.Element("tsRequest")
151153
datasource_element = ET.SubElement(xml_request, "datasource")
152-
datasource_element.attrib["name"] = datasource_item.name
154+
if datasource_item.name:
155+
datasource_element.attrib["name"] = datasource_item.name
153156
if datasource_item.description:
154157
datasource_element.attrib["description"] = str(datasource_item.description)
155158
if datasource_item.use_remote_query_agent is not None:
156159
datasource_element.attrib["useRemoteQueryAgent"] = str(datasource_item.use_remote_query_agent).lower()
157160

158161
if datasource_item.ask_data_enablement:
159162
ask_data_element = ET.SubElement(datasource_element, "askData")
160-
ask_data_element.attrib["enablement"] = datasource_item.ask_data_enablement
163+
ask_data_element.attrib["enablement"] = datasource_item.ask_data_enablement.__str__()
161164

162-
project_element = ET.SubElement(datasource_element, "project")
163-
project_element.attrib["id"] = datasource_item.project_id
165+
if datasource_item.certified:
166+
datasource_element.attrib["isCertified"] = datasource_item.certified.__str__()
167+
if datasource_item.certification_note:
168+
datasource_element.attrib["certificationNote"] = datasource_item.certification_note
169+
170+
if datasource_item.project_id:
171+
project_element = ET.SubElement(datasource_element, "project")
172+
project_element.attrib["id"] = datasource_item.project_id
164173

165174
if connection_credentials is not None and connections is not None:
166175
raise RuntimeError("You cannot set both `connections` and `connection_credentials`")

tableauserverclient/server/request_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Operator:
3838
class Field:
3939
Args = "args"
4040
CompletedAt = "completedAt"
41+
ContentUrl = "contentUrl"
4142
CreatedAt = "createdAt"
4243
DomainName = "domainName"
4344
DomainNickname = "domainNickname"
@@ -147,7 +148,7 @@ def get_query_params(self):
147148
return params
148149

149150

150-
class ExcelRequestOptions(RequestOptionsBase):
151+
class ExcelRequestOptions(_FilterOptionsBase):
151152
def __init__(self, maxage: int = -1) -> None:
152153
super().__init__()
153154
self.max_age = maxage

test/test_datasource_model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33

44

55
class DatasourceModelTests(unittest.TestCase):
6-
def test_invalid_project_id(self):
7-
self.assertRaises(ValueError, TSC.DatasourceItem, None)
8-
datasource = TSC.DatasourceItem("10")
9-
with self.assertRaises(ValueError):
10-
datasource.project_id = None
6+
def test_nullable_project_id(self):
7+
datasource = TSC.DatasourceItem(name="10")
8+
self.assertEqual(datasource.project_id, None)
119

1210
def test_require_boolean_flag_bridge_fail(self):
1311
datasource = TSC.DatasourceItem("10")

test/test_view.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,19 @@ def test_populate_excel(self) -> None:
299299

300300
excel_file = b"".join(single_view.excel)
301301
self.assertEqual(response, excel_file)
302+
303+
def test_filter_excel(self) -> None:
304+
self.server.version = "3.8"
305+
self.baseurl = self.server.views.baseurl
306+
with open(POPULATE_EXCEL, "rb") as f:
307+
response = f.read()
308+
with requests_mock.mock() as m:
309+
m.get(self.baseurl + "/d79634e1-6063-4ec9-95ff-50acbf609ff5/crosstab/excel?maxAge=1", content=response)
310+
single_view = TSC.ViewItem()
311+
single_view._id = "d79634e1-6063-4ec9-95ff-50acbf609ff5"
312+
request_option = TSC.ExcelRequestOptions(maxage=1)
313+
request_option.vf("stuff", "1")
314+
self.server.views.populate_excel(single_view, request_option)
315+
316+
excel_file = b"".join(single_view.excel)
317+
self.assertEqual(response, excel_file)

0 commit comments

Comments
 (0)
0