forked from theskumar/python-dotenv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
64 lines (50 loc) · 1.95 KB
/
test_cli.py
File metadata and controls
64 lines (50 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from os.path import dirname, join
import sh
import dotenv
here = dirname(__file__)
dotenv_path = join(here, '.env')
def test_get_key():
sh.touch(dotenv_path)
success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')
stored_value = dotenv.get_key(dotenv_path, 'HELLO')
assert stored_value == 'WORLD'
sh.rm(dotenv_path)
assert dotenv.get_key(dotenv_path, 'HELLO') is None
success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')
assert success is None
def test_unset():
sh.touch(dotenv_path)
success, key_to_set, value_to_set = dotenv.set_key(dotenv_path, 'HELLO', 'WORLD')
stored_value = dotenv.get_key(dotenv_path, 'HELLO')
assert stored_value == 'WORLD'
success, key_to_unset = dotenv.unset_key(dotenv_path, 'HELLO')
assert dotenv.get_key(dotenv_path, 'HELLO') is None
sh.rm(dotenv_path)
success, key_to_unset = dotenv.unset_key(dotenv_path, 'HELLO')
assert success is None
def test_console_script(cli):
with cli.isolated_filesystem():
sh.touch(dotenv_path)
sh.dotenv('-f', dotenv_path, 'set', 'HELLO', 'WORLD')
output = sh.dotenv('-f', dotenv_path, 'get', 'HELLO', )
assert output == 'HELLO="WORLD"\n'
sh.rm(dotenv_path)
# should fail for not existing file
result = cli.invoke(dotenv.set, ['my_key', 'my_value'])
assert result.exit_code != 0
# should fail for not existing file
result = cli.invoke(dotenv.get, ['my_key'])
assert result.exit_code != 0
# should fail for not existing file
result = cli.invoke(dotenv.list, [])
assert result.exit_code != 0
def test_default_path(cli):
with cli.isolated_filesystem():
sh.touch(dotenv_path)
sh.cd(here)
sh.dotenv('set', 'HELLO', 'WORLD')
output = sh.dotenv('get', 'HELLO')
assert output == 'HELLO="WORLD"\n'
sh.rm(dotenv_path)