Skip to content

Commit

Permalink
Add test of metadata-based freshness mechanism
Browse files Browse the repository at this point in the history
peterallenwebb committed Oct 9, 2023
1 parent e39a6e7 commit 010c781
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# install latest changes in dbt-core
# TODO: how to automate switching from develop to version branches?
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git@paw%2Fmetadata-freshness#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter

# if version 1.x or greater -> pin to major version
33 changes: 33 additions & 0 deletions tests/functional/adapter/test_get_last_relation_modified.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import pytest

from dbt.tests.util import run_dbt

freshness_via_metadata_schema_yml = """version: 2
sources:
- name: test_source
freshness:
warn_after: {count: 10, period: hour}
error_after: {count: 1, period: day}
schema: "{{ env_var('DBT_TEST_SCHEMA_NAME_VARIABLE') }}"
tables:
- name: test_table
"""


class TestGetLastRelationModified:
@pytest.fixture(scope="class", autouse=True)
def set_env_vars(self, project):
os.environ["DBT_TEST_SCHEMA_NAME_VARIABLE"] = project.test_schema
yield
del os.environ["DBT_TEST_SCHEMA_NAME_VARIABLE"]

@pytest.fixture(scope="class")
def models(self):
return {"schema.yml": freshness_via_metadata_schema_yml}

def test_get_last_relation_modified(self, project, set_env_vars):
project.run_sql(
f"create table {project.test_schema}.test_table (id integer autoincrement, name varchar(100) not null);"
)
run_dbt(["source", "freshness"])

0 comments on commit 010c781

Please sign in to comment.