Esempio n. 1
0
async def test_response_general_exception(stub_connection_manager,
                                          ex_undefined, request_ping):
    c = Client()
    c.connection = stub_connection_manager(return_value=ex_undefined)

    with pytest.raises(ResponseException):
        await c.send(request_ping)
Esempio n. 2
0
async def test_raises_timeout_exception(stub_connection_manager, ex_timeout,
                                        spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_timeout)

    with pytest.raises(TimeoutException):
        await client.send(spam)
Esempio n. 3
0
async def test_raises_no_perm_exception(stub_connection_manager, ex_no_perm,
                                        spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_no_perm)

    with pytest.raises(NoPermissionException):
        await client.send(spam)
Esempio n. 4
0
async def test_raises_config_exception(stub_connection_manager, ex_config,
                                       spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_config)

    with pytest.raises(ConfigException):
        await client.send(spam)
Esempio n. 5
0
async def test_raises_temp_fail_exception(stub_connection_manager,
                                          ex_temp_fail, spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_temp_fail)

    with pytest.raises(TemporaryFailureException):
        await client.send(spam)
Esempio n. 6
0
async def test_raises_protocol_exception(stub_connection_manager, ex_protocol,
                                         spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_protocol)

    with pytest.raises(ProtocolException):
        await client.send(spam)
Esempio n. 7
0
async def test_raises_cant_create_exception(stub_connection_manager,
                                            ex_cant_create, spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_cant_create)

    with pytest.raises(CantCreateException):
        await client.send(spam)
Esempio n. 8
0
async def test_raises_io_error_exception(stub_connection_manager, ex_io_err,
                                         spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_io_err)

    with pytest.raises(IOErrorException):
        await client.send(spam)
Esempio n. 9
0
async def test_raises_os_file_exception(stub_connection_manager, ex_os_file,
                                        spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_os_file)

    with pytest.raises(OSFileException):
        await client.send(spam)
Esempio n. 10
0
async def test_raises_software_exception(stub_connection_manager, ex_software,
                                         spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_software)

    with pytest.raises(InternalSoftwareException):
        await client.send(spam)
Esempio n. 11
0
async def test_raises_no_user_exception(stub_connection_manager, ex_no_user,
                                        spam):
    client = Client()
    client.connection = stub_connection_manager(return_value=ex_no_user)

    with pytest.raises(NoUserException):
        await client.send(spam)
Esempio n. 12
0
async def test_send(stub_connection_manager, request_ping, response_pong):
    client = Client()
    client.connection = stub_connection_manager(return_value=response_pong)

    response = await client.send(request_ping)

    assert isinstance(response, Response)
Esempio n. 13
0
async def test_send_with_user(stub_connection_manager, response_with_body,
                              spam, mocker):
    client = Client(host='localhost', user='******')
    client.connection = stub_connection_manager(
        return_value=response_with_body)
    send_spy = mocker.spy(client.connection.connection_stub, 'send')
    await client.check(spam)
    headers = send_spy.call_args[0][0].split(b'\r\n')[1:-1]
    has_user_header = [header.startswith(b'User') for header in headers]

    assert any(has_user_header)
Esempio n. 14
0
async def test_gtk_encoding(stub_connection_manager, response_ok):
    message = EmailMessage()
    message.add_header('From', 'wevsty <*****@*****.**>')
    message.add_header('Subject', '=?UTF-8?B?5Lit5paH5rWL6K+V?=')
    message.add_header('Message-ID', '<*****@*****.**>')
    message.add_header('Date', '')
    message.add_header('X-Mozilla-Draft-Info', '')
    message.add_header('User-Agent', '')
    message.set_param('charset', 'gbk')
    message.set_content('这是Unicode文字.' 'This is Unicode characters.')

    c = Client()
    c.connection = stub_connection_manager(return_value=response_ok)
    result = await c.check(message)

    assert result
Esempio n. 15
0
async def test_spam(stub_connection_manager, response_spam_header, spam):
    c = Client()
    c.connection = stub_connection_manager(return_value=response_spam_header)
    result = await c.check(spam)

    assert result
Esempio n. 16
0
async def test_bad_response_exception(stub_connection_manager, request_ping):
    c = Client()
    c.connection = stub_connection_manager(return_value=b'invalid')

    with pytest.raises(BadResponse):
        await c.send(request_ping)