Skip to content

Commit

Permalink
Assert #658 works (#945)
Browse files Browse the repository at this point in the history
* assert #658 works

* fix linting
  • Loading branch information
pedro-psb committed Jul 2, 2023
1 parent c4f48ea commit c43c29e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
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

0 comments on commit c43c29e

Please sign in to comment.