|
13 | 13 | from couchdb import multipart
|
14 | 14 |
|
15 | 15 |
|
16 |
| -class ReadMultiPartTestCase(unittest.TestCase): |
| 16 | +class ReadMultipartTestCase(unittest.TestCase): |
17 | 17 |
|
18 | 18 | def test_flat(self):
|
19 | 19 | text = '''\
|
@@ -149,10 +149,36 @@ def test_nested(self):
|
149 | 149 | self.assertEqual(num, 3)
|
150 | 150 |
|
151 | 151 |
|
| 152 | +class WriteMultipartTestCase(unittest.TestCase): |
| 153 | + |
| 154 | + def test_unicode_content(self): |
| 155 | + buf = StringIO() |
| 156 | + envelope = multipart.write_multipart(buf, boundary='==123456789==') |
| 157 | + envelope.add('text/plain', u'Iñtërnâtiônàlizætiøn') |
| 158 | + envelope.close() |
| 159 | + self.assertEqual('''Content-Type: multipart/mixed; boundary="==123456789==" |
| 160 | +
|
| 161 | +--==123456789== |
| 162 | +Content-Length: 27 |
| 163 | +Content-MD5: 5eYoIG5zsa5ps3/Gl2Kh4Q== |
| 164 | +Content-Type: text/plain;charset=utf-8 |
| 165 | +
|
| 166 | +Iñtërnâtiônàlizætiøn |
| 167 | +--==123456789==-- |
| 168 | +''', buf.getvalue().replace('\r\n', '\n')) |
| 169 | + |
| 170 | + def test_unicode_content_ascii(self): |
| 171 | + buf = StringIO() |
| 172 | + envelope = multipart.write_multipart(buf, boundary='==123456789==') |
| 173 | + self.assertRaises(UnicodeEncodeError, envelope.add, |
| 174 | + 'text/plain;charset=ascii', u'Iñtërnâtiônàlizætiøn') |
| 175 | + |
| 176 | + |
152 | 177 | def suite():
|
153 | 178 | suite = unittest.TestSuite()
|
154 | 179 | suite.addTest(doctest.DocTestSuite(multipart))
|
155 |
| - suite.addTest(unittest.makeSuite(ReadMultiPartTestCase, 'test')) |
| 180 | + suite.addTest(unittest.makeSuite(ReadMultipartTestCase, 'test')) |
| 181 | + suite.addTest(unittest.makeSuite(WriteMultipartTestCase, 'test')) |
156 | 182 | return suite
|
157 | 183 |
|
158 | 184 |
|
|
0 commit comments