Debian Codegraph @

tests/test_thread.py

raw
1 # Copyright (c) 2015, Menno Smits
2 # Released subject to the New BSD License
3 # Please see http://en.wikipedia.org/wiki/BSD_licenses
4
5 from unittest.mock import Mock
6
7 from imapclient.exceptions import CapabilityError
8
9 from .imapclient_test import IMAPClientTest
10
11
12 class TestThread(IMAPClientTest):
13 def setUp(self):
14 super(TestThread, self).setUp()
15 self.client._cached_capabilities = (b"THREAD=REFERENCES",)
16 self.client._raw_command_untagged = Mock()
17 self.client._raw_command_untagged.return_value = [b"(1 2)(3)(4 5 6)"]
18
19 def check_call(self, expected_args):
20 self.client._raw_command_untagged.assert_called_once_with(
21 b"THREAD", expected_args
22 )
23
24 def test_no_thread_support(self):
25 self.client._cached_capabilities = (b"NOT-THREAD",)
26 self.assertRaises(CapabilityError, self.client.thread)
27
28 def test_unsupported_algorithm(self):
29 self.client._cached_capabilities = (b"THREAD=FOO",)
30 self.assertRaises(CapabilityError, self.client.thread)
31
32 def test_defaults(self):
33 threads = self.client.thread()
34
35 self.check_call([b"REFERENCES", b"UTF-8", b"ALL"])
36 self.assertSequenceEqual(threads, ((1, 2), (3,), (4, 5, 6)))
37
38 def test_all_args(self):
39 self.client._cached_capabilities = (b"THREAD=COTTON",)
40
41 self.client.thread("COTTON", ["TEXT", "\u261e"], "UTF-7")
42
43 self.check_call([b"COTTON", b"UTF-7", b"TEXT", b"+Jh4-"])