Skip to content

Commit

Permalink
have test grant access dynamically create schema
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-rogers-dbt committed Jul 22, 2023
1 parent b6ac19a commit c6bc55b
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions tests/functional/adapter/test_grant_access_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
from dbt.tests.util import run_dbt


SELECT_1 = """
{{ config(
materialized='view',
grant_access_to=[
{'project': 'dbt-test-env-alt', 'dataset': 'GrantAccessTest'},
]
) }}
SELECT 1 as one
"""
def select_1(dataset: str, materialized: str):
return f"""
{{ config(
materialized='{materialized}',
grant_access_to=[
{{'project': 'dbt-test-env-alt', 'dataset': '{dataset}'}},
]
SELECT 1 as one
) }}
"""


SELECT_1_TABLE = """
{{ config(
materialized='table',
grant_access_to=[
{'project': 'dbt-test-env-alt', 'dataset': 'GrantAccessTest'},
]
) }}
SELECT 1 as one
"""
BAD_CONFIG_TABLE_NAME = "bad_view"
BAD_CONFIG_TABLE = """
{{ config(
Expand All @@ -40,8 +33,23 @@

class TestAccessGrantSucceeds:
@pytest.fixture(scope="class")
def models(self):
return {"select_1.sql": SELECT_1, "select_1_table.sql": SELECT_1_TABLE}
def setup_grant_schema(self, project):
with project.adapter.connection_named("__test_grants"):
relation = project.adapter.Relation.create(
database=project.database, schema=f"{project.test_schema}_grant_access"
)
project.adapter.create_schema(relation)
yield relation
project.adapter.drop_relation(relation)

@pytest.fixture(scope="class")
def models(self, setup_grant_schema):
return {
"select_1.sql": select_1(dataset=setup_grant_schema.schema, materialized="view"),
"select_1_table.sql": select_1(
dataset=setup_grant_schema.schema, materialized="table"
),
}

def test_grant_access_succeeds(self, project):
# Need to run twice to validate idempotency
Expand All @@ -53,15 +61,6 @@ def test_grant_access_succeeds(self, project):


class TestAccessGrantFails:
@pytest.fixture(scope="class", autouse=True)
def setup(self, project):
with project.adapter.connection_named("__test_grants"):
relation = project.adapter.Relation.create(
database=project.database, schema=f"{project.test_schema}_seeds"
)
yield relation
project.adapter.drop_relation(relation)

@pytest.fixture(scope="class")
def models(self):
return {
Expand Down

0 comments on commit c6bc55b

Please sign in to comment.