2020-06-09 04:46:28 -04:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2020-06-29 02:54:01 -04:00
|
|
|
# isort:skip_file
|
2020-06-09 04:46:28 -04:00
|
|
|
"""Unit tests for Superset"""
|
|
|
|
from typing import Any, Dict, Tuple
|
|
|
|
|
2020-07-07 08:26:54 -04:00
|
|
|
from marshmallow import ValidationError
|
2020-06-29 02:54:01 -04:00
|
|
|
from tests.test_app import app
|
2020-06-09 04:46:28 -04:00
|
|
|
from superset.charts.schemas import ChartDataQueryContextSchema
|
|
|
|
from superset.common.query_context import QueryContext
|
|
|
|
from tests.base_tests import SupersetTestCase
|
|
|
|
from tests.fixtures.query_context import get_query_context
|
|
|
|
|
|
|
|
|
2020-06-29 18:36:06 -04:00
|
|
|
class TestSchema(SupersetTestCase):
|
2020-06-09 04:46:28 -04:00
|
|
|
def test_query_context_limit_and_offset(self):
|
|
|
|
self.login(username="admin")
|
2020-12-22 20:10:19 -05:00
|
|
|
payload = get_query_context("birth_names")
|
2020-06-09 04:46:28 -04:00
|
|
|
|
|
|
|
# Use defaults
|
|
|
|
payload["queries"][0].pop("row_limit", None)
|
|
|
|
payload["queries"][0].pop("row_offset", None)
|
2020-07-14 09:37:19 -04:00
|
|
|
query_context = ChartDataQueryContextSchema().load(payload)
|
2020-06-09 04:46:28 -04:00
|
|
|
query_object = query_context.queries[0]
|
|
|
|
self.assertEqual(query_object.row_limit, app.config["ROW_LIMIT"])
|
|
|
|
self.assertEqual(query_object.row_offset, 0)
|
|
|
|
|
|
|
|
# Valid limit and offset
|
|
|
|
payload["queries"][0]["row_limit"] = 100
|
|
|
|
payload["queries"][0]["row_offset"] = 200
|
2020-07-07 08:26:54 -04:00
|
|
|
query_context = ChartDataQueryContextSchema().load(payload)
|
2020-06-09 04:46:28 -04:00
|
|
|
query_object = query_context.queries[0]
|
|
|
|
self.assertEqual(query_object.row_limit, 100)
|
|
|
|
self.assertEqual(query_object.row_offset, 200)
|
|
|
|
|
|
|
|
# too low limit and offset
|
|
|
|
payload["queries"][0]["row_limit"] = 0
|
|
|
|
payload["queries"][0]["row_offset"] = -1
|
2020-07-07 08:26:54 -04:00
|
|
|
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])
|
2020-06-29 02:54:01 -04:00
|
|
|
|
|
|
|
def test_query_context_null_timegrain(self):
|
|
|
|
self.login(username="admin")
|
2020-12-22 20:10:19 -05:00
|
|
|
payload = get_query_context("birth_names")
|
2020-06-29 02:54:01 -04:00
|
|
|
payload["queries"][0]["extras"]["time_grain_sqla"] = None
|
2020-07-07 08:26:54 -04:00
|
|
|
_ = ChartDataQueryContextSchema().load(payload)
|
2020-07-10 10:06:05 -04:00
|
|
|
|
2020-07-14 09:37:19 -04:00
|
|
|
def test_query_context_series_limit(self):
|
|
|
|
self.login(username="admin")
|
2020-12-22 20:10:19 -05:00
|
|
|
payload = get_query_context("birth_names")
|
2020-07-14 09:37:19 -04:00
|
|
|
|
|
|
|
payload["queries"][0]["timeseries_limit"] = 2
|
|
|
|
payload["queries"][0]["timeseries_limit_metric"] = {
|
|
|
|
"expressionType": "SIMPLE",
|
|
|
|
"column": {
|
|
|
|
"id": 334,
|
|
|
|
"column_name": "gender",
|
|
|
|
"filterable": True,
|
|
|
|
"groupby": True,
|
|
|
|
"is_dttm": False,
|
|
|
|
"type": "VARCHAR(16)",
|
|
|
|
"optionName": "_col_gender",
|
|
|
|
},
|
|
|
|
"aggregate": "COUNT_DISTINCT",
|
|
|
|
"label": "COUNT_DISTINCT(gender)",
|
|
|
|
}
|
|
|
|
_ = ChartDataQueryContextSchema().load(payload)
|
|
|
|
|
2020-07-10 10:06:05 -04:00
|
|
|
def test_query_context_null_post_processing_op(self):
|
|
|
|
self.login(username="admin")
|
2020-12-22 20:10:19 -05:00
|
|
|
payload = get_query_context("birth_names")
|
2020-07-10 10:06:05 -04:00
|
|
|
|
|
|
|
payload["queries"][0]["post_processing"] = [None]
|
|
|
|
query_context = ChartDataQueryContextSchema().load(payload)
|
|
|
|
self.assertEqual(query_context.queries[0].post_processing, [])
|