Selaa lähdekoodia

test: fix tests in CI for Python <=3.7

Mikael Koli 3 vuotta sitten
vanhempi
sitoutus
17f64608b1

+ 24 - 2
redmail/test/email/test_body.py

@@ -10,13 +10,17 @@ from platform import node
 
 from convert import remove_email_extra, remove_email_content_id, prune_generated_headers
 
-import platform
-PYTHON_VERSION = platform.sys.version_info
 IS_PY37 = sys.version_info < (3, 8)
 
 def test_text_message():
 
     sender = EmailSender(host=None, port=1234)
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        sender.domain = "REDMAIL-1234.mail.com"
+
     msg = sender.get_message(
         sender="me@example.com",
         receivers="you@example.com",
@@ -41,6 +45,12 @@ def test_text_message():
 def test_html_message():
 
     sender = EmailSender(host=None, port=1234)
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        sender.domain = "REDMAIL-1234.mail.com"
+
     msg = sender.get_message(
         sender="me@example.com",
         receivers="you@example.com",
@@ -76,6 +86,12 @@ def test_html_message():
 def test_text_and_html_message():
 
     sender = EmailSender(host=None, port=1234)
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        sender.domain = "REDMAIL-1234.mail.com"
+
     msg = sender.get_message(
         sender="me@example.com",
         receivers="you@example.com",
@@ -183,6 +199,12 @@ def test_without_jinja(use_jinja_obj, use_jinja):
     text = "Hi, \nThis is {{ user }} from { node }. I'm really {{ sender.full_name }}."
 
     sender = EmailSender(host=None, port=1234)
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        sender.domain = "REDMAIL-1234.mail.com"
+
     sender.use_jinja = use_jinja_obj
     msg = sender.get_message(
         sender="me@example.com",

+ 8 - 2
redmail/test/email/test_cookbook.py

@@ -1,10 +1,11 @@
-
-from typing import Union
+import sys
 from textwrap import dedent
 from redmail import EmailSender
 
 from convert import remove_email_content_id, prune_generated_headers
 
+IS_PY37 = sys.version_info < (3, 8)
+
 def test_distributions():
     class DistrSender(EmailSender):
         "Send email using pre-defined distribution lists"
@@ -33,6 +34,11 @@ def test_distributions():
             'group2': ["he@example.com", "she@example.com"],
         }
     )
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        email.domain = "REDMAIL-1234.mail.com"
 
     msg = email.get_message(
         sender="me@example.com",

+ 5 - 0
redmail/test/email/test_headers.py

@@ -56,6 +56,11 @@ def test_message_id():
 
 def test_cc_bcc():
     email = EmailSender(host=None, port=1234)
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        email.domain = "REDMAIL-1234.mail.com"
     msg = email.get_message(sender="me@example.com", subject="Some email", cc=['you@example.com'], bcc=['he@example.com', 'she@example.com'])
     msg = prune_generated_headers(str(msg))
     assert remove_email_content_id(msg) == dedent("""

+ 8 - 2
redmail/test/email/test_template.py

@@ -1,3 +1,4 @@
+import sys
 from textwrap import dedent
 from jinja2 import Environment
 from redmail import EmailSender
@@ -5,9 +6,8 @@ from redmail import EmailSender
 import pytest
 
 from convert import remove_email_extra, remove_email_content_id, prune_generated_headers
-from getpass import getpass, getuser
-from platform import node
 
+IS_PY37 = sys.version_info < (3, 8)
 
 def test_template(tmpdir):
     
@@ -54,6 +54,12 @@ def test_template(tmpdir):
 def test_jinja_env(tmpdir):
 
     sender = EmailSender(host=None, port=1234)
+    if IS_PY37:
+        # CI has FQDN that has UTF-8 chars and goes to new line
+        # for Python <=3.7. We set a realistic looking domain
+        # name for easier testing
+        sender.domain = "REDMAIL-1234.mail.com"
+
     env = Environment()
     env.globals["my_param"] = "<a value>"
     sender.templates_text = env