Debian Codegraph @

tests/test_folder_status.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_test import IMAPClientTest
8
9
10 class TestFolderStatus(IMAPClientTest):
11 def test_basic(self):
12 self.client._imap.status.return_value = (
13 "OK",
14 [b"foo (MESSAGES 3 RECENT 0 UIDNEXT 4 UIDVALIDITY 1435636895 UNSEEN 0)"],
15 )
16
17 out = self.client.folder_status("foo")
18
19 self.client._imap.status.assert_called_once_with(
20 b'"foo"', "(MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN)"
21 )
22 self.assertDictEqual(
23 out,
24 {
25 b"MESSAGES": 3,
26 b"RECENT": 0,
27 b"UIDNEXT": 4,
28 b"UIDVALIDITY": 1435636895,
29 b"UNSEEN": 0,
30 },
31 )
32
33 def test_literal(self):
34 self.client._imap.status.return_value = (
35 "OK",
36 [(b"{3}", b"foo"), b" (UIDNEXT 4)"],
37 )
38
39 out = self.client.folder_status("foo", ["UIDNEXT"])
40
41 self.client._imap.status.assert_called_once_with(b'"foo"', "(UIDNEXT)")
42 self.assertDictEqual(out, {b"UIDNEXT": 4})
43
44 def test_extra_response(self):
45 # In production, we've seen folder names containing spaces come back
46 # like this and be broken into two components in the tuple.
47 server_response = [b"My files (UIDNEXT 24369)"]
48 mock = Mock(return_value=server_response)
49 self.client._command_and_check = mock
50
51 resp = self.client.folder_status("My files", ["UIDNEXT"])
52 self.assertEqual(resp, {b"UIDNEXT": 24369})
53
54 # We've also seen the response contain mailboxes we didn't
55 # ask for. In all known cases, the desired mailbox is last.
56 server_response = [b"sent (UIDNEXT 123)\nINBOX (UIDNEXT 24369)"]
57 mock = Mock(return_value=server_response)
58 self.client._command_and_check = mock
59
60 resp = self.client.folder_status("INBOX", ["UIDNEXT"])
61 self.assertEqual(resp, {b"UIDNEXT": 24369})