Skip to content

Commit

Permalink
check no warning of already existing grant when full_refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
salimmoulouel committed May 6, 2024
1 parent 1831c57 commit 1744e65
Showing 1 changed file with 8 additions and 42 deletions.
50 changes: 8 additions & 42 deletions tests/functional/adapter/test_grant_access_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import pytest

from dbt.tests.util import run_dbt

import re

def select_1(dataset: str, materialized: str):
config = f"""config(
materialized='{materialized}',
grant_access_to=[
{{'project': 'dbt-test-env', 'dataset': '{dataset}'}},
{{'project': 'vg1np-apps-bdi-dev-70', 'dataset': '{dataset}'}},
]
)"""
return (
Expand All @@ -26,7 +26,7 @@ def select_1(dataset: str, materialized: str):
{{ config(
materialized='view',
grant_access_to=[
{'project': 'dbt-test-env', 'dataset': 'NonExistentDataset'},
{'project': 'vg1np-apps-bdi-dev-70', 'dataset': 'NonExistentDataset'},
]
) }}
Expand Down Expand Up @@ -87,51 +87,17 @@ def test_grant_access_succeeds(self, project, setup_grant_schema, teardown_grant



class TestAccessGrantSucceedsWithFullRefresh:
@pytest.fixture(scope="class")
def setup_grant_schema(
self,
project,
unique_schema,
):
with project.adapter.connection_named("__test_grants"):
relation = project.adapter.Relation.create(
database=project.database,
schema=get_schema_name(unique_schema),
identifier="grant_access",
)
project.adapter.create_schema(relation)
yield relation

@pytest.fixture(scope="class")
def teardown_grant_schema(
self,
project,
unique_schema,
):
yield
with project.adapter.connection_named("__test_grants"):
relation = project.adapter.Relation.create(
database=project.database, schema=get_schema_name(unique_schema)
)
project.adapter.drop_schema(relation)

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

def test_grant_access_succeeds(self, project, setup_grant_schema, teardown_grant_schema):
class TestAccessGrantSucceedsWithFullRefresh(TestAccessGrantSucceeds):
def test_grant_access_succeeds(self, project, setup_grant_schema, teardown_grant_schema,capsys):
# Need to run twice to validate idempotency
results = run_dbt(["run"])
assert len(results) == 2
time.sleep(10)
results = run_dbt(["run","--full-refresh"])
assert len(results) == 2

captured = capsys.readouterr()
assert not re.search(r"BigQuery adapter: Access entry <AccessEntry: .* already exists in dataset",captured[0])




Expand Down

0 comments on commit 1744e65

Please sign in to comment.