-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop3tests.py
51 lines (40 loc) · 1.77 KB
/
pop3tests.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import unittest
import mail
import mailclient
import email
class Pop3Tests(unittest.TestCase):
with open('test_message.txt', 'rb') as file:
message = mail.Mail(file.read())
client = mailclient.MailClient('[email protected]', 'pass')
def test_is_message(self):
self.assertIsInstance(self.message.message, email.message.Message)
def test_get_header(self):
headers = list(self.message.get_headers('Subject', 'Not Exists',
'To'))
expected = [('Subject', 'Some Subject'),
('To', 'Слава Вихарев')]
self.assertSequenceEqual(headers, expected)
def test_get_message(self):
message = self.message.get_message()
expected = '''Hello World\nПривет Мир\nПривет'''
self.assertEqual(message, expected)
def test_check_number(self):
self.assertFalse(self.client.check_mail_number('-1', 5))
self.assertFalse(self.client.check_mail_number('0', 5))
self.assertTrue(self.client.check_mail_number('1', 5), 1)
self.assertTrue(self.client.check_mail_number('5', 5))
self.assertFalse(self.client.check_mail_number('6', 5))
self.assertFalse(self.client.check_mail_number('asd', 5))
def test_check_address(self):
address = '[email protected]'
self.assertTrue(mailclient.check_address(address))
address = 'domain.ru'
self.assertFalse(mailclient.check_address(address))
address = '@s.com'
self.assertFalse(mailclient.check_address(address))
address = '[email protected]'
self.assertFalse(mailclient.check_address(address))
address = 'a@com'
self.assertFalse(mailclient.check_address(address))
if __name__ == '__main__':
unittest.main()