Skip to content

Commit

Permalink
rectified code with pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
soksamnanglim committed Oct 4, 2023
1 parent a0ca37d commit ca046c9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 68 deletions.
4 changes: 2 additions & 2 deletions dbt/adapters/redshift/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -254,4 +254,4 @@ def process_grant_dicts(self, unknown_dict):
if grantees_map_temp:
temp[privilege] = grantees_map_temp

return temp
return temp
5 changes: 0 additions & 5 deletions tests/functional/adapter/grants/base_grants.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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)
Expand Down
34 changes: 18 additions & 16 deletions tests/functional/adapter/grants/test_incremental_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') }}"]
Expand All @@ -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):
Expand Down Expand Up @@ -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")
Expand All @@ -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)

Expand All @@ -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)

62 changes: 37 additions & 25 deletions tests/functional/adapter/grants/test_model_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
8 changes: 3 additions & 5 deletions tests/functional/adapter/grants/test_seed_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +57,7 @@
- name: my_seed
config:
grants:
select:
select:
user: []
group: []
role: []
Expand All @@ -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
Expand Down
31 changes: 17 additions & 14 deletions tests/functional/adapter/grants/test_snapshot_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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') }}"]
Expand All @@ -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') }}"]
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
2 changes: 1 addition & 1 deletion tests/functional/adapter/test_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class TestSnapshotGrantsRedshift(BaseSnapshotGrantsRedshift):


class TestInvalidGrantsRedshift(BaseModelGrantsRedshift):
pass
pass

0 comments on commit ca046c9

Please sign in to comment.