Passed
Push — main ( 242f40...8b1e40 )
by Alexander
01:29
created

tests.test_mailbox_imap   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestMailboxCleanerIMAP.test_get_tags() 0 10 1
A TestMailboxCleanerIMAP.test_basics() 0 10 2
A TestMailboxCleanerIMAP.test_convert_date() 0 8 1
A TestMailboxCleanerIMAP.test_struct() 0 10 1
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
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
23
        imap._load_cache()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _load_cache was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
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