Changeset 134:9ae0c002f903
- Timestamp:
- 31/01/10 11:34:44 (2 years ago)
- Author:
- Mark Hammond <mhammond@…>
- Branch:
- default
- Message:
-
make livetest work with gmail
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r131
|
r134
|
|
| 14 | 14 | |
| 15 | 15 | SIMPLE_MESSAGE = 'Subject: something\r\n\r\nFoo\r\n' |
| | 16 | |
| | 17 | def is_gmail(client): |
| | 18 | return client._imap.host == 'imap.gmail.com' |
| | 19 | |
| | 20 | def extract_folder_names(dat): |
| | 21 | ret = [] |
| | 22 | for _, _, folder_name in dat: |
| | 23 | # gmail's "special" folders start with '[' |
| | 24 | if not folder_name.startswith('['): |
| | 25 | ret.append(folder_name) |
| | 26 | return ret |
| 16 | 27 | |
| 17 | 28 | def test_capabilities(client): |
| … |
… |
|
| 29 | 40 | client.create_folder(name) |
| 30 | 41 | |
| 31 | | folders = client.list_folders() |
| | 42 | folders = extract_folder_names(client.list_folders()) |
| 32 | 43 | assert len(folders) > 0, 'No folders visible on server' |
| 33 | 44 | assert 'INBOX' in [f.upper() for f in folders], 'INBOX not returned' |
| … |
… |
|
| 37 | 48 | #TODO: test wildcards |
| 38 | 49 | |
| | 50 | caps = client.capabilities() |
| | 51 | if is_gmail(client): |
| | 52 | assert "XLIST" in caps, caps |
| | 53 | if 'XLIST' in caps: |
| | 54 | info = client.xlist_folders() |
| | 55 | folders = extract_folder_names(info) |
| | 56 | assert len(folders) > 0, 'No folders visible on server' |
| | 57 | for flags, _, _ in info: |
| | 58 | if '\\INBOX' in [flag.upper() for flag in flags]: |
| | 59 | break |
| | 60 | else: |
| | 61 | raise AssertionError('INBOX not returned', info) |
| | 62 | |
| | 63 | for name in some_folders: |
| | 64 | assert name in folders |
| | 65 | |
| 39 | 66 | |
| 40 | 67 | def test_select_and_close(client): |
| … |
… |
|
| 52 | 79 | clear_folders(client) |
| 53 | 80 | |
| 54 | | for folder in client.list_sub_folders(): |
| | 81 | for folder in extract_folder_names(client.list_sub_folders()): |
| 55 | 82 | client.unsubscribe_folder(folder) |
| 56 | 83 | |
| … |
… |
|
| 62 | 89 | client.create_folder(folder) |
| 63 | 90 | |
| 64 | | all_folders = sorted(client.list_folders()) |
| | 91 | all_folders = sorted(extract_folder_names(client.list_folders())) |
| 65 | 92 | |
| 66 | 93 | for folder in all_folders: |
| 67 | 94 | client.subscribe_folder(folder) |
| 68 | 95 | |
| 69 | | assert all_folders == sorted(client.list_sub_folders()) |
| | 96 | assert all_folders == sorted(extract_folder_names(client.list_sub_folders())) |
| 70 | 97 | |
| 71 | 98 | for folder in all_folders: |
| 72 | 99 | client.unsubscribe_folder(folder) |
| 73 | | assert client.list_sub_folders() == [] |
| | 100 | assert extract_folder_names(client.list_sub_folders()) == [] |
| 74 | 101 | |
| 75 | 102 | assert_raises(imapclient.IMAPClient.Error, |
| … |
… |
|
| 96 | 123 | |
| 97 | 124 | assert client.folder_exists(folder) |
| 98 | | assert folder in client.list_folders() |
| | 125 | assert folder in extract_folder_names(client.list_folders()) |
| 99 | 126 | |
| 100 | 127 | client.select_folder(folder) |
| … |
… |
|
| 115 | 142 | try: |
| 116 | 143 | status = client.folder_status(new_folder) |
| 117 | | assert status['MESSAGES'] == 0 |
| 118 | | assert status['RECENT'] == 0 |
| 119 | | assert status['UNSEEN'] == 0 |
| | 144 | assert status['MESSAGES'] == 0, status |
| | 145 | assert status['RECENT'] == 0, status |
| | 146 | assert status['UNSEEN'] == 0, status |
| 120 | 147 | |
| 121 | 148 | # Add a message to the folder, it should show up now. |
| … |
… |
|
| 123 | 150 | |
| 124 | 151 | status = client.folder_status(new_folder) |
| 125 | | assert status['MESSAGES'] == 1 |
| 126 | | assert status['RECENT'] == 1 |
| 127 | | assert status['UNSEEN'] == 1 |
| | 152 | assert status['MESSAGES'] == 1, status |
| | 153 | if not is_gmail(client): |
| | 154 | assert status['RECENT'] == 1, status |
| | 155 | assert status['UNSEEN'] == 1, status |
| 128 | 156 | |
| 129 | 157 | finally: |
| … |
… |
|
| 207 | 235 | |
| 208 | 236 | messages_all = client.search('ALL') |
| 209 | | assert len(messages_all) == len(subjects) # Check we see all messages |
| | 237 | if is_gmail(client): |
| | 238 | # gmail seems to never return deleted items. |
| | 239 | assert len(messages_all) == len(subjects)-1 # Check we see all messages |
| | 240 | else: |
| | 241 | assert len(messages_all) == len(subjects) # Check we see all messages |
| 210 | 242 | assert client.search() == messages_all # Check default |
| 211 | 243 | |
| 212 | 244 | # Single criteria |
| 213 | | assert len(client.search('DELETED')) == 1 |
| 214 | | assert len(client.search('NOT DELETED')) == len(subjects) - 1 |
| | 245 | if not is_gmail(client): |
| | 246 | assert len(client.search('DELETED')) == 1 |
| | 247 | assert len(client.search('NOT DELETED')) == len(subjects) - 1 |
| 215 | 248 | assert client.search('NOT DELETED') == client.search(['NOT DELETED']) |
| 216 | 249 | |
| … |
… |
|
| 274 | 307 | def clear_folders(client): |
| 275 | 308 | client.folder_encode = False |
| 276 | | for folder in client.list_folders(): |
| | 309 | for folder in extract_folder_names(client.list_folders()): |
| 277 | 310 | if folder.upper() != 'INBOX': |
| 278 | 311 | client.delete_folder(folder) |