Closes #74: Return slug when fetching or creating a dashboard.

This commit is contained in:
Marina Samuel 2018-05-28 17:12:17 -04:00
Родитель 2f6ab09280
Коммит 5dd6f7f930
3 изменённых файлов: 27 добавлений и 9 удалений

Просмотреть файл

@ -241,8 +241,14 @@ class RedashClient(object):
json_result, response = self._make_request(
requests.post, query_url, new_dashboard_args)
dashboard_id = json_result.get("id", None)
return dashboard_id
slug = json_result.get("slug", None)
url_path = "dashboard/{slug}".format(slug=slug)
dash_info = {
"dashboard_id": json_result.get("id", None),
"dashboard_slug": slug,
"slug_url": None if slug is None else urljoin(self.BASE_URL, url_path)
}
return dash_info
def get_public_url(self, dash_id):
url_path = "dashboards/{0}/share?{1}".format(

Просмотреть файл

@ -282,33 +282,45 @@ class TestRedashClient(AppTest):
def test_new_dashboard_exists(self):
DASH_NAME = "Activity Stream A/B Testing: Beep Meep"
EXPECTED_QUERY_ID = "query_id123"
EXPECTED_SLUG = "some_slug_it_made"
QUERY_ID_RESPONSE = {
"id": EXPECTED_QUERY_ID
"id": EXPECTED_QUERY_ID,
"slug": EXPECTED_SLUG
}
self.mock_requests_get.return_value = self.get_mock_response(
content=json.dumps(QUERY_ID_RESPONSE))
query_id = self.redash.create_new_dashboard(DASH_NAME)
dash_info = self.redash.create_new_dashboard(DASH_NAME)
self.assertEqual(query_id, EXPECTED_QUERY_ID)
self.assertEqual(dash_info["dashboard_id"], EXPECTED_QUERY_ID)
self.assertEqual(dash_info["dashboard_slug"], EXPECTED_SLUG)
self.assertEqual(
dash_info["slug_url"],
self.redash.BASE_URL + "dashboard/{slug}".format(slug=EXPECTED_SLUG))
self.assertEqual(self.mock_requests_get.call_count, 1)
self.assertEqual(self.mock_requests_post.call_count, 0)
def test_new_dashboard_doesnt_exist(self):
DASH_NAME = "Activity Stream A/B Testing: Beep Meep"
EXPECTED_QUERY_ID = "query_id123"
EXPECTED_SLUG = "some_slug_it_made"
QUERY_ID_RESPONSE = {
"id": EXPECTED_QUERY_ID
"id": EXPECTED_QUERY_ID,
"slug": EXPECTED_SLUG
}
self.mock_requests_get.return_value = self.get_mock_response(status=404)
self.mock_requests_post.return_value = self.get_mock_response(
content=json.dumps(QUERY_ID_RESPONSE))
query_id = self.redash.create_new_dashboard(DASH_NAME)
dash_info = self.redash.create_new_dashboard(DASH_NAME)
self.assertEqual(query_id, EXPECTED_QUERY_ID)
self.assertEqual(dash_info["dashboard_id"], EXPECTED_QUERY_ID)
self.assertEqual(dash_info["dashboard_slug"], EXPECTED_SLUG)
self.assertEqual(
dash_info["slug_url"],
self.redash.BASE_URL + "dashboard/{slug}".format(slug=EXPECTED_SLUG))
self.assertEqual(self.mock_requests_get.call_count, 1)
self.assertEqual(self.mock_requests_post.call_count, 1)

Просмотреть файл

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name = 'redash_client',
packages = ['redash_client'],
version = '0.2.2',
version = '0.2.4',
description = 'A client for the Redash API for stmo (https://sql.telemetry.mozilla.org)',
author = 'Marina Samuel',
author_email = 'msamuel@mozilla.com',