Esempio n. 1
0
def test_smb_share_agent_operation_failure(mock_connect, mock_get_files,
                                           mock_write_section):
    mock_write_section.side_effect = OperationFailure(
        "Operation failure happened", [])
    args = parse_arguments([
        "hostname", "127.0.0.1", "--username", "username", "--password",
        "password"
    ], )
    with pytest.raises(OperationFailure, match="Operation failure happened"):
        smb_share_agent(args)
Esempio n. 2
0
def test_smb_share_agent(arg_list, files, expected_result):
    args = parse_arguments(arg_list)

    with mock.patch("cmk.special_agents.agent_smb_share.get_all_shared_files",
                    return_value=files):
        with mock.patch("cmk.special_agents.agent_smb_share.SectionWriter",
                        MockSectionWriter):
            smb_share_agent(args)

    assert MockSectionWriter.writer == expected_result
Esempio n. 3
0
def test_smb_share_agent_unsuccessful_connect(mock_connect):
    args = parse_arguments([
        "hostname", "127.0.0.1", "--username", "username", "--password",
        "password"
    ], )

    with pytest.raises(
            RuntimeError,
            match=
            "Connection to the remote host was declined. Check your credentials."
    ):
        smb_share_agent(args)
Esempio n. 4
0
def test_smb_share_agent_error():
    args = parse_arguments([
        "hostname", "127.0.0.1", "--username", "username", "--password",
        "password"
    ], )

    with mock.patch("cmk.special_agents.agent_smb_share.SMBConnection.connect"
                    ) as mock_connection:
        mock_connection.side_effect = NotConnectedError
        with pytest.raises(
                RuntimeError,
                match=
                "Could not connect to the remote host. Check your ip address and remote name.",
        ):
            smb_share_agent(args)