mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Fixing header comparison.
This commit is contained in:
parent
d986008b4f
commit
78c9fc1987
1 changed files with 18 additions and 2 deletions
|
|
@ -37,12 +37,28 @@ class EmailMessageTestCase(TestCase):
|
||||||
f.read()
|
f.read()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _headers_identical(self, left, right):
|
||||||
|
""" Check if headers are identical.
|
||||||
|
|
||||||
|
This is particularly tricky because Python 2.6, Python 2.7 and Python 3
|
||||||
|
each handle this slightly differently. This should mash away all
|
||||||
|
of the differences, though.
|
||||||
|
|
||||||
|
"""
|
||||||
|
left = left.replace('\n\t', ' ').replace('\n ', ' ')
|
||||||
|
right = right.replace('\n\t', ' ').replace('\n ', ' ')
|
||||||
|
if right != left:
|
||||||
|
print(repr(left))
|
||||||
|
print(repr(right))
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def compare_email_objects(self, left, right):
|
def compare_email_objects(self, left, right):
|
||||||
# Compare headers
|
# Compare headers
|
||||||
for key, value in left.items():
|
for key, value in left.items():
|
||||||
if not right[key]:
|
if not right[key]:
|
||||||
raise AssertionError("Extra header '%s'" % key)
|
raise AssertionError("Extra header '%s'" % key)
|
||||||
if right[key].replace('\n\t', ' ') != value.replace('\n\t', ' '):
|
if not self._headers_identical(right[key], value):
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"Header '%s' unequal:\n%s\n%s" % (
|
"Header '%s' unequal:\n%s\n%s" % (
|
||||||
key,
|
key,
|
||||||
|
|
@ -53,7 +69,7 @@ class EmailMessageTestCase(TestCase):
|
||||||
for key, value in right.items():
|
for key, value in right.items():
|
||||||
if not left[key]:
|
if not left[key]:
|
||||||
raise AssertionError("Extra header '%s'" % key)
|
raise AssertionError("Extra header '%s'" % key)
|
||||||
if left[key].replace('\n\t', ' ') != value.replace('\n\t', ' '):
|
if not self._headers_identical(left[key], value):
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"Header '%s' unequal:\n%s\n%s" % (
|
"Header '%s' unequal:\n%s\n%s" % (
|
||||||
key,
|
key,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue