Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 14, 2018
1 parent 7e81913 commit 706d860
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def apply_limit_to_sql(cls, sql, limit, database):
)
return database.compile_sqla_query(qry)
elif LimitMethod.FORCE_LIMIT:
no_limit = re.sub(r'(?i)\s+LIMIT\s+\d+;?(\s|;)*$', '', sql)
no_limit = re.sub(r"""
(?ix) # case insensitive, verbose
\s+ # whitespace
Expand Down
48 changes: 24 additions & 24 deletions tests/db_engine_specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import textwrap

from superset import db
from superset.db_engine_specs import (
HiveEngineSpec, MssqlEngineSpec, MySQLEngineSpec)
from superset.models.core import Database
Expand Down Expand Up @@ -85,11 +84,14 @@ def test_job_2_launched_stage_2_stages_progress(self):
""".split('\n') # noqa ignore: E501
self.assertEquals(60, HiveEngineSpec.progress(log))

def get_generic_database(self):
return Database(sqlalchemy_uri='mysql://localhost')

def sql_limit_regex(
self, sql, expected_sql,
engine_spec_class=MySQLEngineSpec,
limit=1000):
main = self.get_main_database(db.session)
main = self.get_generic_database()
limited = engine_spec_class.apply_limit_to_sql(sql, limit, main)
self.assertEquals(expected_sql, limited)

Expand Down Expand Up @@ -146,15 +148,14 @@ def test_limit_query_with_limit_subquery(self):

def test_limit_with_expr(self):
self.sql_limit_regex(
textwrap.dedent(
"""\
SELECT
'LIMIT 777' AS a
, b
FROM
table
LIMIT
99990"""),
textwrap.dedent("""\
SELECT
'LIMIT 777' AS a
, b
FROM
table
LIMIT
99990"""),
textwrap.dedent("""\
SELECT
'LIMIT 777' AS a
Expand All @@ -165,18 +166,17 @@ def test_limit_with_expr(self):

def test_limit_expr_and_semicolon(self):
self.sql_limit_regex(
textwrap.dedent(
"""\
SELECT
'LIMIT 777' AS a
, b
FROM
table
LIMIT 99990 ;"""),
textwrap.dedent("""\
SELECT
'LIMIT 777' AS a
, b
FROM
table LIMIT 1000"""),
SELECT
'LIMIT 777' AS a
, b
FROM
table
LIMIT 99990 ;"""),
textwrap.dedent("""\
SELECT
'LIMIT 777' AS a
, b
FROM
table LIMIT 1000"""),
)

0 comments on commit 706d860

Please sign in to comment.