Skip to content

Commit

Permalink
test: native query exposure reference parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline committed Dec 20, 2024
1 parent c490dcd commit f04264c
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,69 @@ def test_exposures_grouping_type(core: MockDbtMetabase):

for file in (fixtures_path / "dashboard").iterdir():
_assert_exposures(file, output_path / "dashboard" / file.name)


@pytest.mark.parametrize(
("query", "expected"),
[
(
"SELECT * FROM database.schema.table0",
{"database.schema.table0"},
),
(
"SELECT * FROM schema.table0",
{"database.schema.table0"},
),
(
"SELECT * FROM table1",
{"database.public.table1"},
),
(
'SELECT * FROM "schema".table0',
{"database.schema.table0"},
),
(
'SELECT * FROM schema."table0"',
{"database.schema.table0"},
),
(
'SELECT * FROM "schema"."table0"',
{"database.schema.table0"},
),
(
"SELECT * FROM `schema.table0`",
{"database.schema.table0"},
),
],
)
def test_extract_exposures_native_depends(
core: MockDbtMetabase,
query: str,
expected: set,
):
ctx = MockDbtMetabase._ExposuresMixin__Context( # type: ignore
model_refs={
"database.schema.table0": "model0",
"database.public.table1": "model1",
},
database_names={1: "database"},
table_names={},
)
exposure = MockDbtMetabase._ExposuresMixin__Exposure( # type: ignore
model="card",
uid="",
label="",
)
core._ExposuresMixin__exposure_card( # type: ignore
ctx=ctx,
exposure=exposure,
card={
"dataset_query": {
"type": "native",
"database": 1,
"native": {"query": query},
}
},
)
assert expected == exposure.depends
assert query == exposure.native_query

0 comments on commit f04264c

Please sign in to comment.