1+ import logging
12from dataclasses import dataclass
23
4+ import pytest
5+
36from databricks .labs .lsql .backends import MockBackend
47from databricks .labs .lsql .deployment import SchemaDeployer
58
69from . import views
710
811
9- def test_deploys_view ():
12+ @pytest .mark .parametrize ("inventory_catalog" , ["hive_metastore" , "inventory" ])
13+ def test_deploys_schema (caplog , inventory_catalog : str ) -> None :
1014 mock_backend = MockBackend ()
1115 deployment = SchemaDeployer (
1216 sql_backend = mock_backend ,
13- inventory_schema = "inventory" ,
17+ schema = "inventory" ,
1418 mod = views ,
19+ catalog = inventory_catalog ,
1520 )
1621
17- deployment .deploy_view ("some" , "some.sql" )
22+ with caplog .at_level (logging .INFO , logger = "databricks.labs.lsql.deployment" ):
23+ deployment .deploy_schema ()
1824
19- assert mock_backend .queries == [
20- "CREATE OR REPLACE VIEW hive_metastore.inventory.some AS SELECT\n id,\n name\n FROM hive_metastore.inventory.something"
21- ]
25+ assert mock_backend .queries == [f"CREATE SCHEMA IF NOT EXISTS { inventory_catalog } .inventory" ]
26+ assert f"Ensuring { inventory_catalog } .inventory database exists" in caplog .messages
27+
28+
29+ @pytest .mark .parametrize ("inventory_catalog" , ["hive_metastore" , "inventory" ])
30+ def test_deletes_schema (caplog , inventory_catalog : str ) -> None :
31+ mock_backend = MockBackend ()
32+ deployment = SchemaDeployer (
33+ sql_backend = mock_backend ,
34+ schema = "inventory" ,
35+ mod = views ,
36+ catalog = inventory_catalog ,
37+ )
38+
39+ with caplog .at_level (logging .INFO , logger = "databricks.labs.lsql.deployment" ):
40+ deployment .delete_schema ()
41+
42+ assert mock_backend .queries == [f"DROP SCHEMA IF EXISTS { inventory_catalog } .inventory CASCADE" ]
43+ assert f"Deleting { inventory_catalog } .inventory database" in caplog .messages
2244
2345
2446@dataclass
@@ -27,19 +49,40 @@ class Foo:
2749 second : bool
2850
2951
30- def test_deploys_dataclass ():
52+ @pytest .mark .parametrize ("inventory_catalog" , ["hive_metastore" , "inventory" ])
53+ def test_deploys_dataclass (caplog , inventory_catalog : str ) -> None :
3154 mock_backend = MockBackend ()
3255 deployment = SchemaDeployer (
3356 sql_backend = mock_backend ,
34- inventory_schema = "inventory" ,
57+ schema = "inventory" ,
3558 mod = views ,
59+ catalog = inventory_catalog ,
3660 )
37- deployment .deploy_schema ()
38- deployment .deploy_table ("foo" , Foo )
39- deployment .delete_schema ()
61+
62+ with caplog .at_level (logging .INFO , logger = "databricks.labs.lsql.deployment" ):
63+ deployment .deploy_table ("foo" , Foo )
64+
65+ assert mock_backend .queries == [
66+ f"CREATE TABLE IF NOT EXISTS { inventory_catalog } .inventory.foo (first STRING NOT NULL, second BOOLEAN NOT NULL) USING DELTA" ,
67+ ]
68+ assert f"Ensuring { inventory_catalog } .inventory.foo table exists" in caplog .messages
69+
70+
71+ @pytest .mark .parametrize ("inventory_catalog" , ["hive_metastore" , "inventory" ])
72+ def test_deploys_view (caplog , inventory_catalog : str ) -> None :
73+ mock_backend = MockBackend ()
74+ deployment = SchemaDeployer (
75+ sql_backend = mock_backend ,
76+ schema = "inventory" ,
77+ mod = views ,
78+ catalog = inventory_catalog ,
79+ )
80+
81+ with caplog .at_level (logging .INFO , logger = "databricks.labs.lsql.deployment" ):
82+ deployment .deploy_view ("some" , "some.sql" )
4083
4184 assert mock_backend .queries == [
42- "CREATE SCHEMA IF NOT EXISTS hive_metastore.inventory" ,
43- "CREATE TABLE IF NOT EXISTS hive_metastore.inventory.foo (first STRING NOT NULL, second BOOLEAN NOT NULL) USING DELTA" ,
44- "DROP SCHEMA IF EXISTS hive_metastore.inventory CASCADE" ,
85+ f"CREATE OR REPLACE VIEW { inventory_catalog } .inventory.some AS SELECT\n id,\n name\n "
86+ f"FROM { inventory_catalog } .inventory.something"
4587 ]
88+ assert f"Ensuring { inventory_catalog } .inventory.some view matches some.sql contents" in caplog .messages
0 commit comments