From dc40fe1c067723f292ff3a33fff500ef9760d403 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Mon, 20 Dec 2021 16:46:19 -0800 Subject: [PATCH] fix test lint --- superset/common/query_object.py | 2 - superset/config.py | 1 - tests/integration_tests/charts/api_tests.py | 2 - tests/unit_tests/sql_parse_tests.py | 77 +++------------------ 4 files changed, 10 insertions(+), 72 deletions(-) diff --git a/superset/common/query_object.py b/superset/common/query_object.py index 6ef00cdb835b6..e05cad7d6080c 100644 --- a/superset/common/query_object.py +++ b/superset/common/query_object.py @@ -25,8 +25,6 @@ from superset import app, db from superset.connectors.base.models import BaseDatasource from superset.connectors.connector_registry import ConnectorRegistry -from superset.exceptions import QueryObjectValidationError -from superset.typing import Metric, OrderBy from superset.exceptions import ( QueryClauseValidationException, QueryObjectValidationError, diff --git a/superset/config.py b/superset/config.py index 54545dfda89fd..7f504582c5920 100644 --- a/superset/config.py +++ b/superset/config.py @@ -38,7 +38,6 @@ from flask import Blueprint from flask_appbuilder.security.manager import AUTH_DB from pandas.io.parsers import STR_NA_VALUES -from typing_extensions import Literal from werkzeug.local import LocalProxy from superset.jinja_context import BaseTemplateProcessor diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index f77b60616802b..ac4ef4842ef1b 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -2118,5 +2118,3 @@ def test_chart_data_virtual_table_with_colons(self): assert "':asdf'" in result["query"] assert "':xyz:qwerty'" in result["query"] assert "':qwerty:'" in result["query"] - - diff --git a/tests/unit_tests/sql_parse_tests.py b/tests/unit_tests/sql_parse_tests.py index 63dfeeef15ac4..28e8f1f7d9dc6 100644 --- a/tests/unit_tests/sql_parse_tests.py +++ b/tests/unit_tests/sql_parse_tests.py @@ -15,11 +15,13 @@ # specific language governing permissions and limitations # under the License. +from typing import Set from superset.sql_parse import ParsedQuery import pytest import sqlparse +import unittest from superset.exceptions import QueryClauseValidationException from superset.sql_parse import ( @@ -535,29 +537,12 @@ def test_extract_tables_multistatement() -> None: } -def test_extract_tables_keyword() -> None: - """ - Test that table names that are keywords work as expected. - - If the table name is a ``sqlparse`` reserved keyword (eg, "table_name") the parser - needs extra logic to identify it. - """ - assert extract_tables("SELECT * FROM table_name") == {Table("table_name")} - assert extract_tables("SELECT * FROM table_name AS foo") == {Table("table_name")} - - # these 3 are considered keywords - assert extract_tables("SELECT * FROM catalog_name.schema_name.table_name") == { - Table("table_name", "schema_name", "catalog_name") - } - - def test_extract_tables_complex() -> None: """ Test a few complex queries. """ - assert ( - extract_tables( - """ + assert extract_tables( + """ SELECT sum(m_examples) AS "sum__m_example" FROM ( SELECT @@ -578,14 +563,12 @@ def test_extract_tables_complex() -> None: ORDER BY "sum__m_example" DESC LIMIT 10; """ - ) - == { - Table("my_l_table"), - Table("my_b_table"), - Table("my_t_table"), - Table("inner_table"), - } - ) + ) == { + Table("my_l_table"), + Table("my_b_table"), + Table("my_t_table"), + Table("inner_table"), + } assert ( extract_tables( @@ -995,46 +978,6 @@ def test_is_select_cte_with_comments() -> None: assert sql.is_select() -def test_cte_is_select() -> None: - """ - Some CTEs are not correctly identified as SELECTS. - """ - # `AS(` gets parsed as a function - sql = ParsedQuery( - """WITH foo AS( -SELECT - FLOOR(__time TO WEEK) AS "week", - name, - COUNT(DISTINCT user_id) AS "unique_users" -FROM "druid"."my_table" -GROUP BY 1,2 -) -SELECT - f.week, - f.name, - f.unique_users -FROM foo f""" - ) - assert sql.is_select() - - -def test_unknown_select() -> None: - """ - Test that `is_select` works when sqlparse fails to identify the type. - """ - sql = "WITH foo AS(SELECT 1) SELECT 1" - assert sqlparse.parse(sql)[0].get_type() == "UNKNOWN" - assert ParsedQuery(sql).is_select() - - sql = "WITH foo AS(SELECT 1) INSERT INTO my_table (a) VALUES (1)" - assert sqlparse.parse(sql)[0].get_type() == "UNKNOWN" - assert not ParsedQuery(sql).is_select() - - sql = "WITH foo AS(SELECT 1) DELETE FROM my_table" - assert sqlparse.parse(sql)[0].get_type() == "UNKNOWN" - assert not ParsedQuery(sql).is_select() - - def test_get_query_with_new_limit_comment() -> None: """ Test that limit is applied correctly.