[charts] New, REST API (#8917)

* [charts] New REST API

* [charts] Small improvements

* [charts] Fix, lint

* [charts] Tests and datasource validation

* [charts] Fix, lint

* [charts] DRY post schemas

* [charts] lint and improve type declarations

* [charts] DRY owned REST APIs

* [charts] Small fixes

* [charts] More tests

* [charts] Tests and DRY

* [charts] Tests for update

* [charts] More tests

* [charts] Fix, isort

* [charts] DRY and improve quality

* [charts] DRY and more tests

* [charts] Refactor base for api and schemas

* [charts] Fix bug on partial updates for dashboards

* [charts] Fix missing apache license

* black app.py after merge

* [charts] Fix, missing imports and black

* [api] Log on sqlalchemy error

* [api] isort
This commit is contained in:
Daniel Vaz Gaspar
2020-01-21 18:04:52 +00:00
committed by Maxime Beauchemin
parent 2fc5fd4f29
commit 74158694c5
16 changed files with 1425 additions and 586 deletions

View File

@@ -19,17 +19,19 @@ import json
from typing import List
import prison
from flask_appbuilder.security.sqla import models as ab_models
from superset import db, security_manager
from superset.models import core as models
from superset.models.slice import Slice
from superset.views.base import generate_download_headers
from .base_api_tests import ApiOwnersTestCaseMixin
from .base_tests import SupersetTestCase
class DashboardApiTests(SupersetTestCase):
class DashboardApiTests(SupersetTestCase, ApiOwnersTestCaseMixin):
resource_name = "dashboard"
def __init__(self, *args, **kwargs):
super(DashboardApiTests, self).__init__(*args, **kwargs)
@@ -63,14 +65,6 @@ class DashboardApiTests(SupersetTestCase):
db.session.commit()
return dashboard
def get_user(self, username: str) -> ab_models.User:
user = (
db.session.query(security_manager.user_model)
.filter_by(username=username)
.one_or_none()
)
return user
def test_delete_dashboard(self):
"""
Dashboard API: Test delete
@@ -367,64 +361,6 @@ class DashboardApiTests(SupersetTestCase):
db.session.delete(user_alpha2)
db.session.commit()
def test_get_related_owners(self):
"""
Dashboard API: Test dashboard get related owners
"""
self.login(username="admin")
uri = f"api/v1/dashboard/related/owners"
rv = self.client.get(uri)
self.assertEqual(rv.status_code, 200)
response = json.loads(rv.data.decode("utf-8"))
expected_response = {
"count": 6,
"result": [
{"text": "admin user", "value": 1},
{"text": "alpha user", "value": 5},
{"text": "explore_beta user", "value": 6},
{"text": "gamma user", "value": 2},
{"text": "gamma2 user", "value": 3},
{"text": "gamma_sqllab user", "value": 4},
],
}
self.assertEqual(response["count"], expected_response["count"])
# This is needed to be implemented like this because ordering varies between
# postgres and mysql
for result in expected_response["result"]:
self.assertIn(result, response["result"])
def test_get_filter_related_owners(self):
"""
Dashboard API: Test dashboard get filter related owners
"""
self.login(username="admin")
argument = {"filter": "a"}
uri = "api/v1/dashboard/related/owners?{}={}".format(
"q", prison.dumps(argument)
)
rv = self.client.get(uri)
self.assertEqual(rv.status_code, 200)
response = json.loads(rv.data.decode("utf-8"))
expected_response = {
"count": 2,
"result": [
{"text": "admin user", "value": 1},
{"text": "alpha user", "value": 5},
],
}
self.assertEqual(response, expected_response)
def test_get_related_fail(self):
"""
Dashboard API: Test dashboard get related fail
"""
self.login(username="admin")
uri = "api/v1/dashboard/related/owner"
rv = self.client.get(uri)
self.assertEqual(rv.status_code, 404)
def test_export(self):
"""
Dashboard API: Test dashboard export