Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve tests for 1.4 #17835

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('TimezoneSelector', () => {
expect(select).toBeInTheDocument();
userEvent.click(select);
const selection = await screen.findByTitle(
'GMT -06:00 (Mountain Daylight Time)',
'GMT -10:00 (Hawaii Standard Time)',
);
expect(selection).toBeInTheDocument();
userEvent.click(selection);
Expand Down
2 changes: 1 addition & 1 deletion superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
from superset.charts.commands.importers.dispatcher import ImportChartsCommand
from superset.charts.commands.update import UpdateChartCommand
from superset.charts.dao import ChartDAO
from superset.charts.post_processing import apply_post_process
from superset.charts.filters import (
ChartAllTextFilter,
ChartCertifiedFilter,
ChartFavoriteFilter,
ChartFilter,
)
from superset.charts.post_processing import apply_post_process
from superset.charts.schemas import (
CHART_SCHEMAS,
ChartPostSchema,
Expand Down
2 changes: 0 additions & 2 deletions superset/common/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,9 @@ def _get_top_groups(
# string into a timestamp.
if column_map[dimension].is_temporal and isinstance(value, str):
dttm = dateutil.parser.parse(value)
value = text(self.db_engine_spec.convert_dttm("TIMESTAMP", dttm))
value = text(
str(self.db_engine_spec.convert_dttm("TIMESTAMP", dttm))
)

group.append(groupby_exprs[dimension] == value)
groups.append(and_(*group))
Expand Down
2 changes: 1 addition & 1 deletion superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)

from flask_babel import gettext as __
from pytz import _FixedOffset # type: ignore
from pytz import _FixedOffset
from sqlalchemy.dialects.postgresql import ARRAY, DOUBLE_PRECISION, ENUM, JSON
from sqlalchemy.dialects.postgresql.base import PGInspector
from sqlalchemy.types import String, TypeEngine
Expand Down
8 changes: 2 additions & 6 deletions superset/utils/async_query_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,5 @@ def update_job(
logger.debug("********** logging event data to stream %s", scoped_stream_name)
logger.debug(event_data)

self._redis.xadd( # type: ignore
scoped_stream_name, event_data, "*", self._stream_limit
)
self._redis.xadd( # type: ignore
full_stream_name, event_data, "*", self._stream_limit_firehose
)
self._redis.xadd(scoped_stream_name, event_data, "*", self._stream_limit)
self._redis.xadd(full_stream_name, event_data, "*", self._stream_limit_firehose)
2 changes: 0 additions & 2 deletions tests/integration_tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,5 +2179,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"]


60 changes: 2 additions & 58 deletions tests/unit_tests/sql_parse_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# specific language governing permissions and limitations
# under the License.

from superset.sql_parse import ParsedQuery

import unittest
from typing import Set

import pytest
import sqlparse
Expand Down Expand Up @@ -535,22 +535,6 @@ 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.
Expand Down Expand Up @@ -995,46 +979,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.
Expand Down