ansible/test/units/plugins/terminal/test_junos.py
Sam Doran 2d266fbc87
Fix unit tests to work with pytest >= 5.0 (#60246)
pytest made a change in the way the message from ExceptionInfo objects was returned.

https://docs.pytest.org/en/latest/changelog.html#pytest-5-0-0-2019-06-28
2019-08-09 14:58:46 -04:00

55 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Copyright: (c) 2018, Fran Fitzpatrick <francis.x.fitzpatrick@gmail.com> fxfitz
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from mock import call, MagicMock
import pytest
from ansible.errors import AnsibleConnectionFailure
from ansible.plugins.terminal import junos
@pytest.fixture
def junos_terminal():
mock_connection = MagicMock()
return junos.TerminalModule(mock_connection)
def test_on_open_shell_sets_terminal_parameters(junos_terminal):
expected_calls = [
call(b'set cli timestamp disable'),
call(b'set cli screen-length 0'),
call(b'set cli screen-width 1024'),
]
junos_terminal._exec_cli_command = MagicMock()
junos_terminal._get_prompt = MagicMock()
junos_terminal._get_prompt.return_value = b'user@localhost >'
junos_terminal.on_open_shell()
junos_terminal._exec_cli_command.assert_has_calls(expected_calls)
def test_on_open_shell_enters_cli_if_root_prompt(junos_terminal):
expected_calls = [
call(b'cli'),
call(b'set cli timestamp disable'),
call(b'set cli screen-length 0'),
call(b'set cli screen-width 1024'),
]
junos_terminal._exec_cli_command = MagicMock()
junos_terminal._get_prompt = MagicMock()
junos_terminal._connection.get_prompt.return_value = b'root@localhost%'
junos_terminal.on_open_shell()
junos_terminal._exec_cli_command.assert_has_calls(expected_calls)
def test_on_open_shell_raises_problem_setting_terminal_config(junos_terminal):
junos_terminal._connection.exec_command.side_effect = AnsibleConnectionFailure
with pytest.raises(AnsibleConnectionFailure) as exc:
junos_terminal.on_open_shell()
assert 'unable to set terminal parameters' in str(exc.value)