diff --git a/dbt/adapters/redshift/impl.py b/dbt/adapters/redshift/impl.py index cfea6237f..4a497fa03 100644 --- a/dbt/adapters/redshift/impl.py +++ b/dbt/adapters/redshift/impl.py @@ -166,7 +166,7 @@ def debug_query(self): """Override for DebugTask method""" self.execute("select 1 as id") - ## grant-related methods ## + # grant-related methods @available def standardize_grants_dict(self, grants_table): """ @@ -254,4 +254,4 @@ def process_grant_dicts(self, unknown_dict): if grantees_map_temp: temp[privilege] = grantees_map_temp - return temp \ No newline at end of file + return temp diff --git a/tests/functional/adapter/grants/base_grants.py b/tests/functional/adapter/grants/base_grants.py index 740faff92..22a614d01 100644 --- a/tests/functional/adapter/grants/base_grants.py +++ b/tests/functional/adapter/grants/base_grants.py @@ -1,10 +1,6 @@ from dbt.tests.adapter.grants.base_grants import BaseGrants import pytest import os -from dbt.tests.util import ( - relation_from_name, - get_connection, -) TEST_USER_ENV_VARS = ["DBT_TEST_USER_1", "DBT_TEST_USER_2", "DBT_TEST_USER_3"] TEST_GROUP_ENV_VARS = ["DBT_TEST_GROUP_1", "DBT_TEST_GROUP_2", "DBT_TEST_GROUP_3"] @@ -27,7 +23,6 @@ def get_test_permissions(permission_env_vars): class BaseGrantsRedshift(BaseGrants): - @pytest.fixture(scope="class", autouse=True) def get_test_groups(self, project): return get_test_permissions(TEST_GROUP_ENV_VARS) diff --git a/tests/functional/adapter/grants/test_incremental_grants.py b/tests/functional/adapter/grants/test_incremental_grants.py index 8cee6d1e3..77f982d97 100644 --- a/tests/functional/adapter/grants/test_incremental_grants.py +++ b/tests/functional/adapter/grants/test_incremental_grants.py @@ -9,7 +9,6 @@ ) from tests.functional.adapter.grants.base_grants import BaseGrantsRedshift -# from tests.functional.adapter.grants import BaseGrantsRedshift my_incremental_model_sql = """ select 1 as fun @@ -41,8 +40,8 @@ - name: my_incremental_model config: materialized: incremental - grants: - select: + grants: + select: user: ["{{ env_var('DBT_TEST_USER_1') }}"] group: ["{{ env_var('DBT_TEST_GROUP_1') }}"] role: ["{{ env_var('DBT_TEST_ROLE_1') }}"] @@ -54,13 +53,14 @@ - name: my_incremental_model config: materialized: incremental - grants: - select: + grants: + select: user: ["{{ env_var('DBT_TEST_USER_2') }}"] group: ["{{ env_var('DBT_TEST_GROUP_2') }}"] role: ["{{ env_var('DBT_TEST_ROLE_2') }}"] """ + class BaseIncrementalGrantsRedshift(BaseGrantsRedshift): @pytest.fixture(scope="class") def models(self): @@ -131,8 +131,7 @@ def test_incremental_grants(self, project, get_test_users, get_test_groups, get_ assert "revoke " not in log_output self.assert_expected_grants_match_actual(project, "my_incremental_model", expected) - ## Additional tests for privilege grants to extended permission types - + # Additional tests for privilege grants to extended permission types # Incremental materialization, single select grant updated_yaml = self.interpolate_name_overrides(extended_incremental_model_schema_yml) write_file(updated_yaml, project.project_root, "models", "schema.yml") @@ -144,10 +143,12 @@ def test_incremental_grants(self, project, get_test_users, get_test_groups, get_ manifest = get_manifest(project.project_root) model = manifest.nodes[model_id] assert model.config.materialized == "incremental" - expected = {select_privilege_name: { - "user": [test_users[0]], - "group": [test_groups[0]], - "role": [test_roles[0]]} + expected = { + select_privilege_name: { + "user": [test_users[0]], + "group": [test_groups[0]], + "role": [test_roles[0]], + } } self.assert_expected_grants_match_actual(project, "my_incremental_model", expected) @@ -162,10 +163,11 @@ def test_incremental_grants(self, project, get_test_users, get_test_groups, get_ manifest = get_manifest(project.project_root) model = manifest.nodes[model_id] assert model.config.materialized == "incremental" - expected = {select_privilege_name: { - "user": [test_users[1]], - "group": [test_groups[1]], - "role": [test_roles[1]]} + expected = { + select_privilege_name: { + "user": [test_users[1]], + "group": [test_groups[1]], + "role": [test_roles[1]], + } } self.assert_expected_grants_match_actual(project, "my_incremental_model", expected) - diff --git a/tests/functional/adapter/grants/test_model_grants.py b/tests/functional/adapter/grants/test_model_grants.py index f7260f575..1e7ff5f9f 100644 --- a/tests/functional/adapter/grants/test_model_grants.py +++ b/tests/functional/adapter/grants/test_model_grants.py @@ -6,8 +6,6 @@ ) from tests.functional.adapter.grants.base_grants import BaseGrantsRedshift -# from tests.functional.adapter.grants import BaseGrantsRedshift - my_model_sql = """ select 1 as fun """ @@ -141,8 +139,7 @@ def models(self): } def test_view_table_grants(self, project, get_test_users, get_test_groups, get_test_roles): - ## Override/refactor the tests from dbt-core ## - + # Override/refactor the tests from dbt-core # # we want the test to fail, not silently skip test_users = get_test_users test_groups = get_test_groups @@ -217,14 +214,19 @@ def test_view_table_grants(self, project, get_test_users, get_test_groups, get_t assert len(results) == 1 manifest = get_manifest(project.project_root) model = manifest.nodes[model_id] - user_expected = {select_privilege_name: [test_users[0]], insert_privilege_name: [test_users[1]]} + user_expected = { + select_privilege_name: [test_users[0]], + insert_privilege_name: [test_users[1]], + } assert model.config.grants == user_expected assert model.config.materialized == "table" - expected = {select_privilege_name: {"user": [test_users[0]]}, insert_privilege_name: {"user": [test_users[1]]}} + expected = { + select_privilege_name: {"user": [test_users[0]]}, + insert_privilege_name: {"user": [test_users[1]]}, + } self.assert_expected_grants_match_actual(project, "my_model", expected) - ## Additional tests for privilege grants to extended permission types - + # Additional tests for privilege grants to extended permission types # Table materialization, single select grant updated_yaml = self.interpolate_name_overrides(extended_table_model_schema_yml) write_file(updated_yaml, project.project_root, "models", "schema.yml") @@ -233,10 +235,12 @@ def test_view_table_grants(self, project, get_test_users, get_test_groups, get_t manifest = get_manifest(project.project_root) model = manifest.nodes[model_id] assert model.config.materialized == "table" - expected = {select_privilege_name: { - "user": [test_users[0]], - "group": [test_groups[0]], - "role": [test_roles[0]]} + expected = { + select_privilege_name: { + "user": [test_users[0]], + "group": [test_groups[0]], + "role": [test_roles[0]], + } } self.assert_expected_grants_match_actual(project, "my_model", expected) @@ -248,30 +252,38 @@ def test_view_table_grants(self, project, get_test_users, get_test_groups, get_t manifest = get_manifest(project.project_root) model = manifest.nodes[model_id] assert model.config.materialized == "table" - expected = {select_privilege_name: { - "user": [test_users[1]], - "group": [test_groups[1]], - "role": [test_roles[1]]} + expected = { + select_privilege_name: { + "user": [test_users[1]], + "group": [test_groups[1]], + "role": [test_roles[1]], + } } self.assert_expected_grants_match_actual(project, "my_model", expected) # Table materialization, multiple grantees - updated_yaml = self.interpolate_name_overrides(extended_multiple_grantees_table_model_schema_yml) + updated_yaml = self.interpolate_name_overrides( + extended_multiple_grantees_table_model_schema_yml + ) write_file(updated_yaml, project.project_root, "models", "schema.yml") (results, log_output) = run_dbt_and_capture(["--debug", "run"]) assert len(results) == 1 manifest = get_manifest(project.project_root) model = manifest.nodes[model_id] assert model.config.materialized == "table" - expected = {select_privilege_name: { - "user": [test_users[0], test_users[1]], - "group": [test_groups[0], test_groups[1]], - "role": [test_roles[0], test_roles[1]]} + expected = { + select_privilege_name: { + "user": [test_users[0], test_users[1]], + "group": [test_groups[0], test_groups[1]], + "role": [test_roles[0], test_roles[1]], + } } self.assert_expected_grants_match_actual(project, "my_model", expected) # Table materialization, multiple privileges - updated_yaml = self.interpolate_name_overrides(extended_multiple_privileges_table_model_schema_yml) + updated_yaml = self.interpolate_name_overrides( + extended_multiple_privileges_table_model_schema_yml + ) write_file(updated_yaml, project.project_root, "models", "schema.yml") (results, log_output) = run_dbt_and_capture(["--debug", "run"]) assert len(results) == 1 @@ -282,12 +294,12 @@ def test_view_table_grants(self, project, get_test_users, get_test_groups, get_t select_privilege_name: { "user": [test_users[0]], "group": [test_groups[0]], - "role": [test_roles[0]] + "role": [test_roles[0]], }, insert_privilege_name: { "user": [test_users[1]], "group": [test_groups[1]], - "role": [test_roles[1]] - } + "role": [test_roles[1]], + }, } self.assert_expected_grants_match_actual(project, "my_model", expected) diff --git a/tests/functional/adapter/grants/test_seed_grants.py b/tests/functional/adapter/grants/test_seed_grants.py index c826b8e15..c87c68716 100644 --- a/tests/functional/adapter/grants/test_seed_grants.py +++ b/tests/functional/adapter/grants/test_seed_grants.py @@ -6,7 +6,7 @@ write_file, ) from tests.functional.adapter.grants.base_grants import BaseGrantsRedshift -# from dbt.tests.adapter.grants.base_grants import BaseGrantsRedshift + seeds__my_seed_csv = """ id,name,some_date @@ -57,7 +57,7 @@ - name: my_seed config: grants: - select: + select: user: [] group: [] role: [] @@ -76,13 +76,11 @@ def seeds(self): "schema.yml": updated_schema, } - def test_seed_grants(self, project, get_test_users, get_test_groups, get_test_roles): + def test_seed_grants(self, project, get_test_users): # debugging for seeds print("seed testing") test_users = get_test_users - test_groups = get_test_groups - test_roles = get_test_roles select_privilege_name = self.privilege_grantee_name_overrides()["select"] # seed command diff --git a/tests/functional/adapter/grants/test_snapshot_grants.py b/tests/functional/adapter/grants/test_snapshot_grants.py index db6cf02ba..b2ff5e6f1 100644 --- a/tests/functional/adapter/grants/test_snapshot_grants.py +++ b/tests/functional/adapter/grants/test_snapshot_grants.py @@ -7,7 +7,7 @@ ) from tests.functional.adapter.grants.base_grants import BaseGrantsRedshift -# from tests.functional.adapter.grants import BaseGrantsRedshift + my_snapshot_sql = """ {% snapshot my_snapshot %} @@ -42,8 +42,8 @@ snapshots: - name: my_snapshot config: - grants: - select: + grants: + select: user: ["{{ env_var('DBT_TEST_USER_1') }}"] group: ["{{ env_var('DBT_TEST_GROUP_1') }}"] role: ["{{ env_var('DBT_TEST_ROLE_1') }}"] @@ -54,8 +54,8 @@ snapshots: - name: my_snapshot config: - grants: - select: + grants: + select: user: ["{{ env_var('DBT_TEST_USER_2') }}"] group: ["{{ env_var('DBT_TEST_GROUP_2') }}"] role: ["{{ env_var('DBT_TEST_ROLE_2') }}"] @@ -71,7 +71,6 @@ def snapshots(self): } def test_snapshot_grants(self, project, get_test_users, get_test_groups, get_test_roles): - print("snapshot testing") test_users = get_test_users test_groups = get_test_groups @@ -109,10 +108,12 @@ def test_snapshot_grants(self, project, get_test_users, get_test_groups, get_tes write_file(updated_yaml, project.project_root, "snapshots", "schema.yml") (results, log_output) = run_dbt_and_capture(["--debug", "snapshot"]) assert len(results) == 1 - expected = {select_privilege_name: { - "user": [test_users[0]], - "group": [test_groups[0]], - "role": [test_roles[0]]} + expected = { + select_privilege_name: { + "user": [test_users[0]], + "group": [test_groups[0]], + "role": [test_roles[0]], + } } self.assert_expected_grants_match_actual(project, "my_snapshot", expected) @@ -121,9 +122,11 @@ def test_snapshot_grants(self, project, get_test_users, get_test_groups, get_tes write_file(updated_yaml, project.project_root, "snapshots", "schema.yml") (results, log_output) = run_dbt_and_capture(["--debug", "snapshot"]) assert len(results) == 1 - expected = {select_privilege_name: { - "user": [test_users[1]], - "group": [test_groups[1]], - "role": [test_roles[1]]} + expected = { + select_privilege_name: { + "user": [test_users[1]], + "group": [test_groups[1]], + "role": [test_roles[1]], + } } self.assert_expected_grants_match_actual(project, "my_snapshot", expected) diff --git a/tests/functional/adapter/test_grants.py b/tests/functional/adapter/test_grants.py index fe9ab87b9..9dcc63c77 100644 --- a/tests/functional/adapter/test_grants.py +++ b/tests/functional/adapter/test_grants.py @@ -21,4 +21,4 @@ class TestSnapshotGrantsRedshift(BaseSnapshotGrantsRedshift): class TestInvalidGrantsRedshift(BaseModelGrantsRedshift): - pass \ No newline at end of file + pass