Skip to content

Commit

Permalink
Closes #69: Update get_widget_from_dash() to use redash's new json re…
Browse files Browse the repository at this point in the history
…sponse format.
  • Loading branch information
Marina Samuel committed May 10, 2018
1 parent 1b653bf commit cc6b370
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
19 changes: 4 additions & 15 deletions redash_client/client.py
Expand Up @@ -369,22 +369,11 @@ def get_widget_from_dash(self, name):
query_url = urljoin(self.API_BASE_URL, url_path)

# Note: row_arr is in the form:
# [[{}, {}], [{}], ...]
# [{}, {}, {} ...]
#
# Where each sub-array represents a row of widgets in a redash dashboard

get_widget_args = json.dumps({"name": name})
# Where each object represents a widget in a redash dashboard

json_result, response = self._make_request(
requests.get, query_url, get_widget_args)
row_arr = json_result.get("widgets", [])

# Return a flattened list of all widgets
widgets = []
for row in row_arr:
if len(row) == 1:
widgets.append(row[0])
elif len(row) == 2:
widgets += [row[0], row[1]]

requests.get, query_url)
widgets = json_result.get("widgets", [])
return widgets
8 changes: 4 additions & 4 deletions redash_client/tests/test_redash.py
Expand Up @@ -461,13 +461,13 @@ def test_get_widget_from_dash_returns_correctly_flattened_widgets(self):
}]

WIDGETS_RESPONSE = {
"widgets": [[{
"widgets": [{
"visualization": {
"query": {
"id": EXPECTED_QUERY_ID
}
}}],
[{"visualization": {
}},
{"visualization": {
"query": {
"id": EXPECTED_QUERY_ID2
}
Expand All @@ -477,7 +477,7 @@ def test_get_widget_from_dash_returns_correctly_flattened_widgets(self):
"id": EXPECTED_QUERY_ID3
}
}}
]]
]
}

self.mock_requests_get.return_value = self.get_mock_response(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@
setup(
name = 'redash_client',
packages = ['redash_client'],
version = '0.2.1',
version = '0.2.2',
description = 'A client for the re:dash API for stmo (https://sql.telemetry.mozilla.org)',
author = 'Marina Samuel',
author_email = 'msamuel@mozilla.com',
Expand Down

0 comments on commit cc6b370

Please sign in to comment.