Fixed tests

This commit is contained in:
Antoine Nguyen
2024-11-04 14:48:17 +01:00
parent aa5d486a22
commit e3c113849e
7 changed files with 17 additions and 28 deletions
+4 -4
View File
@@ -9,11 +9,11 @@ from email.utils import formataddr, formatdate, getaddresses, make_msgid
import chardet
import lxml.html
from lxml.html import defs
from lxml.html.clean import Cleaner
from lxml_html_clean import Cleaner
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django.utils.encoding import smart_str, smart_str
from django.utils.encoding import smart_str
from django.utils.html import conditional_escape, escape
from django.utils.translation import gettext as _
@@ -26,7 +26,7 @@ _RE_REMOVE_EXTRA_WHITESPACE = re.compile(r"\n\s*\n")
_RE_CID = re.compile(r".*[ ]*cid=\"([^\"]*)\".*", re.I)
class EmailAddress(object):
class EmailAddress:
def __init__(self, address):
self.name, self.address = u2u_decode.decode_address(address)
@@ -39,7 +39,7 @@ class EmailAddress(object):
return self.fulladdress
class Email(object):
class Email:
_basic_headers = (
"From",
@@ -57,7 +57,7 @@ This is an *html* /test /_message._
:-)
--
--
Someone
someone@example.net
@@ -83,12 +83,11 @@ Content-Transfer-Encoding: 7bit
<img moz-do-not-send="false"
src="cid:part1.D56823CE.7959DBD4@example.net" alt="" height="10"
width="10"><br>
<pre class="moz-signature" cols="72">--
<pre class="moz-signature" cols="72">--
someone
<a class="moz-txt-link-abbreviated" href="mailto:someone@example.net">someone@example.net</a></pre>
</body>
</html>
--------------D585B241EEF60F0F44EC20E5
Content-Type: image/png;
name="image.png"
@@ -8,13 +8,8 @@
<span class="moz-smiley-s1"><span>:-)</span></span><br>
<br>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAF0lEQVQY02NgYGD4//8/ThKfHASMRN0AfaqVa6MQxIQAAAAASUVORK5CYII=" alt="" height="10" width="10" target="_blank"><br>
<pre class="moz-signature" cols="72">--
<pre class="moz-signature" cols="72">--
someone
<a class="moz-txt-link-abbreviated" href="mailto:someone@example.net" target="_blank" rel="nofollow">someone@example.net</a></pre>
</body>
<span><b>Some <i>HTML</i> text</b>, a <a href="http://example.net" target="_blank" rel="nofollow">link</a>, an␍
embedded image and an external image.<br>␍
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAF0lEQVQY02NgYGD4//8/ThKfHASMRN0AfaqVa6MQxIQAAAAASUVORK5CYII=" target="_blank"><br>␍
<img src="http://example.net/image.png" target="_blank"><br>␍
Nifty!</span>
</div>
</div>
@@ -8,13 +8,8 @@
<span class="moz-smiley-s1"><span>:-)</span></span><br>
<br>
<img alt="" height="10" width="10"><br>
<pre class="moz-signature" cols="72">--
<pre class="moz-signature" cols="72">--
someone
<a class="moz-txt-link-abbreviated">someone@example.net</a></pre>
</body>
<span><b>Some <i>HTML</i> text</b>, a <a target="_blank" rel="nofollow">link</a>, an␍
embedded image and an external image.<br>␍
<img target="_blank"><br>␍
<img target="_blank"><br>␍
Nifty!</span>
</div>
</div>
@@ -2,6 +2,6 @@
:-)
--
--
Someone
someone@example.net</pre>
someone@example.net</pre>
+4 -4
View File
@@ -34,10 +34,10 @@ class EmailTests(SimpleTestCase):
output: {message_id}-output-{dformat}_{no,}links.txt
"""
def _get_expected_output(self, message_id, **kwargs):
def _get_expected_output(self, message_id: str, **kwargs) -> str:
ext = kwargs["dformat"] if "dformat" in kwargs else "plain"
ext += "_links" if "links" in kwargs and kwargs["links"] else "_nolinks"
message_path = os.path.join(SAMPLES_DIR, "%s-output-%s.txt" % (message_id, ext))
message_path = os.path.join(SAMPLES_DIR, f"{message_id}-output-{ext}.txt")
assert os.path.isfile(message_path), "%s does not exist." % message_path
with open(message_path, "rb") as fp:
@@ -46,11 +46,11 @@ class EmailTests(SimpleTestCase):
return mail_text
def _test_email(self, message_id, **kwargs):
def _test_email(self, message_id: str, **kwargs) -> None:
"""Boiler plate code for testing e-mails."""
expected_output = self._get_expected_output(message_id, **kwargs)
output = EmailTestImplementation(message_id, **kwargs).body
self.assertEqual(output, expected_output)
self.assertEqual(output.strip("\n"), expected_output.strip("\n"))
def test_invalid_links_value(self):
"""modoboa-amavis set links = "0"; in python "0" == True, fixed in PR 79
+1 -1
View File
@@ -30,7 +30,7 @@ python-dateutil
cryptography
pytz
requests
lxml
lxml[html_clean]
chardet
ovh
oath