comparison test/test_multipart.py @ 110:19686b60e410

Multipart message class has the getPart method now. Added some tests for it.
author Richard Jones <richard@users.sourceforge.net>
date Sat, 28 Jul 2001 06:43:02 +0000
parents
children 0791d13baea7
comparison
equal deleted inserted replaced
109:00b13b82adc1 110:19686b60e410
1 # $Id: test_multipart.py,v 1.1 2001-07-28 06:43:02 richard Exp $
2
3 import unittest, cStringIO
4
5 from roundup.mailgw import Message
6
7 class MultipartTestCase(unittest.TestCase):
8 def setUp(self):
9 self.fp = cStringIO.StringIO()
10 w = self.fp.write
11 w('Content-Type: multipart/mixed; boundary="foo"\r\n\r\n')
12 w('This is a multipart message. Ignore this bit.\r\n')
13 w('--foo\r\n')
14
15 w('Content-Type: text/plain\r\n\r\n')
16 w('Hello, world!\r\n')
17 w('\r\n')
18 w('Blah blah\r\n')
19 w('foo\r\n')
20 w('-foo\r\n')
21 w('--foo\r\n')
22
23 w('Content-Type: multipart/alternative; boundary="bar"\r\n\r\n')
24 w('This is a multipart message. Ignore this bit.\r\n')
25 w('--bar\r\n')
26
27 w('Content-Type: text/plain\r\n\r\n')
28 w('Hello, world!\r\n')
29 w('\r\n')
30 w('Blah blah\r\n')
31 w('--bar\r\n')
32
33 w('Content-Type: text/html\r\n\r\n')
34 w('<b>Hello, world!</b>\r\n')
35 w('--bar--\r\n')
36 w('--foo\r\n')
37
38 w('Content-Type: text/plain\r\n\r\n')
39 w('Last bit\n')
40 w('--foo--\r\n')
41 self.fp.seek(0)
42
43 def testMultipart(self):
44 m = Message(self.fp)
45 self.assert_(m is not None)
46
47 # skip the first bit
48 p = m.getPart()
49 self.assert_(p is not None)
50 self.assertEqual(p.fp.read(),
51 'This is a multipart message. Ignore this bit.\r\n')
52
53 # first text/plain
54 p = m.getPart()
55 self.assert_(p is not None)
56 self.assertEqual(p.gettype(), 'text/plain')
57 self.assertEqual(p.fp.read(),
58 'Hello, world!\r\n\r\nBlah blah\r\nfoo\r\n-foo\r\n')
59
60 # sub-multipart
61 p = m.getPart()
62 self.assert_(p is not None)
63 self.assertEqual(p.gettype(), 'multipart/alternative')
64
65 # sub-multipart text/plain
66 q = p.getPart()
67 self.assert_(q is not None)
68 q = p.getPart()
69 self.assert_(q is not None)
70 self.assertEqual(q.gettype(), 'text/plain')
71 self.assertEqual(q.fp.read(), 'Hello, world!\r\n\r\nBlah blah\r\n')
72
73 # sub-multipart text/html
74 q = p.getPart()
75 self.assert_(q is not None)
76 self.assertEqual(q.gettype(), 'text/html')
77 self.assertEqual(q.fp.read(), '<b>Hello, world!</b>\r\n')
78
79 # sub-multipart end
80 q = p.getPart()
81 self.assert_(q is None)
82
83 # final text/plain
84 p = m.getPart()
85 self.assert_(p is not None)
86 self.assertEqual(p.gettype(), 'text/plain')
87 self.assertEqual(p.fp.read(),
88 'Last bit\n')
89
90 # end
91 p = m.getPart()
92 self.assert_(p is None)
93
94 def suite():
95 return unittest.makeSuite(MultipartTestCase, 'test')
96
97
98 #
99 # $Log: not supported by cvs2svn $
100 #

Roundup Issue Tracker: http://roundup-tracker.org/