Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source template variable restrictions (#133)
* Source template variable restrictions Allows use of a dotenv template file to determine the list of non-prefixed and optionally required variable names. * Reduce source template code complexity
- Loading branch information
Showing
4 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import delegator | ||
|
||
|
||
def test_source_vars(monkeypatch, env_file): | ||
"""Check that cli shows only source variables.""" | ||
monkeypatch.setenv('NORMAL_KEY', '1') | ||
monkeypatch.setenv('EXTRA_VALUE', '2') | ||
|
||
variables = delegator.run('dump-env -s {0}'.format(env_file)) | ||
assert variables.out == 'NORMAL_KEY=1\n' | ||
assert variables.subprocess.returncode == 0 | ||
|
||
|
||
def test_source_prefixes(monkeypatch, env_file): | ||
"""Check that cli allows prefixes with source.""" | ||
monkeypatch.setenv('NORMAL_KEY', '1') | ||
monkeypatch.setenv('EXTRA_VALUE', '2') | ||
|
||
variables = delegator.run('dump-env -p EXTRA_ -s {0}'.format(env_file)) | ||
assert variables.out == 'NORMAL_KEY=1\nVALUE=2\n' | ||
assert variables.subprocess.returncode == 0 | ||
|
||
|
||
def test_source_strict(monkeypatch, env_file): | ||
"""Check that cli works correctly with strict-source.""" | ||
monkeypatch.setenv('NORMAL_KEY', '1') | ||
monkeypatch.setenv('EXTRA_VALUE', '2') | ||
|
||
variables = delegator.run( | ||
'dump-env --strict-source -s {0}'.format(env_file), | ||
) | ||
assert variables.out == 'NORMAL_KEY=1\n' | ||
assert variables.subprocess.returncode == 0 | ||
|
||
|
||
def test_source_strict_fail(monkeypatch, env_file): | ||
"""Check that cli works correctly with strict-source missing keys.""" | ||
monkeypatch.setenv('EXTRA_VALUE', '2') | ||
|
||
variables = delegator.run( | ||
'dump-env --strict-source -s {0}'.format(env_file), | ||
) | ||
assert variables.err == 'Missing env vars: NORMAL_KEY\n' | ||
assert variables.subprocess.returncode == 1 |