Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def __contains__(self, key):
self.parser.has_option(self.SECTION, key))

def __getitem__(self, key):
if key in os.environ:
return os.environ[key]
try:
return self.parser.get(self.SECTION, key)
except NoOptionError:
Expand Down Expand Up @@ -163,6 +165,8 @@ def __contains__(self, key):
return key in os.environ or key in self.data

def __getitem__(self, key):
if key in os.environ:
return os.environ[key]
return self.data[key]


Expand All @@ -185,6 +189,8 @@ def __contains__(self, key):
return key in os.environ or key in self.data

def __getitem__(self, key):
if key in os.environ:
return os.environ[key]
return self.data[key]


Expand Down
6 changes: 6 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def test_env_with_quote(config):
assert '''"Y\'''' == config('KeyHasMixedQuotesAsData1')
assert '''\'Y"''' == config('KeyHasMixedQuotesAsData2')

def test_env_repo_reads_os_environ(config):
os.environ['KeyOnlyEnviron'] = 'This'
assert 'This' == config.repository['KeyOnlyEnviron']
del os.environ['KeyOnlyEnviron']


def test_env_repo_keyerror(config):
with pytest.raises(KeyError):
config.repository['UndefinedKey']
6 changes: 6 additions & 0 deletions tests/test_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def test_ini_empty_string_means_false(config):
assert False is config('KeyEmpty', cast=bool)


def test_ini_repo_reads_os_environ(config):
os.environ['KeyOnlyEnviron'] = 'This'
assert 'This' == config.repository['KeyOnlyEnviron']
del os.environ['KeyOnlyEnviron']


def test_ini_repo_keyerror(config):
with pytest.raises(KeyError):
config.repository['UndefinedKey']
9 changes: 9 additions & 0 deletions tests/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def test_secret_overriden_by_environ():
assert 'hi' == config('db_user')
del os.environ['db_user']

def test_secret_repo_reads_os_environ():
path = os.path.join(os.path.dirname(__file__), 'secrets')
repo = RepositorySecret(path)

os.environ['KeyOnlyEnviron'] = 'SOMETHING'
assert 'SOMETHING' == repo['KeyOnlyEnviron']
del os.environ['KeyOnlyEnviron']


def test_secret_repo_keyerror():
path = os.path.join(os.path.dirname(__file__), 'secrets')
repo = RepositorySecret(path)
Expand Down