11import pytest
22
33from dbt .tests .util import run_dbt
4+ from dbt_common .dataclass_schema import ValidationError
45
56# Seed data for source tables
67seeds__source_table_csv = """id,_loaded_at
7778"""
7879
7980
81+ models__model_freshness_schema_yml_build_after_only = """
82+ models:
83+ - name: model_a
84+ description: Model with only model freshness defined
85+ config:
86+ freshness:
87+ build_after:
88+ updates_on: all
89+ """
90+
91+
92+ models__model_freshness_schema_yml_build_period_requires_count = """
93+ models:
94+ - name: model_a
95+ description: Model with only model freshness defined
96+ config:
97+ freshness:
98+ build_after:
99+ period: day
100+ """
101+
102+
103+ models__model_freshness_schema_yml_build_count_requires_period = """
104+ models:
105+ - name: model_a
106+ description: Model with only model freshness defined
107+ config:
108+ freshness:
109+ build_after:
110+ count: 1
111+ """
112+
113+
80114class TestModelFreshnessConfig :
81115
82116 @pytest .fixture (scope = "class" )
@@ -94,3 +128,49 @@ def test_model_freshness_configs(self, project):
94128 run_dbt (["parse" ])
95129 compile_results = run_dbt (["compile" ])
96130 assert len (compile_results ) == 5 # All 4 models compiled successfully
131+
132+
133+ class TestModelFreshnessConfigParseBuildAfterOnly :
134+ @pytest .fixture (scope = "class" )
135+ def models (self ):
136+ return {
137+ "schema.yml" : models__model_freshness_schema_yml_build_after_only ,
138+ "model_a.sql" : models__no_freshness_sql ,
139+ }
140+
141+ def test_model_freshness_configs (self , project ):
142+ run_dbt (["parse" ])
143+
144+
145+ class TestModelFreshnessConfigParseBuildPeriodRequiresCount :
146+ @pytest .fixture (scope = "class" )
147+ def models (self ):
148+ return {
149+ "schema.yml" : models__model_freshness_schema_yml_build_period_requires_count ,
150+ "model_a.sql" : models__no_freshness_sql ,
151+ }
152+
153+ def test_model_freshness_configs (self , project ):
154+ with pytest .raises (ValidationError ) as excinfo :
155+ run_dbt (["parse" ])
156+ expected_msg = (
157+ "`freshness.build_after` must have a value for `count` if a `period` is provided"
158+ )
159+ assert expected_msg in str (excinfo .value )
160+
161+
162+ class TestModelFreshnessConfigParseBuildCountRequiresPeriod :
163+ @pytest .fixture (scope = "class" )
164+ def models (self ):
165+ return {
166+ "schema.yml" : models__model_freshness_schema_yml_build_count_requires_period ,
167+ "model_a.sql" : models__no_freshness_sql ,
168+ }
169+
170+ def test_model_freshness_configs (self , project ):
171+ with pytest .raises (ValidationError ) as excinfo :
172+ run_dbt (["parse" ])
173+ expected_msg = (
174+ "`freshness.build_after` must have a value for `period` if a `count` is provided"
175+ )
176+ assert expected_msg in str (excinfo .value )
0 commit comments