Changeset 137:b2b8a22c47f0
- Timestamp:
- 03/17/10 01:45:40 (5 months ago)
- Author:
- Menno Smits <menno@…>
- Branch:
- default
- Message:
-
Cleaned up XLIST tests and fixed a few thinkos.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r136
|
r137
|
|
| 43 | 43 | return client._imap.host == 'imap.gmail.com' |
| 44 | 44 | |
| 45 | | def extract_folder_names(dat): |
| | 45 | def extract_normal_folders(dat): |
| 46 | 46 | ret = [] |
| 47 | 47 | for _, _, folder_name in dat: |
| … |
… |
|
| 59 | 59 | assert not client.has_capability('WONT EXIST') |
| 60 | 60 | |
| | 61 | |
| 61 | 62 | def test_list_folders(client): |
| 62 | 63 | clear_folders(client) |
| … |
… |
|
| 65 | 66 | client.create_folder(name) |
| 66 | 67 | |
| 67 | | folders = extract_folder_names(client.list_folders()) |
| | 68 | folders = extract_normal_folders(client.list_folders()) |
| 68 | 69 | assert len(folders) > 0, 'No folders visible on server' |
| 69 | 70 | assert 'INBOX' in [f.upper() for f in folders], 'INBOX not returned' |
| … |
… |
|
| 73 | 74 | #TODO: test wildcards |
| 74 | 75 | |
| | 76 | |
| | 77 | def test_xlist(client): |
| | 78 | clear_folders(client) |
| | 79 | |
| 75 | 80 | caps = client.capabilities() |
| 76 | 81 | if is_gmail(client): |
| 77 | | assert "XLIST" in caps, caps |
| 78 | | if 'XLIST' in caps: |
| 79 | | info = client.xlist_folders() |
| 80 | | folders = extract_folder_names(info) |
| 81 | | assert len(folders) > 0, 'No folders visible on server' |
| 82 | | for flags, _, _ in info: |
| 83 | | if '\\INBOX' in [flag.upper() for flag in flags]: |
| 84 | | break |
| | 82 | assert "XLIST" in caps, "expected XLIST in Gmail's capabilities but only got %r" % caps |
| | 83 | |
| | 84 | if not 'XLIST' in caps: |
| | 85 | print "Skipping XLIST tests, server doesn't support XLIST" |
| | 86 | return |
| | 87 | |
| | 88 | info = client.xlist_folders() |
| | 89 | assert len(info) > 0, 'No folders returned by XLIST' |
| | 90 | for flags, _, _ in info: |
| | 91 | if '\\INBOX' in [flag.upper() for flag in flags]: |
| | 92 | break |
| 85 | 93 | else: |
| 86 | 94 | raise AssertionError('INBOX not returned', info) |
| 87 | 95 | |
| 88 | | for name in some_folders: |
| 89 | | assert name in folders |
| 90 | | |
| 91 | 96 | |
| 92 | 97 | def test_select_and_close(client): |
| … |
… |
|
| 104 | 109 | clear_folders(client) |
| 105 | 110 | |
| 106 | | for folder in extract_folder_names(client.list_sub_folders()): |
| | 111 | for folder in extract_normal_folders(client.list_sub_folders()): |
| 107 | 112 | client.unsubscribe_folder(folder) |
| 108 | 113 | |
| … |
… |
|
| 114 | 119 | client.create_folder(folder) |
| 115 | 120 | |
| 116 | | all_folders = sorted(extract_folder_names(client.list_folders())) |
| | 121 | all_folders = sorted(extract_normal_folders(client.list_folders())) |
| 117 | 122 | |
| 118 | 123 | for folder in all_folders: |
| 119 | 124 | client.subscribe_folder(folder) |
| 120 | 125 | |
| 121 | | assert all_folders == sorted(extract_folder_names(client.list_sub_folders())) |
| | 126 | assert all_folders == sorted(extract_normal_folders(client.list_sub_folders())) |
| 122 | 127 | |
| 123 | 128 | for folder in all_folders: |
| 124 | 129 | client.unsubscribe_folder(folder) |
| 125 | | assert extract_folder_names(client.list_sub_folders()) == [] |
| | 130 | assert extract_normal_folders(client.list_sub_folders()) == [] |
| 126 | 131 | |
| 127 | 132 | assert_raises(imapclient.IMAPClient.Error, |
| … |
… |
|
| 148 | 153 | |
| 149 | 154 | assert client.folder_exists(folder) |
| 150 | | assert folder in extract_folder_names(client.list_folders()) |
| | 155 | assert folder in extract_normal_folders(client.list_folders()) |
| 151 | 156 | |
| 152 | 157 | client.select_folder(folder) |
| … |
… |
|
| 342 | 347 | test_capabilities(client) |
| 343 | 348 | test_list_folders(client) |
| | 349 | test_xlist(client) |
| 344 | 350 | test_select_and_close(client) |
| 345 | 351 | test_subscriptions(client) |
| … |
… |
|
| 361 | 367 | def clear_folders(client): |
| 362 | 368 | client.folder_encode = False |
| 363 | | for folder in extract_folder_names(client.list_folders()): |
| | 369 | for folder in extract_normal_folders(client.list_folders()): |
| 364 | 370 | if folder.upper() != 'INBOX': |
| 365 | 371 | client.delete_folder(folder) |