From: Menno Smits Date: Mon, 8 Nov 2010 13:08:35 +0000 (+0000) Subject: Working BODY and BODYSTRUCTURE live tests X-Git-Tag: 0.7~8^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=093616c6e6418e011d51b604c5ae46f27dafef87;p=imapclient.git Working BODY and BODYSTRUCTURE live tests --- diff --git a/livetest.py b/livetest.py index 8f43e9b..a841032 100755 --- a/livetest.py +++ b/livetest.py @@ -8,6 +8,7 @@ import sys from datetime import datetime from optparse import OptionParser +from pprint import pformat import imapclient @@ -350,6 +351,43 @@ def test_partial_fetch(client): assert len(body) == 25 assert body.startswith('om: Bob Smith') +def test_BODYSTRUCTURE(client): + clear_folder(client, 'INBOX') + client.select_folder('INBOX') + client.append('INBOX', SIMPLE_MESSAGE) + client.append('INBOX', MULTIPART_MESSAGE) + msgs = client.search() + + fetched = client.fetch(msgs, ['BODY', 'BODYSTRUCTURE']) + + # The expected test data is the same for BODY and BODYSTRUCTURE + # since we can't predicate what the server we're testing against + # will return. + + expected = ('text', 'plain', ('charset', 'us-ascii'), None, None, '7bit', 5, 1) + check_BODYSTRUCTURE(expected, fetched[msgs[0]]['BODY']) + check_BODYSTRUCTURE(expected, fetched[msgs[0]]['BODYSTRUCTURE']) + + expected = ([('text', 'html', ('charset', 'us-ascii'), None, None, 'quoted-printable', 55, 3), + ('text', 'plain', ('charset', 'us-ascii'), None, None, '7bit', 26, 1), + ], + 'mixed', + ('boundary', '===============1534046211==')) + check_BODYSTRUCTURE(expected, fetched[msgs[1]]['BODY']) + check_BODYSTRUCTURE(expected, fetched[msgs[1]]['BODYSTRUCTURE']) + + +def check_BODYSTRUCTURE(expected, actual): + # BODYSTRUCTURE lengths can various according to the server so + # compare up until what is returned + for e, a in zip(expected, actual): + if isinstance(e, list) and isinstance(a, list): + for e2, a2, in zip(e, a): + check_BODYSTRUCTURE(e2, a2) + else: + assert a == e, "%r != %r\ngot = %s\nexpected = %s" \ + % (a, e, pformat(actual), pformat(expected)) + def assert_raises(exception_class, func, *args, **kwargs): try: @@ -377,6 +415,7 @@ def runtests(client): test_search(client) test_fetch(client) test_partial_fetch(client) + test_BODYSTRUCTURE(client) test_copy(client)