Skip to content

Commit

Permalink
Update test_model_grants.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmeireles committed Jan 21, 2025
1 parent 0551fdc commit 389e04a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tests/functional/adapter/grants/test_model_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
select: ["{{ env_var('DBT_TEST_USER_1') }}"]
"""

class TestViewGrantsDremio(BaseGrantsDremio):
class TestViewGrantsDremio(BaseGrantsDremio, BaseModelGrants):
@pytest.fixture(scope="class")
def models(self):
updated_schema = self.interpolate_name_overrides(model_schema_yml)
Expand Down Expand Up @@ -80,7 +80,14 @@ def test_view_table_grants(self, project, get_test_users):
self.assert_expected_grants_match_actual(project, "my_model", expected)


class TestTableGrantsDremio(BaseGrantsDremio):
class TestTableGrantsDremio(BaseGrantsDremio, BaseModelGrants):
@pytest.fixture(scope="class")
def models(self):
updated_schema = self.interpolate_name_overrides(model_schema_yml)
return {
"my_model.sql": my_model_sql,
"schema.yml": updated_schema,
}
# Need to override this to make sure it uses our modified version of relation_from_name
# This isn't needed for views, as dbt-core's version defaults to database/schema path
def get_grants_on_relation(self, project, relation_name):
Expand Down Expand Up @@ -108,7 +115,7 @@ def test_view_table_grants(self, project, get_test_users):
model_id = "model.test.my_model"
model = manifest.nodes[model_id]
assert model.config.materialized == "table"
expected = {select_privilege_name: [test_users[0]]}
expected = {select_privilege_name: ["user:" + test_users[0]]}
self.assert_expected_grants_match_actual(project, "my_model", expected)

# Table materialization, change select grant user
Expand All @@ -119,7 +126,7 @@ def test_view_table_grants(self, project, get_test_users):
manifest = get_manifest(project.project_root)
model = manifest.nodes[model_id]
assert model.config.materialized == "table"
expected = {select_privilege_name: [test_users[1]]}
expected = {select_privilege_name: ["user:" + test_users[1]]}
self.assert_expected_grants_match_actual(project, "my_model", expected)

# Table materialization, multiple grantees
Expand All @@ -132,7 +139,7 @@ def test_view_table_grants(self, project, get_test_users):
manifest = get_manifest(project.project_root)
model = manifest.nodes[model_id]
assert model.config.materialized == "table"
expected = {select_privilege_name: [test_users[0], test_users[1]]}
expected = {select_privilege_name: ["user:" + test_users[0], "user:" + test_users[1]]}
self.assert_expected_grants_match_actual(project, "my_model", expected)

# Table materialization, multiple privileges
Expand All @@ -146,7 +153,7 @@ def test_view_table_grants(self, project, get_test_users):
model = manifest.nodes[model_id]
assert model.config.materialized == "table"
expected = {
select_privilege_name: [test_users[0]],
insert_privilege_name: [test_users[1]],
select_privilege_name: ["user:" + test_users[0]],
insert_privilege_name: ["user:" + test_users[1]],
}
self.assert_expected_grants_match_actual(project, "my_model", expected)

0 comments on commit 389e04a

Please sign in to comment.