Changeset 137:b2b8a22c47f0

Show
Ignore:
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:
1 modified

Legend:

Unmodified
Added
Removed
  • livetest.py

    r136 r137  
    4343    return client._imap.host == 'imap.gmail.com' 
    4444 
    45 def extract_folder_names(dat): 
     45def extract_normal_folders(dat): 
    4646    ret = [] 
    4747    for _, _, folder_name in dat: 
     
    5959    assert not client.has_capability('WONT EXIST') 
    6060 
     61 
    6162def test_list_folders(client): 
    6263    clear_folders(client) 
     
    6566        client.create_folder(name) 
    6667 
    67     folders = extract_folder_names(client.list_folders()) 
     68    folders = extract_normal_folders(client.list_folders()) 
    6869    assert len(folders) > 0, 'No folders visible on server' 
    6970    assert 'INBOX' in [f.upper() for f in folders], 'INBOX not returned' 
     
    7374    #TODO: test wildcards 
    7475 
     76 
     77def test_xlist(client): 
     78    clear_folders(client) 
     79 
    7580    caps = client.capabilities() 
    7681    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 
    8593        else: 
    8694            raise AssertionError('INBOX not returned', info) 
    8795 
    88     for name in some_folders: 
    89         assert name in folders 
    90          
    9196 
    9297def test_select_and_close(client): 
     
    104109    clear_folders(client) 
    105110 
    106     for folder in extract_folder_names(client.list_sub_folders()): 
     111    for folder in extract_normal_folders(client.list_sub_folders()): 
    107112        client.unsubscribe_folder(folder) 
    108113 
     
    114119        client.create_folder(folder) 
    115120 
    116     all_folders = sorted(extract_folder_names(client.list_folders())) 
     121    all_folders = sorted(extract_normal_folders(client.list_folders())) 
    117122 
    118123    for folder in all_folders: 
    119124        client.subscribe_folder(folder) 
    120125 
    121     assert all_folders == sorted(extract_folder_names(client.list_sub_folders())) 
     126    assert all_folders == sorted(extract_normal_folders(client.list_sub_folders())) 
    122127 
    123128    for folder in all_folders: 
    124129        client.unsubscribe_folder(folder) 
    125     assert extract_folder_names(client.list_sub_folders()) == [] 
     130    assert extract_normal_folders(client.list_sub_folders()) == [] 
    126131 
    127132    assert_raises(imapclient.IMAPClient.Error, 
     
    148153 
    149154        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()) 
    151156 
    152157        client.select_folder(folder) 
     
    342347    test_capabilities(client) 
    343348    test_list_folders(client) 
     349    test_xlist(client) 
    344350    test_select_and_close(client) 
    345351    test_subscriptions(client) 
     
    361367def clear_folders(client): 
    362368    client.folder_encode = False 
    363     for folder in extract_folder_names(client.list_folders()): 
     369    for folder in extract_normal_folders(client.list_folders()): 
    364370        if folder.upper() != 'INBOX': 
    365371            client.delete_folder(folder)