Skip to content

Commit

Permalink
one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 30, 2024
1 parent be86bef commit c18e9ff
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/functional/defer_state/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,15 @@
- name: customers
"""

schema_source_with_updated_env_var_as_schema_property_yml = """
sources:
- name: jaffle_shop
database: "test"
schema: "updated"
tables:
- name: customers
"""

schema_source_with_jinja_as_database_property_yml = """
sources:
- name: jaffle_shop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from dbt.tests.util import get_artifact, run_dbt, write_file
Expand All @@ -6,6 +8,7 @@
schema_source_with_env_var_as_schema_property_yml,
schema_source_with_jinja_as_database_property_yml,
schema_source_with_jinja_as_schema_property_yml,
schema_source_with_updated_env_var_as_schema_property_yml,
schema_source_with_updated_jinja_as_database_property_yml,
schema_source_with_updated_jinja_as_schema_property_yml,
)
Expand All @@ -30,6 +33,53 @@ def models(self):
"schema.yml": schema_source_with_env_var_as_schema_property_yml,
}

def test_change_env_var(self, project):
# Generate ./state without changing environment variable value
run_dbt(["run"])
self.copy_state()

manifest_json = get_artifact(project.project_root, "target", "manifest.json")
assert manifest_json["sources"]["source.test.jaffle_shop.customers"]["schema"] == "table"
assert (
manifest_json["sources"]["source.test.jaffle_shop.customers"]["unrendered_schema"]
== "{{ env_var('DBT_TEST_STATE_MODIFIED') }}"
)

# Assert no false positive
results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert len(results) == 0

# Change environment variable and assert no false positive
# Environment variables do not have an effect on state:modified
os.environ["DBT_TEST_STATE_MODIFIED"] = "view"
results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert len(results) == 0

# Confirm env change changed schema, but not unrendered_schema
manifest_json = get_artifact(project.project_root, "target", "manifest.json")
assert manifest_json["sources"]["source.test.jaffle_shop.customers"]["schema"] == "view"
assert (
manifest_json["sources"]["source.test.jaffle_shop.customers"]["unrendered_schema"]
== "{{ env_var('DBT_TEST_STATE_MODIFIED') }}"
)

# Assert no false negative after actual change to schema
write_file(
schema_source_with_updated_env_var_as_schema_property_yml,
project.project_root,
"models",
"schema.yml",
)
results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert len(results) == 1

manifest_json = get_artifact(project.project_root, "target", "manifest.json")
assert manifest_json["sources"]["source.test.jaffle_shop.customers"]["schema"] == "updated"
assert (
manifest_json["sources"]["source.test.jaffle_shop.customers"]["unrendered_schema"]
== "updated"
)


class TestSourceNodeWithJinjaInDatabase(BaseModifiedState):
@pytest.fixture(scope="class")
Expand Down

0 comments on commit c18e9ff

Please sign in to comment.