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

Assert #658 works #945

Merged
merged 2 commits into from
Jul 2, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests_functional/issues/658_nested_envvar_override/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: test

test:
pytest -v app_test.py
60 changes: 60 additions & 0 deletions tests_functional/issues/658_nested_envvar_override/app_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Given:
- loaded settings file with three nested levels a.b.c
When
- override nested value (a.b.c) with envvar loading
Should
- access the new value case-insensitive (a.b.c == A.B.C)
Instead
- lowercase override doesn't work, while uppercase work

https://github.com/dynaconf/dynaconf/issues/658
"""
from __future__ import annotations

from textwrap import dedent

from dynaconf import Dynaconf


def create_file(filename: str, data: str):
"""Utility to write files"""
with open(filename, "w") as f:
f.write(dedent(data))
return filename


def new_settings(tmp_path):
"""Common setup for tests"""
# settings file used
filename = create_file(
tmp_path / "s.yaml",
"""\
a:
b: foo
c:
d: hello
""",
)

# setup
return Dynaconf(
envvar_prefix="DYNACONF",
settings_files=filename,
)


def test_nested_one_uppercase(monkeypatch, tmp_path):
monkeypatch.setenv("DYNACONF_A__B", "OK")
assert new_settings(tmp_path).a.b == "OK"


def test_nested_two_lowercase(monkeypatch, tmp_path):
monkeypatch.setenv("DYNACONF_a__b__c", "OK")
assert new_settings(tmp_path).a.b.c == "OK"


def test_nested_two_uppercase(monkeypatch, tmp_path):
monkeypatch.setenv("DYNACONF_A__B__C", "OK")
assert new_settings(tmp_path).A.B.C == "OK"
assert new_settings(tmp_path).a.b.c == "OK" # failed before