Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert default selectors tests to pytest #5820

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20220912-134000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Convert default selector tests to pytest
time: 2022-09-12T13:40:00.625912-05:00
custom:
Author: stu-k
Issue: "5728"
PR: "5820"

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions test/integration/073_default_selectors_tests/models/schema.yml

This file was deleted.

This file was deleted.

This file was deleted.

98 changes: 98 additions & 0 deletions tests/functional/selectors/test_default_selectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import pytest
from dbt.tests.util import run_dbt

models__schema_yml = """
version: 2

sources:
- name: src
schema: "{{ target.schema }}"
freshness:
warn_after: {count: 24, period: hour}
loaded_at_field: _loaded_at
tables:
- name: source_a
identifier: model_c
columns:
- name: fun
- name: _loaded_at
- name: src
schema: "{{ target.schema }}"
freshness:
warn_after: {count: 24, period: hour}
loaded_at_field: _loaded_at
tables:
- name: source_b
identifier: model_c
columns:
- name: fun
- name: _loaded_at

models:
- name: model_a
columns:
- name: fun
tags: [marketing]
- name: model_b
columns:
- name: fun
tags: [finance]
"""

models__model_a_sql = """
SELECT 1 AS fun
"""

models__model_b_sql = """
SELECT 1 AS fun
"""

seeds__model_c_csv = """fun,_loaded_at
1,2021-04-19 01:00:00"""


@pytest.fixture(scope="class")
def models():
return {
"schema.yml": models__schema_yml,
"model_b.sql": models__model_b_sql,
"model_a.sql": models__model_a_sql,
}


@pytest.fixture(scope="class")
def seeds():
return {"model_c.csv": seeds__model_c_csv}


@pytest.fixture(scope="class")
def selectors():
return """
selectors:
- name: default_selector
description: test default selector
definition:
union:
- method: source
value: "test.src.source_a"
- method: fqn
value: "model_a"
default: true
"""


class TestDefaultSelectors:
def test_model__list(self, project):
result = run_dbt(["ls", "--resource-type", "model"])
assert "test.model_a" in result

def test_model__compile(self, project):
result = run_dbt(["compile"])
assert len(result) == 1
assert result.results[0].node.name == "model_a"

def test_source__freshness(self, project):
run_dbt(["seed", "-s", "test.model_c"])
result = run_dbt(["source", "freshness"])
assert len(result) == 1
assert result.results[0].node.name == "source_a"