mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Make SMTP tests fast
This commit is contained in:
parent
6cd57ac02f
commit
f7ac644c11
@ -1,5 +1,6 @@
|
|||||||
"""The tests for the notify smtp platform."""
|
"""The tests for the notify smtp platform."""
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.notify import smtp
|
from homeassistant.components.notify import smtp
|
||||||
|
|
||||||
@ -9,10 +10,6 @@ from tests.common import get_test_home_assistant
|
|||||||
class MockSMTP(smtp.MailNotificationService):
|
class MockSMTP(smtp.MailNotificationService):
|
||||||
"""Test SMTP object that doesn't need a working server."""
|
"""Test SMTP object that doesn't need a working server."""
|
||||||
|
|
||||||
def connection_is_valid(self):
|
|
||||||
"""Pretend connection is always valid for testing."""
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _send_email(self, msg):
|
def _send_email(self, msg):
|
||||||
"""Just return string for testing."""
|
"""Just return string for testing."""
|
||||||
return msg.as_string()
|
return msg.as_string()
|
||||||
@ -31,7 +28,8 @@ class TestNotifySmtp(unittest.TestCase):
|
|||||||
""""Stop down everything that was started."""
|
""""Stop down everything that was started."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_text_email(self):
|
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
||||||
|
def test_text_email(self, mock_make_msgid):
|
||||||
"""Test build of default text email behavior."""
|
"""Test build of default text email behavior."""
|
||||||
msg = self.mailer.send_message('Test msg')
|
msg = self.mailer.send_message('Test msg')
|
||||||
expected = ('^Content-Type: text/plain; charset="us-ascii"\n'
|
expected = ('^Content-Type: text/plain; charset="us-ascii"\n'
|
||||||
@ -47,7 +45,8 @@ class TestNotifySmtp(unittest.TestCase):
|
|||||||
'Test msg$')
|
'Test msg$')
|
||||||
self.assertRegex(msg, expected)
|
self.assertRegex(msg, expected)
|
||||||
|
|
||||||
def test_mixed_email(self):
|
@patch('email.utils.make_msgid', return_value='<mock@mock>')
|
||||||
|
def test_mixed_email(self, mock_make_msgid):
|
||||||
"""Test build of mixed text email behavior."""
|
"""Test build of mixed text email behavior."""
|
||||||
msg = self.mailer.send_message('Test msg',
|
msg = self.mailer.send_message('Test msg',
|
||||||
data={'images': ['test.jpg']})
|
data={'images': ['test.jpg']})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user