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

Add get_query method #70

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+54 −0
Diff settings

Always

Just for now

@@ -377,3 +377,20 @@ def get_widget_from_dash(self, name):
requests.get, query_url)
widgets = json_result.get("widgets", [])
return widgets

def get_query(self, query_id):
url_path = "queries/{0}?{1}".format(str(query_id), self._url_params)
query_url = urljoin(self.API_BASE_URL, url_path)

query, _ = self._make_request(requests.get, query_url)
visualization = self._get_visualization(query_id)

return {
"id": query_id,
"description": query.get("description", None),
"name": query.get("name", None),
"data_source_id": query.get("data_source_id", None),
"options": visualization.get("options", None),
"type": visualization.get("type", None),
"query": query.get("query", None)
}
@@ -487,3 +487,40 @@ def test_get_widget_from_dash_returns_correctly_flattened_widgets(self):

self.assertEqual(widget_list, FLAT_WIDGETS)
self.assertEqual(self.mock_requests_get.call_count, 1)

def test_get_query_returns_correct_attributes(self):
self.get_calls = 0
QUERY_RESPONSE = {
"id": 5,
"description": "SomeQuery",
"name": "Query Title",
"data_source_id": 5,
}
VISUALIZATIONS_FOR_QUERY = {
"visualizations": [
{"options": {}},
{"options": {}},
]
}

def get_server(url):
response = self.get_mock_response()
if self.get_calls == 0:
response = self.get_mock_response(
content=json.dumps(QUERY_RESPONSE))
else:
response = self.get_mock_response(
content=json.dumps(VISUALIZATIONS_FOR_QUERY))

self.get_calls += 1
return response

self.mock_requests_get.side_effect = get_server

query = self.redash.get_query(5)

self.assertEqual(query["id"], QUERY_RESPONSE["id"])
self.assertEqual(query["description"], QUERY_RESPONSE["description"])
self.assertEqual(query["name"], QUERY_RESPONSE["name"])
self.assertEqual(query["data_source_id"], QUERY_RESPONSE["data_source_id"])
self.assertEqual(self.mock_requests_get.call_count, 2)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.