MCPcopy
hub / github.com/django/django / assertMessageHasHeaders

Method assertMessageHasHeaders

tests/mail/tests.py:126–144  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

124
125class 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

Callers 3

test_long_linesMethod · 0.80

Calls 3

message_from_bytesFunction · 0.85
itemsMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected