Changeset 136:5ea0fc2ddb18

Show
Ignore:
Timestamp:
03/17/10 01:32:55 (5 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

Added fetch tests to livetest.py

These exercise various fields including ENVELOPE. Passes on Dovecot and Gmail.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • livetest.py

    r134 r136  
    1111import imapclient 
    1212 
    13 #TODO: more fetch() testing 
    1413 
    1514SIMPLE_MESSAGE = 'Subject: something\r\n\r\nFoo\r\n' 
     15 
     16MULTIPART_MESSAGE = """\ 
     17From: Bob Smith <bob@smith.com> 
     18To: Some One <some@one.com> 
     19Date: Tue, 16 Mar 2010 16:45:32 +0000 
     20Message-ID: <1A472770E042064698CB5ADC83A12ACD39455AAB@ABC> 
     21MIME-Version: 1.0 
     22Subject: A multipart message 
     23Content-Type: multipart/mixed; boundary="===============1534046211==" 
     24 
     25--===============1534046211== 
     26Content-Type: text/html; charset="us-ascii" 
     27Content-Transfer-Encoding: quoted-printable 
     28 
     29<html><body> 
     30Here is the first part. 
     31</body></html> 
     32 
     33--===============1534046211== 
     34Content-Type: text/plain; charset="us-ascii" 
     35Content-Transfer-Encoding: 7bit 
     36 
     37Here is the second part. 
     38 
     39--===============1534046211==-- 
     40""".replace('\n', '\r\n') 
    1641 
    1742def is_gmail(client): 
     
    273298 
    274299 
     300def test_fetch(client): 
     301    clear_folder(client, 'INBOX') 
     302 
     303    client.select_folder('INBOX') 
     304    client.append('INBOX', MULTIPART_MESSAGE) 
     305 
     306    fields = ['RFC822', 'FLAGS', 'INTERNALDATE', 'ENVELOPE'] 
     307    msg_id = client.search()[0] 
     308    resp = client.fetch(msg_id, fields) 
     309 
     310    assert len(resp) == 1 
     311    msginfo = resp[msg_id] 
     312 
     313    assert set(msginfo.keys()) == set(fields + ['SEQ']) 
     314    assert msginfo['SEQ'] == 1 
     315    assert msginfo['RFC822'] == MULTIPART_MESSAGE 
     316    assert isinstance(msginfo['INTERNALDATE'], datetime) 
     317    assert isinstance(msginfo['FLAGS'], tuple) 
     318    assert msginfo['ENVELOPE'] == ('Tue, 16 Mar 2010 16:45:32 +0000', 
     319                                   'A multipart message', 
     320                                   (('Bob Smith', None, 'bob', 'smith.com'),), 
     321                                   (('Bob Smith', None, 'bob', 'smith.com'),), 
     322                                   (('Bob Smith', None, 'bob', 'smith.com'),), 
     323                                   (('Some One', None, 'some', 'one.com'),), 
     324                                   None, None, None, 
     325                                   '<1A472770E042064698CB5ADC83A12ACD39455AAB@ABC>') 
     326     
     327 
    275328def assert_raises(exception_class, func, *args, **kwargs): 
    276329    try: 
     
    286339    '''Run a sequence of tests against the IMAP server 
    287340    ''' 
    288     # The ordering of these tests is important 
     341    # The ordering of these tests is important (but shouldn't be!) 
    289342    test_capabilities(client) 
    290343    test_list_folders(client) 
     
    296349    test_flags(client) 
    297350    test_search(client) 
     351    test_fetch(client) 
    298352    test_copy(client) 
    299353