-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
89 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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import delegator | ||
|
||
|
||
def test_simple_usage(monkeypatch): | ||
"""Check that cli shows prefixed variables.""" | ||
monkeypatch.setenv('SOM_TT_VALUE', '1') | ||
|
||
variables = delegator.run('dump-env -p SOM_TT_') | ||
assert variables.out == 'VALUE=1\n' | ||
|
||
|
||
def test_both_options(monkeypatch, env_file): | ||
""" | ||
Check with template and prefix. | ||
CLI must show all prefixed variables by template. | ||
""" | ||
monkeypatch.setenv('SOM_TT_VALUE', '1') | ||
|
||
variables = delegator.run('dump-env -p SOM_TT_ -t {0}'.format(env_file)) | ||
assert variables.out == 'NORMAL_KEY=SOMEVALUE\nVALUE=1\n' | ||
|
||
|
||
def test_multiple_prefixes(monkeypatch): | ||
""" | ||
Check that CLI with multiple prefixes. | ||
CLI must show all prefixed variables correctly. | ||
""" | ||
monkeypatch.setenv('SOM_TT_VALUE', '1') | ||
monkeypatch.setenv('ANOTHER_TT_VALUE', '2') | ||
|
||
variables = delegator.run('dump-env -p SOM_TT_ -p ANOTHER_TT_') | ||
assert variables.out == 'VALUE=2\n' | ||
|
||
|
||
def test_simple_usage_file_output(monkeypatch, tmpdir): | ||
"""Check that CLI puts prefixed variables into file correctly.""" | ||
monkeypatch.setenv('SOM_TT_VALUE', '1') | ||
|
||
filename = tmpdir.mkdir('tests').join('.env').strpath | ||
|
||
delegator.run('dump-env -p SOM_TT_ > {0}'.format(filename)) | ||
|
||
with open(filename) as env_file: | ||
assert env_file.read() == 'VALUE=1\n' |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import delegator | ||
|
||
|
||
def test_help_option(): | ||
"""Check that cli shows help.""" | ||
variables = delegator.run('dump-env --help') | ||
assert 'show this help message and exit' in variables.out | ||
assert '--template TEMPLATE' in variables.out | ||
assert '--prefix PREFIX' in variables.out | ||
assert '--strict' in variables.out | ||
assert variables.subprocess.returncode == 0 |
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,44 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import delegator | ||
|
||
|
||
def test_strict_vars1(monkeypatch): | ||
"""Check that cli works correctly with strict vars.""" | ||
monkeypatch.setenv('SOM_TT_VALUE', '1') | ||
monkeypatch.setenv('SOM_TT_KEY', '2') | ||
|
||
variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY') | ||
assert variables.out == 'KEY=2\nVALUE=1\n' | ||
assert variables.subprocess.returncode == 0 | ||
|
||
|
||
def test_strict_vars2(monkeypatch): | ||
"""Check that cli works correctly with strict vars.""" | ||
monkeypatch.setenv('SOM_TT_VALUE', '1') | ||
monkeypatch.setenv('SOM_TT_KEY', '2') | ||
|
||
variables = delegator.run( | ||
'dump-env -p SOM_TT_ --strict=SOM_TT_KEY --strict=SOM_TT_VALUE', | ||
) | ||
assert variables.out == 'KEY=2\nVALUE=1\n' | ||
assert variables.subprocess.returncode == 0 | ||
|
||
|
||
def test_strict_missing_vars1(monkeypatch): | ||
"""Check that cli raises errors for missing strict keys.""" | ||
variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY') | ||
assert variables.out == '' | ||
assert variables.err == 'Missing env vars: SOM_TT_KEY\n' | ||
assert variables.subprocess.returncode == 1 | ||
|
||
|
||
def test_strict_missing_vars2(monkeypatch): | ||
"""Check that cli raises errors for missing strict keys.""" | ||
variables = delegator.run( | ||
'dump-env -p SOM_TT_ --strict=SOM_TT_KEY --strict=SOM_TT_VALUE', | ||
) | ||
assert variables.out == '' | ||
assert 'SOM_TT_VALUE' in variables.err | ||
assert 'SOM_TT_KEY' in variables.err | ||
assert variables.subprocess.returncode == 1 |