-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
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 @@ | ||
import functools | ||
from unittest.mock import MagicMock | ||
import mock | ||
|
||
|
||
def session(func): | ||
@mock.patch("onep.onep.check_session", mock.MagicMock(return_value="dummysession")) | ||
@mock.patch("onep.util.load_session", mock.MagicMock(return_value="dummysession")) | ||
@functools.wraps(func) | ||
def _func(*args, **kwargs): | ||
func(*args, **kwargs) | ||
|
||
return _func |
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,54 @@ | ||
import pytest | ||
import mock | ||
|
||
from onep.onep import main | ||
from . import common | ||
|
||
|
||
@common.session | ||
@mock.patch("onep.commands.search.run", return_value=(True, "[]", "")) | ||
def test_search_no_result(a, capsys): | ||
try: | ||
main(["personal", "search", "dummy"]) | ||
except SystemExit: | ||
pass | ||
|
||
output = capsys.readouterr().err | ||
|
||
assert output == "" | ||
|
||
|
||
ENTRIES = """[{"id": "entry1", "title": "First entry"}, {"id": "entry2", "title": "Second entry"}]""" | ||
|
||
|
||
@common.session | ||
@mock.patch("onep.commands.search.run", return_value=(True, ENTRIES, "")) | ||
def test_search(a, capsys): | ||
try: | ||
main(["personal", "search", "-t", "dummy"]) | ||
except SystemExit: | ||
pass | ||
|
||
output = capsys.readouterr().out | ||
|
||
assert output.count("\n") == 3 | ||
assert "entry1" in output | ||
assert "First entry" in output | ||
assert "entry2" in output | ||
assert "Second entry" in output | ||
|
||
|
||
@common.session | ||
@mock.patch("onep.commands.search.run", return_value=(True, ENTRIES, "")) | ||
def test_search_filter(a, capsys): | ||
try: | ||
main(["personal", "search", "-t", "dummy", "Second"]) | ||
except SystemExit: | ||
pass | ||
|
||
output = capsys.readouterr().out | ||
|
||
assert output.count("\n") == 2 | ||
assert "entry1" not in output | ||
assert "entry2" in output | ||
assert "Second entry" in output |
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