Skip to content
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
9 changes: 7 additions & 2 deletions tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,13 @@ class Connection(object):
@_tsrequest_wrapped
def update_req(self, xml_request: ET.Element, connection_item: "ConnectionItem") -> None:
connection_element = ET.SubElement(xml_request, "connection")
if connection_item.server_address is not None:
connection_element.attrib["serverAddress"] = connection_item.server_address.lower()
if (server_address := connection_item.server_address) is not None:
if (conn_type := connection_item.connection_type) is not None:
if conn_type.casefold() != "odata".casefold():
server_address = server_address.lower()
else:
server_address = server_address.lower()
connection_element.attrib["serverAddress"] = server_address
if connection_item.server_port is not None:
connection_element.attrib["serverPort"] = str(connection_item.server_port)
if connection_item.username is not None:
Expand Down
7 changes: 7 additions & 0 deletions test/assets/odata_connection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_23.xsd">
<connections>
<connection id="17376070-64d1-4d17-acb4-a56e4b5b1768" type="odata" embedPassword="false" serverAddress="https://odata.website.com/TestODataEndpoint" userName="" queryTaggingEnabled="false">
<datasource id="d82f784e-178f-4b7e-a723-d8f615155a42" name="People (services.odata.org/ODataPeopleService/People)"/>
</connection>
</connections>
</tsResponse>
29 changes: 29 additions & 0 deletions test/test_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
GET_EMPTY_XML = os.path.join(TEST_ASSET_DIR, "workbook_get_empty.xml")
GET_INVALID_DATE_XML = os.path.join(TEST_ASSET_DIR, "workbook_get_invalid_date.xml")
GET_XML = os.path.join(TEST_ASSET_DIR, "workbook_get.xml")
ODATA_XML = os.path.join(TEST_ASSET_DIR, "odata_connection.xml")
POPULATE_CONNECTIONS_XML = os.path.join(TEST_ASSET_DIR, "workbook_populate_connections.xml")
POPULATE_PDF = os.path.join(TEST_ASSET_DIR, "populate_pdf.pdf")
POPULATE_POWERPOINT = os.path.join(TEST_ASSET_DIR, "populate_powerpoint.pptx")
Expand Down Expand Up @@ -944,3 +945,31 @@ def test_bad_download_response(self) -> None:
)
file_path = self.server.workbooks.download("9dbd2263-16b5-46e1-9c43-a76bb8ab65fb", td)
self.assertTrue(os.path.exists(file_path))

def test_odata_connection(self) -> None:
self.baseurl = self.server.workbooks.baseurl
workbook = TSC.WorkbookItem("project", "test")
workbook._id = "06b944d2-959d-4604-9305-12323c95e70e"
connection = TSC.ConnectionItem()
url = "https://odata.website.com/TestODataEndpoint"
connection.server_address = url
connection._connection_type = "odata"
connection._id = "17376070-64d1-4d17-acb4-a56e4b5b1768"

creds = TSC.ConnectionCredentials("", "", True)
connection.connection_credentials = creds
with open(ODATA_XML, "rb") as f:
response_xml = f.read().decode("utf-8")

with requests_mock.mock() as m:
m.put(f"{self.baseurl}/{workbook.id}/connections/{connection.id}", text=response_xml)
self.server.workbooks.update_connection(workbook, connection)

history = m.request_history

request = history[0]
xml = fromstring(request.body)
xml_connection = xml.find(".//connection")

assert xml_connection is not None
self.assertEqual(xml_connection.get("serverAddress"), url)