| 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 TestSort(IMAPClientTest): |
| 13 |
def setUp(self): |
| 14 |
super(TestSort, self).setUp() |
| 15 |
self.client._cached_capabilities = (b"SORT",) |
| 16 |
self.client._raw_command_untagged = Mock() |
| 17 |
self.client._raw_command_untagged.return_value = b"9 8 7" |
| 18 |
|
| 19 |
def check_call(self, expected_args): |
| 20 |
self.client._raw_command_untagged.assert_called_once_with( |
| 21 |
b"SORT", expected_args, unpack=True |
| 22 |
) |
| 23 |
|
| 24 |
def test_no_support(self): |
| 25 |
self.client._cached_capabilities = (b"BLAH",) |
| 26 |
self.assertRaises(CapabilityError, self.client.sort, "ARRIVAL") |
| 27 |
|
| 28 |
def test_single_criteria(self): |
| 29 |
ids = self.client.sort("arrival") |
| 30 |
|
| 31 |
self.check_call([b"(ARRIVAL)", b"UTF-8", b"ALL"]) |
| 32 |
self.assertSequenceEqual(ids, [9, 8, 7]) |
| 33 |
|
| 34 |
def test_multiple_criteria(self): |
| 35 |
self.client.sort(["arrival", b"SUBJECT"]) |
| 36 |
|
| 37 |
self.check_call([b"(ARRIVAL SUBJECT)", b"UTF-8", b"ALL"]) |
| 38 |
|
| 39 |
def test_all_args(self): |
| 40 |
self.client.sort("arrival", ["TEXT", "\u261e"], "UTF-7") |
| 41 |
|
| 42 |
self.check_call([b"(ARRIVAL)", b"UTF-7", b"TEXT", b"+Jh4-"]) |