@@ -39,8 +39,8 @@ def test_sampling_pii_disabled(test_id: str, dbt_project: DbtProject):
3939 test_vars = {
4040 "enable_elementary_test_materialization" : True ,
4141 "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
42- "disable_samples_on_pii_tables " : True ,
43- "pii_table_tags " : ["pii" , "sensitive" ],
42+ "disable_samples_on_pii_tags " : True ,
43+ "pii_tags " : ["pii" , "sensitive" ],
4444 },
4545 )
4646 assert test_result ["status" ] == "fail"
@@ -53,8 +53,8 @@ def test_sampling_pii_disabled(test_id: str, dbt_project: DbtProject):
5353
5454
5555@pytest .mark .skip_targets (["clickhouse" ])
56- def test_sampling_non_pii_enabled (test_id : str , dbt_project : DbtProject ):
57- """Test that non- PII tables still collect samples normally """
56+ def test_sampling_pii_disabled_with_default_config (test_id : str , dbt_project : DbtProject ):
57+ """Test that PII-tagged tables don't upload samples even when tests fail """
5858 null_count = 50
5959 data = [{COLUMN_NAME : None } for _ in range (null_count )]
6060
@@ -64,12 +64,11 @@ def test_sampling_non_pii_enabled(test_id: str, dbt_project: DbtProject):
6464 dict (column_name = COLUMN_NAME ),
6565 data = data ,
6666 as_model = True ,
67- model_config = {"config" : {"tags" : ["normal " ]}},
67+ model_config = {"config" : {"tags" : ["pii " ]}},
6868 test_vars = {
6969 "enable_elementary_test_materialization" : True ,
7070 "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
71- "disable_samples_on_pii_tables" : True ,
72- "pii_table_tags" : ["pii" , "sensitive" ],
71+ "disable_samples_on_pii_tags" : True ,
7372 },
7473 )
7574 assert test_result ["status" ] == "fail"
@@ -78,12 +77,11 @@ def test_sampling_non_pii_enabled(test_id: str, dbt_project: DbtProject):
7877 json .loads (row ["result_row" ])
7978 for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
8079 ]
81- assert len (samples ) == TEST_SAMPLE_ROW_COUNT
80+ assert len (samples ) == 0
8281
8382
84- @pytest .mark .skip_targets (["clickhouse" ])
85- def test_sampling_pii_feature_disabled (test_id : str , dbt_project : DbtProject ):
86- """Test that when PII feature is disabled, PII tables still collect samples"""
83+ def test_sampling_pii_enabled_with_default_config (test_id : str , dbt_project : DbtProject ):
84+ """Test that PII-tagged tables don't upload samples even when tests fail"""
8785 null_count = 50
8886 data = [{COLUMN_NAME : None } for _ in range (null_count )]
8987
@@ -97,8 +95,6 @@ def test_sampling_pii_feature_disabled(test_id: str, dbt_project: DbtProject):
9795 test_vars = {
9896 "enable_elementary_test_materialization" : True ,
9997 "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
100- "disable_samples_on_pii_tables" : False ,
101- "pii_table_tags" : ["pii" , "sensitive" ],
10298 },
10399 )
104100 assert test_result ["status" ] == "fail"
@@ -111,8 +107,8 @@ def test_sampling_pii_feature_disabled(test_id: str, dbt_project: DbtProject):
111107
112108
113109@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 """
110+ def test_sampling_non_pii_enabled (test_id : str , dbt_project : DbtProject ):
111+ """Test that non-PII tables still collect samples normally """
116112 null_count = 50
117113 data = [{COLUMN_NAME : None } for _ in range (null_count )]
118114
@@ -122,14 +118,41 @@ def test_sampling_disable_samples_flag(test_id: str, dbt_project: DbtProject):
122118 dict (column_name = COLUMN_NAME ),
123119 data = data ,
124120 as_model = True ,
125- model_config = {
126- "config" : {"meta" : {"disable_samples" : True }, "tags" : ["normal" ]}
121+ model_config = {"config" : {"tags" : ["normal" ]}},
122+ test_vars = {
123+ "enable_elementary_test_materialization" : True ,
124+ "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
125+ "disable_samples_on_pii_tags" : True ,
126+ "pii_tags" : ["pii" , "sensitive" ],
127127 },
128+ )
129+ assert test_result ["status" ] == "fail"
130+
131+ samples = [
132+ json .loads (row ["result_row" ])
133+ for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
134+ ]
135+ assert len (samples ) == TEST_SAMPLE_ROW_COUNT
136+
137+
138+ @pytest .mark .skip_targets (["clickhouse" ])
139+ def test_sampling_pii_feature_disabled (test_id : str , dbt_project : DbtProject ):
140+ """Test that when PII feature is disabled, PII tables still collect samples"""
141+ null_count = 50
142+ data = [{COLUMN_NAME : None } for _ in range (null_count )]
143+
144+ test_result = dbt_project .test (
145+ test_id ,
146+ "not_null" ,
147+ dict (column_name = COLUMN_NAME ),
148+ data = data ,
149+ as_model = True ,
150+ model_config = {"config" : {"tags" : ["pii" ]}},
128151 test_vars = {
129152 "enable_elementary_test_materialization" : True ,
130153 "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
131- "disable_samples_on_pii_tables " : False ,
132- "pii_table_tags " : ["pii" ],
154+ "disable_samples_on_pii_tags " : False ,
155+ "pii_tags " : ["pii" , "sensitive " ],
133156 },
134157 )
135158 assert test_result ["status" ] == "fail"
@@ -138,12 +161,13 @@ def test_sampling_disable_samples_flag(test_id: str, dbt_project: DbtProject):
138161 json .loads (row ["result_row" ])
139162 for row in dbt_project .run_query (SAMPLES_QUERY .format (test_id = test_id ))
140163 ]
141- assert len (samples ) == 0
164+ assert len (samples ) == TEST_SAMPLE_ROW_COUNT
165+
142166
143167
144168@pytest .mark .skip_targets (["clickhouse" ])
145169def 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"""
170+ """Test that disable_test_samples flag overrides PII detection when both are present"""
147171 null_count = 50
148172 data = [{COLUMN_NAME : None } for _ in range (null_count )]
149173
@@ -153,12 +177,12 @@ def test_sampling_disable_samples_overrides_pii(test_id: str, dbt_project: DbtPr
153177 dict (column_name = COLUMN_NAME ),
154178 data = data ,
155179 as_model = True ,
156- model_config = {"config" : {"meta" : {"disable_samples " : True }, "tags" : ["pii" ]}},
180+ model_config = {"config" : {"meta" : {"disable_test_samples " : True }, "tags" : ["pii" ]}},
157181 test_vars = {
158182 "enable_elementary_test_materialization" : True ,
159183 "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
160- "disable_samples_on_pii_tables " : True ,
161- "pii_table_tags " : ["pii" ],
184+ "disable_samples_on_pii_tags " : True ,
185+ "pii_tags " : ["pii" ],
162186 },
163187 )
164188 assert test_result ["status" ] == "fail"
@@ -174,7 +198,7 @@ def test_sampling_disable_samples_overrides_pii(test_id: str, dbt_project: DbtPr
174198def test_sampling_disable_samples_false_allows_samples (
175199 test_id : str , dbt_project : DbtProject
176200):
177- """Test that disable_samples : false allows sample collection normally"""
201+ """Test that disable_test_samples : false allows sample collection normally"""
178202 null_count = 50
179203 data = [{COLUMN_NAME : None } for _ in range (null_count )]
180204
@@ -185,13 +209,13 @@ def test_sampling_disable_samples_false_allows_samples(
185209 data = data ,
186210 as_model = True ,
187211 model_config = {
188- "config" : {"meta" : {"disable_samples " : False }, "tags" : ["normal" ]}
212+ "config" : {"meta" : {"disable_test_samples " : False }, "tags" : ["normal" ]}
189213 },
190214 test_vars = {
191215 "enable_elementary_test_materialization" : True ,
192216 "test_sample_row_count" : TEST_SAMPLE_ROW_COUNT ,
193- "disable_samples_on_pii_tables " : False ,
194- "pii_table_tags " : ["pii" ],
217+ "disable_samples_on_pii_tags " : False ,
218+ "pii_tags " : ["pii" ],
195219 },
196220 )
197221 assert test_result ["status" ] == "fail"
0 commit comments