mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
feat(api): bump marshmallow and FAB to version 3 (#9964)
* feat(api): bump marshmallow and FAB to version 3 * revert query context tests changes * obey mypy * fix tests * ignore types that collide with marshmallow * preparing for RC2 * fix tests for marshmallow 3 * typing fixes for marshmallow * fix tests and black * fix tests * bump to RC3 and lint * Test RC4 * Final 3.0.0 * Address comments, fix tests, better naming, docs * fix test * couple of fixes, addressing comments * bumping marshmallow
This commit is contained in:
committed by
GitHub
parent
bacf567656
commit
878dbcda3f
@@ -51,7 +51,10 @@ appbuilder.add_api(Model1Api)
|
||||
class TestBaseModelRestApi(SupersetTestCase):
|
||||
def test_default_missing_declaration_get(self):
|
||||
"""
|
||||
API: Test default missing declaration on get
|
||||
API: Test default missing declaration on get
|
||||
|
||||
We want to make sure that not declared list_columns will
|
||||
not render all columns by default but just the model's pk
|
||||
"""
|
||||
# Check get list response
|
||||
self.login(username="admin")
|
||||
@@ -73,6 +76,12 @@ class TestBaseModelRestApi(SupersetTestCase):
|
||||
self.assertEqual(list(response["result"].keys()), ["id"])
|
||||
|
||||
def test_default_missing_declaration_put_spec(self):
|
||||
"""
|
||||
API: Test default missing declaration on put openapi spec
|
||||
|
||||
We want to make sure that not declared edit_columns will
|
||||
not render all columns by default but just the model's pk
|
||||
"""
|
||||
self.login(username="admin")
|
||||
uri = "api/v1/_openapi"
|
||||
rv = self.client.get(uri)
|
||||
@@ -91,6 +100,12 @@ class TestBaseModelRestApi(SupersetTestCase):
|
||||
)
|
||||
|
||||
def test_default_missing_declaration_post(self):
|
||||
"""
|
||||
API: Test default missing declaration on post
|
||||
|
||||
We want to make sure that not declared add_columns will
|
||||
not accept all columns by default
|
||||
"""
|
||||
dashboard_data = {
|
||||
"dashboard_title": "title1",
|
||||
"slug": "slug1",
|
||||
@@ -102,30 +117,41 @@ class TestBaseModelRestApi(SupersetTestCase):
|
||||
self.login(username="admin")
|
||||
uri = "api/v1/model1api/"
|
||||
rv = self.client.post(uri, json=dashboard_data)
|
||||
# dashboard model accepts all fields are null
|
||||
self.assertEqual(rv.status_code, 201)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(list(response["result"].keys()), ["id"])
|
||||
model = db.session.query(Dashboard).get(response["id"])
|
||||
self.assertEqual(model.dashboard_title, None)
|
||||
self.assertEqual(model.slug, None)
|
||||
self.assertEqual(model.position_json, None)
|
||||
self.assertEqual(model.json_metadata, None)
|
||||
db.session.delete(model)
|
||||
db.session.commit()
|
||||
self.assertEqual(rv.status_code, 422)
|
||||
expected_response = {
|
||||
"message": {
|
||||
"css": ["Unknown field."],
|
||||
"dashboard_title": ["Unknown field."],
|
||||
"json_metadata": ["Unknown field."],
|
||||
"position_json": ["Unknown field."],
|
||||
"published": ["Unknown field."],
|
||||
"slug": ["Unknown field."],
|
||||
}
|
||||
}
|
||||
self.assertEqual(response, expected_response)
|
||||
|
||||
def test_default_missing_declaration_put(self):
|
||||
"""
|
||||
API: Test default missing declaration on put
|
||||
|
||||
We want to make sure that not declared edit_columns will
|
||||
not accept all columns by default
|
||||
"""
|
||||
dashboard = db.session.query(Dashboard).first()
|
||||
dashboard_data = {"dashboard_title": "CHANGED", "slug": "CHANGED"}
|
||||
self.login(username="admin")
|
||||
uri = f"api/v1/model1api/{dashboard.id}"
|
||||
rv = self.client.put(uri, json=dashboard_data)
|
||||
# dashboard model accepts all fields are null
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
changed_dashboard = db.session.query(Dashboard).get(dashboard.id)
|
||||
self.assertNotEqual(changed_dashboard.dashboard_title, "CHANGED")
|
||||
self.assertNotEqual(changed_dashboard.slug, "CHANGED")
|
||||
self.assertEqual(rv.status_code, 422)
|
||||
expected_response = {
|
||||
"message": {
|
||||
"dashboard_title": ["Unknown field."],
|
||||
"slug": ["Unknown field."],
|
||||
}
|
||||
}
|
||||
self.assertEqual(response, expected_response)
|
||||
|
||||
|
||||
class ApiOwnersTestCaseMixin:
|
||||
|
||||
@@ -338,7 +338,8 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
self.assertEqual(rv.status_code, 400)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(
|
||||
response, {"message": {"datasource_type": ["Not a valid choice."]}}
|
||||
response,
|
||||
{"message": {"datasource_type": ["Must be one of: druid, table, view."]}},
|
||||
)
|
||||
chart_data = {
|
||||
"slice_name": "title1",
|
||||
@@ -444,7 +445,8 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
self.assertEqual(rv.status_code, 400)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(
|
||||
response, {"message": {"datasource_type": ["Not a valid choice."]}}
|
||||
response,
|
||||
{"message": {"datasource_type": ["Must be one of: druid, table, view."]}},
|
||||
)
|
||||
chart_data = {"datasource_id": 0, "datasource_type": "table"}
|
||||
uri = f"api/v1/chart/{chart.id}"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"""Unit tests for Superset"""
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
from marshmallow import ValidationError
|
||||
from tests.test_app import app
|
||||
from superset.charts.schemas import ChartDataQueryContextSchema
|
||||
from superset.common.query_context import QueryContext
|
||||
@@ -39,8 +40,7 @@ class TestSchema(SupersetTestCase):
|
||||
# Use defaults
|
||||
payload["queries"][0].pop("row_limit", None)
|
||||
payload["queries"][0].pop("row_offset", None)
|
||||
query_context, errors = load_query_context(payload)
|
||||
self.assertEqual(errors, {})
|
||||
query_context = load_query_context(payload)
|
||||
query_object = query_context.queries[0]
|
||||
self.assertEqual(query_object.row_limit, app.config["ROW_LIMIT"])
|
||||
self.assertEqual(query_object.row_offset, 0)
|
||||
@@ -48,8 +48,7 @@ class TestSchema(SupersetTestCase):
|
||||
# Valid limit and offset
|
||||
payload["queries"][0]["row_limit"] = 100
|
||||
payload["queries"][0]["row_offset"] = 200
|
||||
query_context, errors = ChartDataQueryContextSchema().load(payload)
|
||||
self.assertEqual(errors, {})
|
||||
query_context = ChartDataQueryContextSchema().load(payload)
|
||||
query_object = query_context.queries[0]
|
||||
self.assertEqual(query_object.row_limit, 100)
|
||||
self.assertEqual(query_object.row_offset, 200)
|
||||
@@ -57,9 +56,10 @@ class TestSchema(SupersetTestCase):
|
||||
# too low limit and offset
|
||||
payload["queries"][0]["row_limit"] = 0
|
||||
payload["queries"][0]["row_offset"] = -1
|
||||
query_context, errors = ChartDataQueryContextSchema().load(payload)
|
||||
self.assertIn("row_limit", errors["queries"][0])
|
||||
self.assertIn("row_offset", errors["queries"][0])
|
||||
with self.assertRaises(ValidationError) as context:
|
||||
_ = ChartDataQueryContextSchema().load(payload)
|
||||
self.assertIn("row_limit", context.exception.messages["queries"][0])
|
||||
self.assertIn("row_offset", context.exception.messages["queries"][0])
|
||||
|
||||
def test_query_context_null_timegrain(self):
|
||||
self.login(username="admin")
|
||||
@@ -68,5 +68,4 @@ class TestSchema(SupersetTestCase):
|
||||
payload = get_query_context(table.name, table.id, table.type)
|
||||
|
||||
payload["queries"][0]["extras"]["time_grain_sqla"] = None
|
||||
_, errors = ChartDataQueryContextSchema().load(payload)
|
||||
self.assertEqual(errors, {})
|
||||
_ = ChartDataQueryContextSchema().load(payload)
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
"slug": "slug1_changed",
|
||||
"position_json": '{"b": "B"}',
|
||||
"css": "css_changed",
|
||||
"json_metadata": '{"a": "A"}',
|
||||
"json_metadata": '{"refresh_frequency": 30}',
|
||||
"published": False,
|
||||
}
|
||||
|
||||
@@ -473,7 +473,7 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
"owners": [admin_id],
|
||||
"position_json": '{"a": "A"}',
|
||||
"css": "css",
|
||||
"json_metadata": '{"b": "B"}',
|
||||
"json_metadata": '{"refresh_frequency": 30}',
|
||||
"published": True,
|
||||
}
|
||||
self.login(username="admin")
|
||||
|
||||
@@ -371,6 +371,11 @@ class TestDatasetApi(SupersetTestCase):
|
||||
self.login(username="admin")
|
||||
rv = self.get_assert_metric(uri, "get")
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
for column in data["result"]["columns"]:
|
||||
column.pop("changed_on", None)
|
||||
column.pop("created_on", None)
|
||||
|
||||
data["result"]["columns"].append(new_column_data)
|
||||
rv = self.client.put(uri, json={"columns": data["result"]["columns"]})
|
||||
|
||||
@@ -404,6 +409,10 @@ class TestDatasetApi(SupersetTestCase):
|
||||
# Get current cols and alter one
|
||||
rv = self.get_assert_metric(uri, "get")
|
||||
resp_columns = json.loads(rv.data.decode("utf-8"))["result"]["columns"]
|
||||
for column in resp_columns:
|
||||
column.pop("changed_on", None)
|
||||
column.pop("created_on", None)
|
||||
|
||||
resp_columns[0]["groupby"] = False
|
||||
resp_columns[0]["filterable"] = False
|
||||
v = self.client.put(uri, json={"columns": resp_columns})
|
||||
|
||||
@@ -39,8 +39,7 @@ class TestQueryContext(SupersetTestCase):
|
||||
payload = get_query_context(
|
||||
table.name, table.id, table.type, add_postprocessing_operations=True
|
||||
)
|
||||
query_context, errors = ChartDataQueryContextSchema().load(payload)
|
||||
self.assertDictEqual(errors, {})
|
||||
query_context = ChartDataQueryContextSchema().load(payload)
|
||||
self.assertEqual(len(query_context.queries), len(payload["queries"]))
|
||||
for query_idx, query in enumerate(query_context.queries):
|
||||
payload_query = payload["queries"][query_idx]
|
||||
|
||||
Reference in New Issue
Block a user