Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thebjorn committed Jan 30, 2025
1 parent 2466439 commit de38d8a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
8 changes: 7 additions & 1 deletion seeqret/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def env(ctx):
for line in f.readlines() if line.strip()]

envserializer = SERIALIZERS['env']()
curdir = os.getcwd()
with seeqret_dir():
storage = SqliteStorage()

Expand All @@ -181,7 +182,12 @@ def env(ctx):
print(res)
print()

with open(os.path.join(ctx.obj['curdir'], '.env'), 'w') as f:
try:
curdir = ctx.obj['curdir']
except: # noqa
pass

with open(os.path.join(curdir, '.env'), 'w') as f:
f.write(res)
click.secho(f"\nCreated .env file with {len(secrets)} secrets", fg='green')

Expand Down
Empty file added tests/env.template
Empty file.
43 changes: 43 additions & 0 deletions tests/test_cli_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re
import sys
from click.testing import CliRunner

from seeqret.db_utils import debug_fetch_users, debug_secrets
from seeqret.main import cli, user, users, init, list
from seeqret.cli_group_add import key
from tests.clirunner_utils import print_result

from seeqret.main import cli, env
from seeqret.migrations.utils import current_version


def test_env():
runner = CliRunner(env=dict(TESTING="TRUE"))
with runner.isolated_filesystem():
result = runner.invoke(init, [
'.',
'--user=test',
'[email protected]',
])
if result.exit_code != 0: print_result(result)
assert result.exit_code == 0

assert len(debug_secrets()) == 0
result = runner.invoke(list)
assert result.exit_code == 0

result = runner.invoke(key, [
'FOO', 'BAR',
'--app=myapp',
'--env=dev'
])
if result.exit_code != 0: print_result(result)

with open('env.template', 'w') as f:
f.write(':dev\n')
result = runner.invoke(env)
if result.exit_code != 0: print_result(result)

assert result.exit_code == 0
assert 'FOO="BAR"' in open('.env').read()

13 changes: 13 additions & 0 deletions tests/test_cli_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re
import sys

from click.testing import CliRunner
from seeqret.main import cli, init, info
from seeqret.migrations.utils import current_version


def test_info():
runner = CliRunner(env=dict(TESTING="TRUE"))
with runner.isolated_filesystem():
result = runner.invoke(info)
assert result.exit_code == 0

0 comments on commit de38d8a

Please sign in to comment.