Skip to content

Commit

Permalink
tests: add unit test for _post_cli_attach
Browse files Browse the repository at this point in the history
testing only the relevant output

Signed-off-by: Renan Rodrigo <[email protected]>
  • Loading branch information
renanrodrigo committed Nov 24, 2023
1 parent 715ba56 commit 1dfa00f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions uaclient/cli/tests/test_cli_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from uaclient import event_logger, http, messages, util
from uaclient.cli import (
_post_cli_attach,
action_attach,
attach_parser,
get_parser,
Expand Down Expand Up @@ -231,6 +232,25 @@ def test_lock_file_exists(
}
assert expected == json.loads(capsys.readouterr()[0])

@mock.patch(
"uaclient.status.format_tabular", return_value="mock_tabular_status"
)
@mock.patch("uaclient.actions.status", return_value=("", 0))
@mock.patch(M_PATH + "daemon")
def test_post_cli_attach(
self, m_daemon, m_status, m_format_tabular, capsys, FakeConfig
):
cfg = FakeConfig.for_attached_machine()
_post_cli_attach(cfg)

assert [mock.call()] == m_daemon.stop.call_args_list
assert [mock.call(cfg)] == m_daemon.cleanup.call_args_list
assert [mock.call(cfg)] == m_status.call_args_list
assert [mock.call("")] == m_format_tabular.call_args_list
out, _ = capsys.readouterr()
assert "This machine is now attached to 'test_contract'" in out
assert "mock_tabular_status" in out

@mock.patch(
M_PATH + "contract.UAContractClient.update_activity_token",
)
Expand Down

0 comments on commit 1dfa00f

Please sign in to comment.