Ver código fonte

test: add more test for better coverage

Mikael Koli 4 anos atrás
pai
commit
5c45404194
2 arquivos alterados com 37 adições e 1 exclusões
  1. 21 1
      redmail/test/email/test_body.py
  2. 16 0
      redmail/test/test_utils.py

+ 21 - 1
redmail/test/email/test_body.py

@@ -182,4 +182,24 @@ def test_cc_bcc():
 def test_missing_subject():
     email = EmailSender(host=None, port=1234)
     with pytest.raises(ValueError):
-        email.get_message(sender="me@example.com", receivers=['you@example.com'])
+        email.get_message(sender="me@example.com", receivers=['you@example.com'])
+
+
+def test_no_table_templates():
+    email = EmailSender(host="localhost", port=0)
+
+    assert email.default_html_theme == "modest.html"
+    assert email.default_text_theme == "pandas.txt"
+
+    email.default_html_theme = None
+    email.default_text_theme = None
+    msg = email.get_message(
+        sender="me@gmail.com",
+        receivers="you@gmail.com",
+        subject="Some news",
+    )
+    assert dict(msg.items()) == {
+        'from': 'me@gmail.com', 
+        'subject': 'Some news', 
+        'to': 'you@gmail.com', 
+    }

+ 16 - 0
redmail/test/test_utils.py

@@ -0,0 +1,16 @@
+
+import pytest
+from redmail.utils import import_from_string
+
+def test_import_from_string():
+    my_pkg = import_from_string("pathlib", if_missing="ignore")
+    assert my_pkg is not None
+    assert hasattr(my_pkg, "Path")
+
+def test_import_from_string_ignore():
+    my_pkg = import_from_string("non_existent_package", if_missing="ignore")
+    assert my_pkg is None
+
+def test_import_from_string_raise():
+    with pytest.raises(ImportError):
+        my_pkg = import_from_string("non_existent_package", if_missing="raise")