Skip to content

Commit

Permalink
Better tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed May 14, 2022
1 parent 6c6ce8a commit 0398e9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion onep/commands/vaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import sys

from ..util import fatal, run, create_table
from ..util import exit, fatal, run, create_table


def vaults(session: str, to_json: bool) -> None:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
import mock

from onep.onep import main


@mock.patch("onep.onep.check_session", return_value="dummysession")
@mock.patch("onep.util.load_session", return_value="dummysession")
@mock.patch("onep.commands.vaults.run", return_value=(False, "", "dummy error from upstream"))
def test_error(a, b, c, capsys):
with pytest.raises(SystemExit) as e:
main(["personal", "vaults"])

output = capsys.readouterr().err

assert e.value.code == 1
assert "ERROR:" in output
assert "dummy error from upstream" in output
7 changes: 5 additions & 2 deletions tests/test_vaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
@mock.patch("onep.onep.check_session", return_value="dummysession")
@mock.patch("onep.util.load_session", return_value="dummysession")
@mock.patch("onep.commands.vaults.run", return_value=(True, "{}", ""))
def test_no_vaults(a, b, c):
def test_no_vaults(a, b, c, capsys):
with pytest.raises(SystemExit) as e:
main(["personal", "vaults"])

assert "There are no vaults in this account." in str(e.value)
output = capsys.readouterr().err

assert e.value.code == 0
assert "There are no vaults in this account." in output


TWO_VAULTS_OUTPUT = """[{"id": "vault1", "name": "First vault"}, {"id": "vault2", "name": "Second vault"}]"""
Expand Down

0 comments on commit 0398e9f

Please sign in to comment.