Skip to content
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

ggrushka/DAR-385/tableau url limitation #131

Merged
merged 3 commits into from
Jul 4, 2024
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
5 changes: 4 additions & 1 deletion apollo/integrations/tableau/tableau_proxy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def api_request(
"X-Tableau-Auth": self._server.auth_token,
"Content-Type": content_type,
}
url = f"{self._server.baseurl}/sites/{self._server.site_id}/{path}"
if path.startswith("/"):
url = f"{self._server.baseurl}{path}"
else:
url = f"{self._server.baseurl}/sites/{self._server.site_id}/{path}"
response = requests.request(
method=request_method, url=url, data=data, headers=headers, params=params
)
Expand Down
61 changes: 61 additions & 0 deletions tests/test_tableau_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,64 @@ def test_api_request(
},
params={"pageNumber": 1, "pageSize": 10},
)

@patch("apollo.integrations.tableau.tableau_proxy_client.JwtAuth")
@patch("apollo.integrations.tableau.tableau_proxy_client.Server")
@patch("apollo.integrations.tableau.tableau_proxy_client.generate_jwt")
@patch("requests.request")
def test_api_request_with_url(
self, mock_request, mock_jwt_gen, mock_server_init, mock_creds_init
):
mock_response = create_autospec(Response)
mock_request.return_value = mock_response
expected_result = (
"<tsResponse>\n\t<views>\n"
'\t\t<view id="view-id" name="view-name" contentUrl="content-url">\n'
'\t\t\t<workbook id="workbook-id" />\n\t\t\t<owner id="owner-id" />\n'
'\t\t\t<usage totalViewCount="total-count" />\n\t\t</view>\n\t</views>\n</tsResponse>'
)
mock_response.status_code = 200
mock_response.text = expected_result

mock_jwt_gen.return_value = "fake_jwt"
mock_server_init.return_value = self._mock_client
mock_creds_init.return_value = self._mock_creds
self._mock_client.baseurl = "https://example.com"
self._mock_client.site_id = "sample_site_id"
self._mock_client.auth_token = "fizz|buzz|sample_site_id"

result = self._agent.execute_operation(
"tableau",
"_query",
{
"trace_id": "1234",
"skip_cache": True,
"commands": [
{
"method": "api_request",
"kwargs": {
"path": "/sites/sample_site_id/views?includeUsageStatistics=true",
"request_method": "GET",
"content_type": "application/xml",
"params": {"pageNumber": 1, "pageSize": 10},
},
}
],
},
credentials=_TABLEAU_CREDENTIALS,
)
self.assertIsNone(result.result.get(ATTRIBUTE_NAME_ERROR))

response = result.result[ATTRIBUTE_NAME_RESULT]
self.assertEqual((expected_result, 200), response)
self._mock_client.auth.sign_in.assert_called_once_with(self._mock_creds)
mock_request.assert_called_once_with(
method="GET",
url="https://example.com/sites/sample_site_id/views?includeUsageStatistics=true",
data=None,
headers={
"X-Tableau-Auth": "fizz|buzz|sample_site_id",
"Content-Type": "application/xml",
},
params={"pageNumber": 1, "pageSize": 10},
)