[query] Migrate api v1 query to new location (#9479)

* [query] Migrate api v1 query to new location

* Improved errors and tests

* [query] nit and revert undesired change

* [query] lint

* [query] revert nan change

* Update superset/queries/api.py

Co-Authored-By: Ville Brofeldt <33317356+villebro@users.noreply.github.com>

* Update tests/queries/api_tests.py

Co-Authored-By: Ville Brofeldt <33317356+villebro@users.noreply.github.com>

* change endpoint location to charts

Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
This commit is contained in:
Daniel Vaz Gaspar
2020-04-09 09:05:49 +01:00
committed by GitHub
parent 5565895819
commit 0610c489bb
4 changed files with 157 additions and 3 deletions

View File

@@ -16,7 +16,7 @@
# under the License.
"""Unit tests for Superset"""
import json
from typing import List, Optional
from typing import Any, Dict, List, Optional
import prison
from sqlalchemy.sql import func
@@ -69,6 +69,22 @@ class ChartApiTests(SupersetTestCase, ApiOwnersTestCaseMixin):
db.session.commit()
return slice
def _get_query_context(self) -> Dict[str, Any]:
self.login(username="admin")
slc = self.get_slice("Girl Name Cloud", db.session)
return {
"datasource": {"id": slc.datasource_id, "type": slc.datasource_type},
"queries": [
{
"granularity": "ds",
"groupby": ["name"],
"metrics": [{"label": "sum__num"}],
"filters": [],
"row_limit": 100,
}
],
}
def test_delete_chart(self):
"""
Chart API: Test delete
@@ -580,3 +596,25 @@ class ChartApiTests(SupersetTestCase, ApiOwnersTestCaseMixin):
self.assertEqual(rv.status_code, 200)
data = json.loads(rv.data.decode("utf-8"))
self.assertEqual(data["count"], 0)
def test_chart_data(self):
"""
Query API: Test chart data query
"""
self.login(username="admin")
query_context = self._get_query_context()
uri = "api/v1/chart/data"
rv = self.client.post(uri, json=query_context)
self.assertEqual(rv.status_code, 200)
data = json.loads(rv.data.decode("utf-8"))
self.assertEqual(data[0]["rowcount"], 100)
def test_query_exec_not_allowed(self):
"""
Query API: Test chart data query not allowed
"""
self.login(username="gamma")
query_context = self._get_query_context()
uri = "api/v1/chart/data"
rv = self.client.post(uri, json=query_context)
self.assertEqual(rv.status_code, 401)