mirror of https://github.com/apache/superset.git
Use test name for the custom macros testing: (#10695)
: Co-authored-by: bogdan kyryliuk <bogdankyryliuk@dropbox.com>
This commit is contained in:
parent
7abdf53944
commit
6ed36552e6
|
@ -334,22 +334,22 @@ class SupersetTestCase(TestCase):
|
|||
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:
|
||||
|
|
|
@ -23,21 +23,18 @@ import html
|
|||
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 @@ from superset import (
|
|||
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 @@ class TestCore(SupersetTestCase):
|
|||
"""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 @@ class TestCore(SupersetTestCase):
|
|||
"""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 @@ class TestCore(SupersetTestCase):
|
|||
"""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 @@ class TestCore(SupersetTestCase):
|
|||
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 @@ class TestCore(SupersetTestCase):
|
|||
"""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 @@ class TestCore(SupersetTestCase):
|
|||
}
|
||||
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 @@ class TestCore(SupersetTestCase):
|
|||
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")
|
||||
|
|
|
@ -95,11 +95,7 @@ class TestDatabaseModel(SupersetTestCase):
|
|||
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 @@ class TestDatabaseModel(SupersetTestCase):
|
|||
)
|
||||
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):
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue