From: Menno Smits Date: Fri, 3 Jun 2011 15:19:08 +0000 (+0100) Subject: added BODY and BODYSTRUCTURE fetch response parser tests and removed juxtaposed tuple... X-Git-Tag: 0.8~34^2~6 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=dbc32081c556314505f56376d4f1db87ed8d1782;p=imapclient.git added BODY and BODYSTRUCTURE fetch response parser tests and removed juxtaposed tuples tests (going to handle this differently) --- diff --git a/imapclient/test/test_response_parser.py b/imapclient/test/test_response_parser.py index 77e6172..df41d26 100644 --- a/imapclient/test/test_response_parser.py +++ b/imapclient/test/test_response_parser.py @@ -51,22 +51,6 @@ class TestParseResponse(unittest.TestCase): self._test('(123 "foo" ((0 1 2) "more" NIL) 66)', (123, "foo", ((0, 1, 2), "more", None), 66)) - def test_juxtatposed_tuples(self): - # Tuples with no whitespace between them should be returned as - # a list of tuples - self._test('(12 "foo")(34 NIL 0)', - [(12, "foo"), (34, None, 0)]) - self._test('(12 "foo")(34 NIL 0)(5 66)', - [(12, "foo"), (34, None, 0), (5, 66)]) - self._test('((12 "foo")(34 NIL 0) "foo")', - ([(12, "foo"), (34, None, 0)], "foo")) - self._test('((12 "foo")(34 NIL 0)(4 55 6) "foo")', - ([(12, "foo"), (34, None, 0), (4, 55, 6)], "foo")) - self._test('((12 "foo")(34 (NIL 1 2) 0)(4 55 6) "foo")', - ([(12, "foo"), (34, (None, 1, 2), 0), (4, 55, 6)], "foo")) - self._test('(12 "foo")(34 NIL ("a" "b")("c" "d"))', - [(12, "foo"), (34, None, [('a', 'b'), ('c', 'd')])]) - def test_complex_mixed(self): self._test('((FOO "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152 23) ' '("TEXT" "PLAIN" ("CHARSET" "US-ASCII" "NAME" "cc.diff") ' @@ -149,19 +133,13 @@ class TestParseResponse(unittest.TestCase): def test_incomplete_tuple(self): self._test_parse_error('abc (1 2', 'Tuple incomplete before "\(1 2"') - def test_incomplete_juxtaposed_tuples(self): - self._test_parse_error('(1 2)(3 4', - 'Juxtaposed tuples incomplete before "\(1 2\)\(3 4"') - def test_bad_literal(self): self._test_parse_error([('{99}', 'abc')], 'Expecting literal of size 99, got 3') - def test_bad_quoting(self): self._test_parse_error('"abc next', """No closing '"'""") - def _test(self, to_parse, expected, wrap=True): if wrap: # convenience - expected value should be wrapped in another tuple @@ -271,6 +249,31 @@ class TestParseFetchResponse(unittest.TestCase): { 31710: {'BODY[HEADER.FIELDS (FROM SUBJECT)]': header_text, 'SEQ': 123}}) + def test_BODY(self): + self.check_BODYish_single_part('BODY') + self.check_BODYish_multipart('BODY') + + def test_BODYSTRUCTURE(self): + self.check_BODYish_single_part('BODYSTRUCTURE') + self.check_BODYish_multipart('BODYSTRUCTURE') + + def check_BODYish_single_part(self, respType): + resp = '123 (UID 317 %s ("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 16 1))' % respType + self.assertEquals(parse_fetch_response([resp]), + { 317: {respType: ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 16, 1), + 'SEQ': 123 } + }) + + def check_BODYish_multipart(self, respType): + resp = '123 (UID 269 %s (("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 55 3)' \ + '("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 26 1) "MIXED"))' \ + % respType + self.assertEquals(parse_fetch_response([resp]), + {269: {respType: ([('TEXT', 'HTML', ('CHARSET', 'us-ascii'), None, None, 'QUOTED-PRINTABLE', 55, 3), + ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 26, 1)], + 'MIXED'), + 'SEQ': 123} + }) def test_partial_fetch(self): body = '01234567890123456789'