Skip to content

Commit ccb0c2d

Browse files
committed
feat: Add new test for selector
1 parent 87ab8ef commit ccb0c2d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,23 @@ def model_files(dbt_project_dir):
341341
return paths
342342

343343

344+
@pytest.fixture(scope="session")
345+
def selector_file(model_files, dbt_project_dir):
346+
"""Create a selector file."""
347+
p = dbt_project_dir / "selectors.yml"
348+
first_model = next(str(m.stem) for m in model_files)
349+
350+
p.write_text(f"""\
351+
selectors:
352+
- name: first_model
353+
definition:
354+
method: fqn
355+
value: "{first_model}"
356+
""")
357+
358+
return p
359+
360+
344361
@pytest.fixture(scope="session")
345362
def sources_file(model_files, database):
346363
"""Create test source file."""

tests/operators/test_dbt_run.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ def test_dbt_run_models(profiles_file, dbt_project_file, model_files, logs_dir):
136136
)
137137

138138

139+
def test_dbt_run_models_with_first_model_selector(
140+
profiles_file, dbt_project_file, model_files, selector_file, logs_dir
141+
):
142+
"""Test execution of DbtRunOperator with a single model selector."""
143+
op = DbtRunOperator(
144+
task_id="dbt_task",
145+
project_dir=dbt_project_file.parent,
146+
profiles_dir=profiles_file.parent,
147+
selector="first_model",
148+
do_xcom_push=True,
149+
log_path=logs_dir,
150+
log_level_file="info",
151+
debug=True,
152+
)
153+
154+
execution_results = op.execute({})
155+
run_result = execution_results["results"][0]
156+
157+
assert run_result["status"] == RunStatus.Success
158+
159+
log_file = logs_dir / "dbt.log"
160+
assert log_file.exists()
161+
162+
with open(log_file) as f:
163+
logs = f.read()
164+
165+
assert (
166+
"OK created view model public.model_4" in logs
167+
or "OK created sql view model public.model_4" in logs
168+
)
169+
170+
139171
def test_dbt_run_models_with_env_vars(
140172
profiles_file_with_env, dbt_project_file, model_files, logs_dir, database
141173
):

0 commit comments

Comments
 (0)