1414
1515import pytest , os
1616
17- from dbt .tests .adapter .grants .test_seed_grants import BaseSeedGrants
17+ from dbt .tests .adapter .grants .test_seed_grants import (
18+ BaseSeedGrants ,
19+ user2_schema_base_yml ,
20+ ignore_grants_yml ,
21+ zero_grants_yml ,
22+ )
1823from tests .functional .adapter .grants .base_grants import BaseGrantsDremio
1924from tests .utils .util import relation_from_name
20- from dbt .tests .util import get_connection
25+ from dbt .tests .util import (
26+ get_connection ,
27+ get_manifest ,
28+ run_dbt ,
29+ run_dbt_and_capture ,
30+ write_file ,
31+ )
2132
2233DREMIO_EDITION = os .getenv ("DREMIO_EDITION" )
2334
@@ -38,3 +49,75 @@ def get_grants_on_relation(self, project, relation_name):
3849 _ , grant_table = adapter .execute (show_grant_sql , fetch = True )
3950 actual_grants = adapter .standardize_grants_dict (grant_table )
4051 return actual_grants
52+
53+ # Override to add user prefix in expected results
54+ def test_seed_grants (self , project , get_test_users ):
55+ test_users = get_test_users
56+ select_privilege_name = self .privilege_grantee_name_overrides ()["select" ]
57+
58+ # seed command
59+ (results , log_output ) = run_dbt_and_capture (["--debug" , "seed" ])
60+ assert len (results ) == 1
61+ manifest = get_manifest (project .project_root )
62+ seed_id = "seed.test.my_seed"
63+ seed = manifest .nodes [seed_id ]
64+ expected = {select_privilege_name : ["user:" + test_users [0 ]]}
65+ assert "grant " in log_output
66+ self .assert_expected_grants_match_actual (project , "my_seed" , expected )
67+
68+ # run it again, with no config changes
69+ (results , log_output ) = run_dbt_and_capture (["--debug" , "seed" ])
70+ assert len (results ) == 1
71+ # seeds are always full-refreshed on this adapter, so we need to re-grant
72+ assert "revoke " not in log_output
73+ assert "grant " in log_output
74+ self .assert_expected_grants_match_actual (project , "my_seed" , expected )
75+
76+ # change the grantee, assert it updates
77+ updated_yaml = self .interpolate_name_overrides (user2_schema_base_yml )
78+ write_file (updated_yaml , project .project_root , "seeds" , "schema.yml" )
79+ (results , log_output ) = run_dbt_and_capture (["--debug" , "seed" ])
80+ assert len (results ) == 1
81+ expected = {select_privilege_name : ["user:" + test_users [1 ]]}
82+ self .assert_expected_grants_match_actual (project , "my_seed" , expected )
83+
84+ # run it again, with --full-refresh, grants should be the same
85+ run_dbt (["seed" , "--full-refresh" ])
86+ self .assert_expected_grants_match_actual (project , "my_seed" , expected )
87+
88+ # change config to 'grants: {}' -- should be completely ignored
89+ updated_yaml = self .interpolate_name_overrides (ignore_grants_yml )
90+ write_file (updated_yaml , project .project_root , "seeds" , "schema.yml" )
91+ (results , log_output ) = run_dbt_and_capture (["--debug" , "seed" ])
92+ assert len (results ) == 1
93+ assert "revoke " not in log_output
94+ assert "grant " not in log_output
95+ manifest = get_manifest (project .project_root )
96+ seed_id = "seed.test.my_seed"
97+ seed = manifest .nodes [seed_id ]
98+ expected_config = {}
99+ expected_actual = {select_privilege_name : [test_users [1 ]]}
100+ if self .seeds_support_partial_refresh ():
101+ # ACTUAL grants will NOT match expected grants
102+ self .assert_expected_grants_match_actual (project , "my_seed" , expected_actual )
103+ else :
104+ # there should be ZERO grants on the seed
105+ self .assert_expected_grants_match_actual (project , "my_seed" , expected_config )
106+
107+ # now run with ZERO grants -- all grants should be removed
108+ # whether explicitly (revoke) or implicitly (recreated without any grants added on)
109+ updated_yaml = self .interpolate_name_overrides (zero_grants_yml )
110+ write_file (updated_yaml , project .project_root , "seeds" , "schema.yml" )
111+ (results , log_output ) = run_dbt_and_capture (["--debug" , "seed" ])
112+ assert len (results ) == 1
113+ if self .seeds_support_partial_refresh ():
114+ assert "revoke " in log_output
115+ expected = {}
116+ self .assert_expected_grants_match_actual (project , "my_seed" , expected )
117+
118+ # run it again -- dbt shouldn't try to grant or revoke anything
119+ (results , log_output ) = run_dbt_and_capture (["--debug" , "seed" ])
120+ assert len (results ) == 1
121+ assert "revoke " not in log_output
122+ assert "grant " not in log_output
123+ self .assert_expected_grants_match_actual (project , "my_seed" , expected )
0 commit comments