-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathtest_enable.py
69 lines (50 loc) · 2 KB
/
test_enable.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright (c) 2017, Menno Smits
# Released subject to the New BSD License
# Please see http://en.wikipedia.org/wiki/BSD_licenses
from unittest.mock import Mock
from imapclient.exceptions import IllegalStateError
from .imapclient_test import IMAPClientTest
class TestEnable(IMAPClientTest):
def setUp(self):
super(TestEnable, self).setUp()
self.command = Mock()
self.client._raw_command_untagged = self.command
self.client._imap.state = "AUTH"
self.client._cached_capabilities = [b"ENABLE"]
def test_success(self):
self.command.return_value = b"CONDSTORE"
resp = self.client.enable("CONDSTORE")
self.command.assert_called_once_with(
b"ENABLE", [b"CONDSTORE"], uid=False, response_name="ENABLED", unpack=True
)
self.assertEqual(resp, [b"CONDSTORE"])
def test_failed1(self):
# When server returns an empty ENABLED response
self.command.return_value = b""
resp = self.client.enable("FOO")
self.command.assert_called_once_with(
b"ENABLE", [b"FOO"], uid=False, response_name="ENABLED", unpack=True
)
self.assertEqual(resp, [])
def test_failed2(self):
# When server returns no ENABLED response
self.command.return_value = None
resp = self.client.enable("FOO")
self.command.assert_called_once_with(
b"ENABLE", [b"FOO"], uid=False, response_name="ENABLED", unpack=True
)
self.assertEqual(resp, [])
def test_multiple(self):
self.command.return_value = b"FOO BAR"
resp = self.client.enable("FOO", "BAR")
self.command.assert_called_once_with(
b"ENABLE", [b"FOO", b"BAR"], uid=False, response_name="ENABLED", unpack=True
)
self.assertEqual(resp, [b"FOO", b"BAR"])
def test_wrong_state(self):
self.client._imap.state = "SELECTED"
self.assertRaises(
IllegalStateError,
self.client.enable,
"FOO",
)