From 809b677bdecb4654536bc614da62891fdc5c3ca7 Mon Sep 17 00:00:00 2001 From: Kshitij Aranke Date: Fri, 12 Jul 2024 18:31:59 +0100 Subject: [PATCH] Check if test_env_vars_casing passes on 1.6.latest --- .gitignore | 1 + .../context_methods/test_env_vars_casing.py | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/functional/context_methods/test_env_vars_casing.py diff --git a/.gitignore b/.gitignore index a9bbe77cba9..24adc700834 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ venv/ # poetry poetry.lock +.venv/ diff --git a/tests/functional/context_methods/test_env_vars_casing.py b/tests/functional/context_methods/test_env_vars_casing.py new file mode 100644 index 00000000000..fc743782595 --- /dev/null +++ b/tests/functional/context_methods/test_env_vars_casing.py @@ -0,0 +1,64 @@ +import os + +import pytest + +from dbt.tests.util import run_dbt + +context_sql = """ + +{{ + config( + materialized='table' + ) +}} + +select + '{{ env_var("local_user", "") }}' as lowercase, + '{{ env_var("LOCAL_USER", "") }}' as uppercase, + '{{ env_var("lOcAl_UsEr", "") }}' as mixedcase +""" + + +class TestEnvVars: + @pytest.fixture(scope="class") + def models(self): + return {"context.sql": context_sql} + + @pytest.fixture(scope="class", autouse=True) + def setup(self): + os.environ["local_user"] = "dan" + yield + del os.environ["local_user"] + + def get_ctx_vars(self, project): + fields = [ + "lowercase", + "uppercase", + "mixedcase", + ] + field_list = ", ".join(['"{}"'.format(f) for f in fields]) + query = "select {field_list} from {schema}.context".format( + field_list=field_list, schema=project.test_schema + ) + vals = project.run_sql(query, fetch="all") + ctx = dict([(k, v) for (k, v) in zip(fields, vals[0])]) + return ctx + + def test_env_vars( + self, + project, + ): + results = run_dbt(["run"]) + assert len(results) == 1 + ctx = self.get_ctx_vars(project) + + assert ctx["lowercase"] == "dan" + + # Windows env-vars are not case-sensitive, but Linux/macOS ones are + # So on Windows, the uppercase and mixedcase vars should also resolve to "dan" + if os.name == "nt": + assert ctx["uppercase"] == "dan" + assert ctx["mixedcase"] == "dan" + else: + assert ctx["uppercase"] == "" + assert ctx["mixedcase"] == ""