Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cover commands start and help with unit tests #658

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions aries_cloudagent/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def load_command(command: str):
for cmd in available_commands():
if cmd["name"] == command:
module = cmd["name"]
if "module" in cmd:
module_path = cmd["module"]
module_path = cmd.get("module")
break
if module and not module_path:
module_path = f"{__package__}.{module}"
Expand Down
9 changes: 7 additions & 2 deletions aries_cloudagent/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ def execute(argv: Sequence[str] = None):
parser.print_help()


if __name__ == "__main__":
execute()
def main():
"""Execute the main line."""
if __name__ == "__main__":
execute()


main()
9 changes: 7 additions & 2 deletions aries_cloudagent/commands/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@ def execute(argv: Sequence[str] = None):
loop.run_until_complete(provision(settings))


if __name__ == "__main__":
execute()
def main():
"""Execute the main line."""
if __name__ == "__main__":
execute()


main()
18 changes: 16 additions & 2 deletions aries_cloudagent/commands/tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ class TestHelp(AsyncTestCase):
def test_exec_help(self):
with async_mock.patch.object(
command.ArgumentParser, "print_help"
) as print_help:
) as mock_print_help, async_mock.patch(
"builtins.print", async_mock.MagicMock()
) as mock_print:
command.execute([])
print_help.assert_called_once()
mock_print_help.assert_called_once()

command.execute(["-v"])
mock_print.assert_called_once_with(command.__version__)

def test_main(self):
with async_mock.patch.object(
command, "__name__", "__main__"
) as mock_name, async_mock.patch.object(
command, "execute", async_mock.MagicMock()
) as mock_execute:
command.main()
mock_execute.assert_called_once
22 changes: 22 additions & 0 deletions aries_cloudagent/commands/tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from asynctest import TestCase as AsyncTestCase
from asynctest import mock as async_mock

from ... import commands as test_module


class TestInit(AsyncTestCase):
def test_available(self):
avail = test_module.available_commands()
assert len(avail) == 3

def test_run(self):
with async_mock.patch.object(
test_module, "load_command", async_mock.MagicMock()
) as mock_load:
mock_module = async_mock.MagicMock()
mock_module.execute = async_mock.MagicMock()
mock_load.return_value = mock_module

test_module.run_command("hello", ["world"])
mock_load.assert_called_once()
mock_module.execute.assert_called_once()
17 changes: 17 additions & 0 deletions aries_cloudagent/commands/tests/test_provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ def test_bad_calls(self):
def test_provision_wallet(self):
test_seed = "testseed000000000000000000000001"
command.execute(["--wallet-type", "indy", "--seed", test_seed])

async def test_provision_ledger_configured(self):
with async_mock.patch.object(
command, "wallet_config", async_mock.CoroutineMock()
) as mock_wallet_config, async_mock.patch.object(
command, "ledger_config", async_mock.CoroutineMock(return_value=True)
) as mock_ledger_config:
await command.provision({})

def test_main(self):
with async_mock.patch.object(
command, "__name__", "__main__"
) as mock_name, async_mock.patch.object(
command, "execute", async_mock.MagicMock()
) as mock_execute:
command.main()
mock_execute.assert_called_once