diff --git a/tests/base_tests.py b/tests/base_tests.py index 670f26d878f67..1c593320ca76f 100644 --- a/tests/base_tests.py +++ b/tests/base_tests.py @@ -334,22 +334,22 @@ def delete_fake_db(self): if database: db.session.delete(database) - def create_fake_presto_db(self): + def create_fake_db_for_macros(self): self.login(username="admin") - database_name = "presto" + database_name = "db_for_macros_testing" db_id = 200 return self.get_or_create( cls=models.Database, criteria={"database_name": database_name}, session=db.session, - sqlalchemy_uri="presto://user@host:8080/hive", + sqlalchemy_uri="db_for_macros_testing://user@host:8080/hive", id=db_id, ) - def delete_fake_presto_db(self): + def delete_fake_db_for_macros(self): database = ( db.session.query(Database) - .filter(Database.database_name == "presto") + .filter(Database.database_name == "db_for_macros_testing") .scalar() ) if database: diff --git a/tests/core_tests.py b/tests/core_tests.py index b10c24983af42..40d6bf1dfc6a4 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -23,21 +23,18 @@ import io import json import logging -import os -from typing import Dict, List, Optional +from typing import Dict, List from urllib.parse import quote import pytz import random import re -import string import unittest from unittest import mock, skipUnless import pandas as pd import sqlalchemy as sqla -from superset.utils.core import get_example_database from tests.test_app import app # isort:skip import superset.views.utils from superset import ( @@ -49,7 +46,6 @@ is_feature_enabled, ) from superset.connectors.sqla.models import SqlaTable -from superset.datasets.dao import DatasetDAO from superset.db_engine_specs.base import BaseEngineSpec from superset.db_engine_specs.mssql import MssqlEngineSpec from superset.models import core as models @@ -702,7 +698,7 @@ def test_custom_process_template(self, mock_dt) -> None: """Test macro defined in custom template processor works.""" mock_dt.utcnow = mock.Mock(return_value=datetime.datetime(1970, 1, 1)) db = mock.Mock() - db.backend = "presto" + db.backend = "db_for_macros_testing" tp = jinja_context.get_template_processor(database=db) sql = "SELECT '$DATE()'" @@ -717,7 +713,7 @@ def test_custom_get_template_kwarg(self): """Test macro passed as kwargs when getting template processor works in custom template processor.""" db = mock.Mock() - db.backend = "presto" + db.backend = "db_for_macros_testing" s = "$foo()" tp = jinja_context.get_template_processor(database=db, foo=lambda: "bar") rendered = tp.process_template(s) @@ -727,7 +723,7 @@ def test_custom_template_kwarg(self) -> None: """Test macro passed as kwargs when processing template works in custom template processor.""" db = mock.Mock() - db.backend = "presto" + db.backend = "db_for_macros_testing" s = "$foo()" tp = jinja_context.get_template_processor(database=db) rendered = tp.process_template(s, foo=lambda: "bar") @@ -736,7 +732,7 @@ def test_custom_template_kwarg(self) -> None: def test_custom_template_processors_overwrite(self) -> None: """Test template processor for presto gets overwritten by custom one.""" db = mock.Mock() - db.backend = "presto" + db.backend = "db_for_macros_testing" tp = jinja_context.get_template_processor(database=db) sql = "SELECT '{{ datetime(2017, 1, 1).isoformat() }}'" @@ -751,11 +747,7 @@ def test_custom_template_processors_ignored(self) -> None: """Test custom template processor is ignored for a difference backend database.""" maindb = utils.get_example_database() - sql = ( - "SELECT '$DATE()'" - if maindb.backend != "presto" - else f"SELECT '{datetime.date.today().isoformat()}'" - ) + sql = "SELECT '$DATE()'" tp = jinja_context.get_template_processor(database=maindb) rendered = tp.process_template(sql) assert sql == rendered @@ -774,7 +766,7 @@ def test_custom_templated_sql_json(self, sql_lab_mock, mock_dt) -> None: } sql_lab_mock.return_value = resp - dbobj = self.create_fake_presto_db() + dbobj = self.create_fake_db_for_macros() json_payload = dict(database_id=dbobj.id, sql=sql) self.get_json_resp( "/superset/sql_json/", raise_on_error=False, json_=json_payload @@ -782,7 +774,7 @@ def test_custom_templated_sql_json(self, sql_lab_mock, mock_dt) -> None: assert sql_lab_mock.called self.assertEqual(sql_lab_mock.call_args[0][1], "SELECT '1970-01-01' as test") - self.delete_fake_presto_db() + self.delete_fake_db_for_macros() def test_fetch_datasource_metadata(self): self.login(username="admin") diff --git a/tests/sqla_models_tests.py b/tests/sqla_models_tests.py index e2a7fd0f655f5..9e1884503d4c4 100644 --- a/tests/sqla_models_tests.py +++ b/tests/sqla_models_tests.py @@ -95,11 +95,7 @@ def test_extra_cache_keys(self, flask_g): query_obj = dict(**base_query_obj, extras={}) extra_cache_keys = table.get_extra_cache_keys(query_obj) self.assertTrue(table.has_extra_cache_key_calls(query_obj)) - # TODO(bkyryliuk): make it work with presto - if get_example_database().backend == "presto": - assert extra_cache_keys == [] - else: - assert extra_cache_keys == ["abc"] + assert extra_cache_keys == ["abc"] # Table with Jinja callable disabled. table = SqlaTable( @@ -131,11 +127,7 @@ def test_extra_cache_keys(self, flask_g): ) extra_cache_keys = table.get_extra_cache_keys(query_obj) self.assertTrue(table.has_extra_cache_key_calls(query_obj)) - # TODO(bkyryliuk): make it work with presto and hive - if get_example_database().backend == "presto": - assert extra_cache_keys == [] - else: - assert extra_cache_keys == ["abc"] + assert extra_cache_keys == ["abc"] def test_where_operators(self): class FilterTestCase(NamedTuple): diff --git a/tests/superset_test_custom_template_processors.py b/tests/superset_test_custom_template_processors.py index 28fc65da428b0..b3534814786a7 100644 --- a/tests/superset_test_custom_template_processors.py +++ b/tests/superset_test_custom_template_processors.py @@ -35,7 +35,7 @@ def DATE( class CustomPrestoTemplateProcessor(PrestoTemplateProcessor): """A custom presto template processor for test.""" - engine = "presto" + engine = "db_for_macros_testing" def process_template(self, sql: str, **kwargs) -> str: """Processes a sql template with $ style macro using regex."""