xtr_mime.testing ¶
Checks on the emails a test builds: their headers, subject, bodies and attachments.
Each check takes the message first and raises :class:AssertionError when the email is not
what the test expects, saying what was expected and, where it helps, what was found::
email = Email().to("fabien@example.com").subject("Your order shipped").text("Hello")
assert_email_header_same(email, "To", "fabien@example.com")
assert_email_subject_contains(email, "order")
assert_email_text_body_contains(email, "Hello")
A check asked about something a message cannot have — the headers of raw bytes, the subject
of a message that is not an :class:~xtr_mime.Email — raises
:class:~xtr_mime.exception.LogicError instead: the test is wrong, not the email.
Nothing here needs a test framework, and the package itself never imports this module.
assert_email_attachment_count ¶
Check message carries expected_value attachments, inline images included.
Raises:
-
AssertionError–When it carries another number.
-
LogicError–When
messageis not an :class:~xtr_mime.Email.
assert_email_html_body_contains ¶
Check the HTML body of message contains expected_text, markup included.
Raises:
-
AssertionError–When it does not.
-
LogicError–When
messageis not an :class:~xtr_mime.Email. -
InvalidArgumentError–When the body is bytes or a file in a charset Python does not know, as rendering the email reports it.
assert_email_html_body_not_contains ¶
Check the HTML body of message does not contain expected_text.
Raises:
-
AssertionError–When it does.
-
LogicError–When
messageis not an :class:~xtr_mime.Email. -
InvalidArgumentError–When the body is bytes or a file in a charset Python does not know, as rendering the email reports it.
assert_email_subject_contains ¶
Check the subject of message contains expected_value; a missing one reads empty.
Raises:
-
AssertionError–When it does not.
-
LogicError–When
messageis not an :class:~xtr_mime.Email.
assert_email_subject_not_contains ¶
Check the subject of message does not contain expected_value.
Raises:
-
AssertionError–When it does.
-
LogicError–When
messageis not an :class:~xtr_mime.Email.
assert_email_text_body_contains ¶
Check the text body of message contains expected_text; a missing one reads empty.
A body given as bytes is read in its charset, one given as a file from its start.
Raises:
-
AssertionError–When it does not.
-
LogicError–When
messageis not an :class:~xtr_mime.Email. -
InvalidArgumentError–When the body is bytes or a file in a charset Python does not know, as rendering the email reports it.
assert_email_text_body_not_contains ¶
Check the text body of message does not contain expected_text.
Raises:
-
AssertionError–When it does.
-
LogicError–When
messageis not an :class:~xtr_mime.Email. -
InvalidArgumentError–When the body is bytes or a file in a charset Python does not know, as rendering the email reports it.
assert_email_address_contains ¶
Check the header_name address header of message holds expected_value.
expected_value is the bare address, fabien@example.com, whatever name it is
written with.
Raises:
-
AssertionError–When no address of the header is
expected_value. -
LogicError–When
messageis raw bytes, or the header is missing or holds no address.
assert_email_has_header ¶
Check message has a header_name header.
Raises:
-
AssertionError–When it has none.
-
LogicError–When
messageis raw bytes, with no headers to read.
assert_email_header_not_same ¶
Check the header_name header of message is missing or reads another value.
Raises:
-
AssertionError–When the header reads
expected_value. -
LogicError–When
messageis raw bytes, with no headers to read.
assert_email_header_same ¶
Check the header_name header of message reads expected_value.
A text header is compared by its value, any other by its body as written on the wire —
"Fabien <fabien@example.com>" for an address.
Raises:
-
AssertionError–When the header reads anything else, or is missing.
-
LogicError–When
messageis raw bytes, with no headers to read.
assert_email_not_has_header ¶
Check message has no header_name header.
Raises:
-
AssertionError–When it has one.
-
LogicError–When
messageis raw bytes, with no headers to read.