mirror of
https://github.com/apache/superset.git
synced 2026-04-12 12:47:53 +00:00
refactor(db_engine_specs): Removing top-level import of app (#14366)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
@@ -167,25 +167,6 @@ class TestDbEngineSpecs(TestDbEngineSpec):
|
||||
"SELECT * FROM table", "SELECT * FROM table", DummyEngineSpec
|
||||
)
|
||||
|
||||
def test_time_grain_denylist(self):
|
||||
with app.app_context():
|
||||
app.config["TIME_GRAIN_DENYLIST"] = ["PT1M"]
|
||||
time_grain_functions = SqliteEngineSpec.get_time_grain_expressions()
|
||||
self.assertNotIn("PT1M", time_grain_functions)
|
||||
|
||||
def test_time_grain_addons(self):
|
||||
with app.app_context():
|
||||
app.config["TIME_GRAIN_ADDONS"] = {"PTXM": "x seconds"}
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {
|
||||
"sqlite": {"PTXM": "ABC({col})"}
|
||||
}
|
||||
time_grains = SqliteEngineSpec.get_time_grains()
|
||||
time_grain_addon = time_grains[-1]
|
||||
self.assertEqual("PTXM", time_grain_addon.duration)
|
||||
self.assertEqual("x seconds", time_grain_addon.label)
|
||||
app.config["TIME_GRAIN_ADDONS"] = {}
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {}
|
||||
|
||||
def test_engine_time_grain_validity(self):
|
||||
time_grains = set(builtin_time_grains.keys())
|
||||
# loop over all subclasses of BaseEngineSpec
|
||||
@@ -198,43 +179,6 @@ class TestDbEngineSpecs(TestDbEngineSpec):
|
||||
intersection = time_grains.intersection(defined_grains)
|
||||
self.assertSetEqual(defined_grains, intersection, engine)
|
||||
|
||||
def test_get_time_grain_with_config(self):
|
||||
""" Should concatenate from configs and then sort in the proper order """
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {
|
||||
"mysql": {
|
||||
"PT2H": "foo",
|
||||
"PT4H": "foo",
|
||||
"PT6H": "foo",
|
||||
"PT8H": "foo",
|
||||
"PT10H": "foo",
|
||||
"PT12H": "foo",
|
||||
"PT1S": "foo",
|
||||
}
|
||||
}
|
||||
time_grains = MySQLEngineSpec.get_time_grain_expressions()
|
||||
self.assertEqual(
|
||||
list(time_grains.keys()),
|
||||
[
|
||||
None,
|
||||
"PT1S",
|
||||
"PT1M",
|
||||
"PT1H",
|
||||
"PT2H",
|
||||
"PT4H",
|
||||
"PT6H",
|
||||
"PT8H",
|
||||
"PT10H",
|
||||
"PT12H",
|
||||
"P1D",
|
||||
"P1W",
|
||||
"P1M",
|
||||
"P0.25Y",
|
||||
"P1Y",
|
||||
"1969-12-29T00:00:00Z/P1W",
|
||||
],
|
||||
)
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {}
|
||||
|
||||
def test_get_time_grain_expressions(self):
|
||||
time_grains = MySQLEngineSpec.get_time_grain_expressions()
|
||||
self.assertEqual(
|
||||
@@ -253,18 +197,6 @@ class TestDbEngineSpecs(TestDbEngineSpec):
|
||||
],
|
||||
)
|
||||
|
||||
def test_get_time_grain_with_unkown_values(self):
|
||||
"""Should concatenate from configs and then sort in the proper order
|
||||
putting unknown patterns at the end"""
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {
|
||||
"mysql": {"PT2H": "foo", "weird": "foo", "PT12H": "foo",}
|
||||
}
|
||||
time_grains = MySQLEngineSpec.get_time_grain_expressions()
|
||||
self.assertEqual(
|
||||
list(time_grains)[-1], "weird",
|
||||
)
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {}
|
||||
|
||||
def test_get_table_names(self):
|
||||
inspector = mock.Mock()
|
||||
inspector.get_table_names = mock.Mock(return_value=["schema.table", "table_2"])
|
||||
@@ -339,3 +271,84 @@ def test_is_readonly():
|
||||
assert is_readonly("WITH (SELECT 1) bla SELECT * from bla")
|
||||
assert is_readonly("SHOW CATALOGS")
|
||||
assert is_readonly("SHOW TABLES")
|
||||
|
||||
|
||||
def test_time_grain_denylist():
|
||||
config = app.config.copy()
|
||||
app.config["TIME_GRAIN_DENYLIST"] = ["PT1M"]
|
||||
|
||||
with app.app_context():
|
||||
time_grain_functions = SqliteEngineSpec.get_time_grain_expressions()
|
||||
assert not "PT1M" in time_grain_functions
|
||||
|
||||
app.config = config
|
||||
|
||||
|
||||
def test_time_grain_addons():
|
||||
config = app.config.copy()
|
||||
app.config["TIME_GRAIN_ADDONS"] = {"PTXM": "x seconds"}
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {"sqlite": {"PTXM": "ABC({col})"}}
|
||||
|
||||
with app.app_context():
|
||||
time_grains = SqliteEngineSpec.get_time_grains()
|
||||
time_grain_addon = time_grains[-1]
|
||||
assert "PTXM" == time_grain_addon.duration
|
||||
assert "x seconds" == time_grain_addon.label
|
||||
|
||||
app.config = config
|
||||
|
||||
|
||||
def test_get_time_grain_with_config():
|
||||
""" Should concatenate from configs and then sort in the proper order """
|
||||
config = app.config.copy()
|
||||
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {
|
||||
"mysql": {
|
||||
"PT2H": "foo",
|
||||
"PT4H": "foo",
|
||||
"PT6H": "foo",
|
||||
"PT8H": "foo",
|
||||
"PT10H": "foo",
|
||||
"PT12H": "foo",
|
||||
"PT1S": "foo",
|
||||
}
|
||||
}
|
||||
|
||||
with app.app_context():
|
||||
time_grains = MySQLEngineSpec.get_time_grain_expressions()
|
||||
assert set(time_grains.keys()) == {
|
||||
None,
|
||||
"PT1S",
|
||||
"PT1M",
|
||||
"PT1H",
|
||||
"PT2H",
|
||||
"PT4H",
|
||||
"PT6H",
|
||||
"PT8H",
|
||||
"PT10H",
|
||||
"PT12H",
|
||||
"P1D",
|
||||
"P1W",
|
||||
"P1M",
|
||||
"P0.25Y",
|
||||
"P1Y",
|
||||
"1969-12-29T00:00:00Z/P1W",
|
||||
}
|
||||
|
||||
app.config = config
|
||||
|
||||
|
||||
def test_get_time_grain_with_unkown_values():
|
||||
"""Should concatenate from configs and then sort in the proper order
|
||||
putting unknown patterns at the end"""
|
||||
config = app.config.copy()
|
||||
|
||||
app.config["TIME_GRAIN_ADDON_EXPRESSIONS"] = {
|
||||
"mysql": {"PT2H": "foo", "weird": "foo", "PT12H": "foo",}
|
||||
}
|
||||
|
||||
with app.app_context():
|
||||
time_grains = MySQLEngineSpec.get_time_grain_expressions()
|
||||
assert list(time_grains)[-1] == "weird"
|
||||
|
||||
app.config = config
|
||||
|
||||
Reference in New Issue
Block a user