1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
"""Module documentation goes here.""" |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
import unittest |
8
|
|
|
from src.mailbox_imap import MailboxCleanerIMAP |
9
|
|
|
from tests.test_mailbox_abstract import TestMailboxAbstract |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TestMailboxCleanerIMAP(TestMailboxAbstract, unittest.TestCase): |
13
|
|
|
"""Class documentation goes here.""" |
14
|
|
|
|
15
|
|
|
def test_basics(self): |
16
|
|
|
"""Testing basic class.""" |
17
|
|
|
|
18
|
|
|
imap = MailboxCleanerIMAP(self.args) |
19
|
|
|
with self.assertRaises(SystemExit) as error: |
20
|
|
|
imap.login() |
21
|
|
|
self.assertTrue("wrong server" in error.exception.code) |
22
|
|
|
|
|
|
|
|
23
|
|
|
imap._load_cache() |
|
|
|
|
24
|
|
|
imap.cleanup() |
25
|
|
|
|
26
|
|
|
def test_get_tags(self): |
27
|
|
|
"""Testing flag extraction.""" |
28
|
|
|
|
29
|
|
|
test_input = [(b'1 (RFC822 {242020}', b'\r\n'), |
30
|
|
|
b' UID 142377 FLAGS (\\Seen \\Recent NotJunk)'] |
31
|
|
|
test_output = MailboxCleanerIMAP.get_flags_from_struct(test_input) |
32
|
|
|
print("Result: ", test_output) |
33
|
|
|
self.assertTrue("Seen" in test_output) |
34
|
|
|
self.assertTrue("NotJunk" in test_output) |
35
|
|
|
self.assertFalse("Recent" in test_output) |
36
|
|
|
|
37
|
|
|
def test_convert_date(self): |
38
|
|
|
"""Testing date conversion.""" |
39
|
|
|
|
40
|
|
|
test_input = "Thu, 22 Oct 2020 12:38:26 +0200" |
41
|
|
|
test_output = MailboxCleanerIMAP.convert_date(test_input) |
42
|
|
|
test_expectation = '22-Oct-2020' |
43
|
|
|
print("Result: ", test_output) |
44
|
|
|
self.assertTrue(test_expectation in test_output) |
45
|
|
|
|
46
|
|
|
def test_struct(self): |
47
|
|
|
"""Testing struct parser.""" |
48
|
|
|
|
49
|
|
|
test_input = [(b'1 (RFC822 {242020}', b'\x80abc'), |
50
|
|
|
b' UID 142377 FLAGS (\\Seen \\Recent NotJunk)'] |
51
|
|
|
test_output = MailboxCleanerIMAP.get_msg_from_struct(test_input) |
52
|
|
|
test_output = test_output.as_string() |
53
|
|
|
test_expectation = 'abc' |
54
|
|
|
print("Result: '%s'" % test_output) |
55
|
|
|
self.assertTrue(test_expectation in test_output) |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
if __name__ == '__main__': |
59
|
|
|
unittest.main() |
60
|
|
|
|