From 706d8608f6e28f282f029fb1c6c3fd5f87a84343 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 14 May 2018 13:36:45 -0500 Subject: [PATCH] Fix tests --- superset/db_engine_specs.py | 1 - tests/db_engine_specs_test.py | 48 +++++++++++++++++------------------ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 88c51eadbcd38..b91d93f393aca 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -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 diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py index 71c93ee328f7f..c38e4f569023a 100644 --- a/tests/db_engine_specs_test.py +++ b/tests/db_engine_specs_test.py @@ -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 @@ -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) @@ -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 @@ -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"""), )