-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fake.py
36 lines (26 loc) · 928 Bytes
/
test_fake.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import smtplib
import unittest
from alert import EmailSender
class fake_SMTP:
calls = []
def __init__(self, _server, _port):
self.calls.append("__init__('%s', %d)" % (_server, _port) )
def sendmail(self, _from, _to, _msg):
self.calls.append("sendmail('%s', %s, <msg>)" % (_from, _to))
def quit(self):
self.calls.append("quit()")
class TestFakeSendEmail(unittest.TestCase):
def setUp(self):
self.real_SMTP = getattr(smtplib, 'SMTP')
setattr(smtplib, 'SMTP', fake_SMTP)
def tearDown(self):
setattr(smtplib, 'SMTP', self.real_SMTP)
def test_fake(self):
name = 'Yoyo'
email = EmailSender()
email.send_message(['[email protected]'], name)
self.assertEqual(fake_SMTP.calls,
["__init__('localhost', 1025)",
"sendmail('user', ['[email protected]'], <msg>)",
"quit()"]
)