This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+37 -28
View File
@@ -22,43 +22,52 @@ class TestNotifySmtp(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.mailer = MockSMTP('localhost', 25, 5, 'test@test.com', 1,
'testuser', 'testpass',
['recip1@example.com', 'testrecip@test.com'],
'HomeAssistant', 0)
self.mailer = MockSMTP(
"localhost",
25,
5,
"test@test.com",
1,
"testuser",
"testpass",
["recip1@example.com", "testrecip@test.com"],
"HomeAssistant",
0,
)
def tearDown(self): # pylint: disable=invalid-name
"""Stop down everything that was started."""
self.hass.stop()
@patch('email.utils.make_msgid', return_value='<mock@mock>')
@patch("email.utils.make_msgid", return_value="<mock@mock>")
def test_text_email(self, mock_make_msgid):
"""Test build of default text email behavior."""
msg = self.mailer.send_message('Test msg')
expected = ('^Content-Type: text/plain; charset="us-ascii"\n'
'MIME-Version: 1.0\n'
'Content-Transfer-Encoding: 7bit\n'
'Subject: Home Assistant\n'
'To: recip1@example.com,testrecip@test.com\n'
'From: HomeAssistant <test@test.com>\n'
'X-Mailer: HomeAssistant\n'
'Date: [^\n]+\n'
'Message-Id: <[^@]+@[^>]+>\n'
'\n'
'Test msg$')
msg = self.mailer.send_message("Test msg")
expected = (
'^Content-Type: text/plain; charset="us-ascii"\n'
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 7bit\n"
"Subject: Home Assistant\n"
"To: recip1@example.com,testrecip@test.com\n"
"From: HomeAssistant <test@test.com>\n"
"X-Mailer: HomeAssistant\n"
"Date: [^\n]+\n"
"Message-Id: <[^@]+@[^>]+>\n"
"\n"
"Test msg$"
)
assert re.search(expected, msg)
@patch('email.utils.make_msgid', return_value='<mock@mock>')
@patch("email.utils.make_msgid", return_value="<mock@mock>")
def test_mixed_email(self, mock_make_msgid):
"""Test build of mixed text email behavior."""
msg = self.mailer.send_message('Test msg',
data={'images': ['test.jpg']})
assert 'Content-Type: multipart/related' in msg
msg = self.mailer.send_message("Test msg", data={"images": ["test.jpg"]})
assert "Content-Type: multipart/related" in msg
@patch('email.utils.make_msgid', return_value='<mock@mock>')
@patch("email.utils.make_msgid", return_value="<mock@mock>")
def test_html_email(self, mock_make_msgid):
"""Test build of html email behavior."""
html = '''
html = """
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head><meta charset="UTF-8"></head>
@@ -70,8 +79,8 @@ class TestNotifySmtp(unittest.TestCase):
<img alt="test.jpg" src="cid:test.jpg"/>
</div>
</body>
</html>'''
msg = self.mailer.send_message('Test msg',
data={'html': html,
'images': ['test.jpg']})
assert 'Content-Type: multipart/related' in msg
</html>"""
msg = self.mailer.send_message(
"Test msg", data={"html": html, "images": ["test.jpg"]}
)
assert "Content-Type: multipart/related" in msg