Asserts that the `message` has all `headers`. message: can be an instance of an email.Message subclass or bytes with the contents of an email message. headers: should be a set of (header-name, header-value) tuples.
(self, message, headers)
| 124 | |
| 125 | class MailTestsMixin: |
| 126 | def assertMessageHasHeaders(self, message, headers): |
| 127 | """ |
| 128 | Asserts that the `message` has all `headers`. |
| 129 | |
| 130 | message: can be an instance of an email.Message subclass or bytes |
| 131 | with the contents of an email message. |
| 132 | headers: should be a set of (header-name, header-value) tuples. |
| 133 | """ |
| 134 | if isinstance(message, bytes): |
| 135 | message = message_from_bytes(message) |
| 136 | msg_headers = set(message.items()) |
| 137 | if not headers.issubset(msg_headers): |
| 138 | missing = "\n".join(f" {h}: {v}" for h, v in headers - msg_headers) |
| 139 | actual = "\n".join(f" {h}: {v}" for h, v in msg_headers) |
| 140 | raise self.failureException( |
| 141 | f"Expected headers not found in message.\n" |
| 142 | f"Missing headers:\n{missing}\n" |
| 143 | f"Actual headers:\n{actual}" |
| 144 | ) |
| 145 | |
| 146 | # In assertStartsWith()/assertEndsWith() failure messages, when truncating |
| 147 | # a long first ("haystack") string, include this many characters beyond the |
no test coverage detected