bonzo.testing – Unit testing support for asynchronous code

Unit testing support for asynchronous code.

class bonzo.testing.AsyncSMTPTestCase(methodName: str = 'runTest')[source]

Bases: AsyncTestCase

A test case that starts up an SMTP server.

Subclasses must override get_request_callback(), which returns a SMTPServer callback to be tested.

close()[source]

Closes the stream.

connect(read_response=True)[source]

Creates a instance of IOStream for reading and writing bytes to the opened socket on the SMTP server address.

Parameters:

read_response (bool) – Reads the response of the server immediately after to establish connection. Useful to read the response and discard the welcome message.

get_request_callback()[source]

Should be overridden by subclasses to return a SMTPServer callback.

get_smtp_port()[source]

Returns the port used by the server.

A new port is chosen for each test.

get_smtp_server()[source]

Returns an instance of SMTPServer that will be used in the test case. It’s inmediatelly called when the AsyncSMTPTestCase is instanced.

get_smtpserver_options()[source]

May be overridden by subclasses to return additional keyword arguments for the server.

read_response()[source]

Reads the response of the stream.

send_mail(hostname, mail, rcpt, data)[source]

Sends a coherent sequence of command to send a message. Returns the result from the DATA command.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.