feat: deprecate old API and create new API for dashes created by me (#19434)

* feat: deprecate old API and create new API for dashes created by me

* add tests

* fix previous test

* fix test and lint

* fix sqlite test

* fix lint

* fix lint

* lint

* fix tests

* fix tests

* use dashboards get list instead

* clean unnecessary marshmallow schema

* Update superset/views/core.py

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

* lint

Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
This commit is contained in:
Daniel Vaz Gaspar
2022-04-08 09:05:22 +01:00
committed by GitHub
parent 8da2c9b96a
commit d6d2777ada
9 changed files with 143 additions and 24 deletions

View File

@@ -18,6 +18,7 @@
"""Unit tests for Superset"""
import json
from io import BytesIO
from time import sleep
from typing import List, Optional
from unittest.mock import patch
from zipfile import is_zipfile, ZipFile
@@ -27,7 +28,6 @@ from tests.integration_tests.insert_chart_mixin import InsertChartMixin
import pytest
import prison
import yaml
from sqlalchemy.sql import func
from freezegun import freeze_time
from sqlalchemy import and_
@@ -160,6 +160,27 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
db.session.delete(fav_dashboard)
db.session.commit()
@pytest.fixture()
def create_created_by_admin_dashboards(self):
with self.create_app().app_context():
dashboards = []
admin = self.get_user("admin")
for cx in range(2):
dashboard = self.insert_dashboard(
f"create_title{cx}",
f"create_slug{cx}",
[admin.id],
created_by=admin,
)
sleep(1)
dashboards.append(dashboard)
yield dashboards
for dashboard in dashboards:
db.session.delete(dashboard)
db.session.commit()
@pytest.fixture()
def create_dashboard_with_report(self):
with self.create_app().app_context():
@@ -674,7 +695,41 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
rv = self.get_assert_metric(uri, "get_list")
self.assertEqual(rv.status_code, 200)
data = json.loads(rv.data.decode("utf-8"))
self.assertEqual(data["count"], 6)
self.assertEqual(data["count"], 5)
@pytest.mark.usefixtures("create_created_by_admin_dashboards")
def test_get_dashboards_created_by_me(self):
"""
Dashboard API: Test get dashboards created by current user
"""
query = {
"columns": ["created_on_delta_humanized", "dashboard_title", "url"],
"filters": [{"col": "created_by", "opr": "created_by_me", "value": "me"}],
"order_column": "changed_on",
"order_direction": "desc",
"page": 0,
"page_size": 100,
}
uri = f"api/v1/dashboard/?q={prison.dumps(query)}"
self.login(username="admin")
rv = self.client.get(uri)
data = json.loads(rv.data.decode("utf-8"))
assert rv.status_code == 200
assert len(data["result"]) == 2
assert list(data["result"][0].keys()) == query["columns"]
expected_results = [
{
"dashboard_title": "create_title1",
"url": "/superset/dashboard/create_slug1/",
},
{
"dashboard_title": "create_title0",
"url": "/superset/dashboard/create_slug0/",
},
]
for idx, response_item in enumerate(data["result"]):
for key, value in expected_results[idx].items():
assert response_item[key] == value
def create_dashboard_import(self):
buf = BytesIO()