@@ -108,3 +108,96 @@ def test_sampling_pii_feature_disabled(test_id: str, dbt_project: DbtProject):
108108 for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
109109 ]
110110 assert len (samples ) == TEST_SAMPLE_ROW_COUNT
111+
112+
113+ @pytest .mark .skip_targets (["clickhouse" ])
114+ def test_sampling_disable_samples_flag (test_id : str , dbt_project : DbtProject ):
115+ """Test that disable_samples flag prevents sample collection regardless of PII tags"""
116+ null_count = 50
117+ data = [{COLUMN_NAME : None } for _ in range (null_count )]
118+
119+ test_result = dbt_project .test (
120+ test_id ,
121+ "not_null" ,
122+ dict (column_name = COLUMN_NAME ),
123+ data = data ,
124+ as_model = True ,
125+ model_config = {
126+ "config" : {"meta" : {"disable_samples" : True }, "tags" : ["normal" ]}
127+ },
128+ test_vars = {
129+ "enable_elementary_test_materialization" : True ,
130+ "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
131+ "disable_samples_on_pii_tables" : False ,
132+ "pii_table_tags" : ["pii" ],
133+ },
134+ )
135+ assert test_result ["status" ] == "fail"
136+
137+ samples = [
138+ json .loads (row ["result_row" ])
139+ for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
140+ ]
141+ assert len (samples ) == 0
142+
143+
144+ @pytest .mark .skip_targets (["clickhouse" ])
145+ def test_sampling_disable_samples_overrides_pii (test_id : str , dbt_project : DbtProject ):
146+ """Test that disable_samples flag overrides PII detection when both are present"""
147+ null_count = 50
148+ data = [{COLUMN_NAME : None } for _ in range (null_count )]
149+
150+ test_result = dbt_project .test (
151+ test_id ,
152+ "not_null" ,
153+ dict (column_name = COLUMN_NAME ),
154+ data = data ,
155+ as_model = True ,
156+ model_config = {"config" : {"meta" : {"disable_samples" : True }, "tags" : ["pii" ]}},
157+ test_vars = {
158+ "enable_elementary_test_materialization" : True ,
159+ "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
160+ "disable_samples_on_pii_tables" : True ,
161+ "pii_table_tags" : ["pii" ],
162+ },
163+ )
164+ assert test_result ["status" ] == "fail"
165+
166+ samples = [
167+ json .loads (row ["result_row" ])
168+ for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
169+ ]
170+ assert len (samples ) == 0
171+
172+
173+ @pytest .mark .skip_targets (["clickhouse" ])
174+ def test_sampling_disable_samples_false_allows_samples (
175+ test_id : str , dbt_project : DbtProject
176+ ):
177+ """Test that disable_samples: false allows sample collection normally"""
178+ null_count = 50
179+ data = [{COLUMN_NAME : None } for _ in range (null_count )]
180+
181+ test_result = dbt_project .test (
182+ test_id ,
183+ "not_null" ,
184+ dict (column_name = COLUMN_NAME ),
185+ data = data ,
186+ as_model = True ,
187+ model_config = {
188+ "config" : {"meta" : {"disable_samples" : False }, "tags" : ["normal" ]}
189+ },
190+ test_vars = {
191+ "enable_elementary_test_materialization" : True ,
192+ "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
193+ "disable_samples_on_pii_tables" : False ,
194+ "pii_table_tags" : ["pii" ],
195+ },
196+ )
197+ assert test_result ["status" ] == "fail"
198+
199+ samples = [
200+ json .loads (row ["result_row" ])
201+ for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
202+ ]
203+ assert len (samples ) == TEST_SAMPLE_ROW_COUNT
0 commit comments