comparison test/test_multipart.py @ 5306:91354bf0b683

Codecov showed text/html followed by text/plain not tested. Fixed bug discovered. The html part was double attached. Removed an unneeded attachment call. Added some more test cases. Reworked test code to make selecting html filter tool easier.
author John Rouillard <rouilj@ieee.org>
date Fri, 13 Oct 2017 22:56:42 -0400
parents e20f472fde7d
children 5b4931cfc182
comparison
equal deleted inserted replaced
5305:e20f472fde7d 5306:91354bf0b683
158 158
159 # end 159 # end
160 p = m.getpart() 160 p = m.getpart()
161 self.assert_(p is None) 161 self.assert_(p is None)
162 162
163 def TestExtraction(self, spec, expected): 163 def TestExtraction(self, spec, expected, convert_html_with=False):
164 from roundup.dehtml import dehtml 164 if convert_html_with:
165 from roundup.dehtml import dehtml
166 html2text=dehtml(convert_html_with).html2text
167 else:
168 html2text=None
165 169
166 self.assertEqual(ExampleMessage(spec).extract_content( 170 self.assertEqual(ExampleMessage(spec).extract_content(
167 html2text=dehtml('dhtml').html2text), expected) 171 html2text=html2text), expected)
168 172
169 def testTextPlain(self): 173 def testTextPlain(self):
170 self.TestExtraction('text/plain', ('foo\n', [], False)) 174 self.TestExtraction('text/plain', ('foo\n', [], False))
171 175
172 def testAttachedTextPlain(self): 176 def testAttachedTextPlain(self):
184 application/pdf""", 188 application/pdf""",
185 ('foo\n', 189 ('foo\n',
186 [('foo.pdf', 'application/pdf', 'foo\n')], False)) 190 [('foo.pdf', 'application/pdf', 'foo\n')], False))
187 191
188 def testMultipartMixedHtml(self): 192 def testMultipartMixedHtml(self):
193 # test with html conversion enabled
189 self.TestExtraction(""" 194 self.TestExtraction("""
190 multipart/mixed 195 multipart/mixed
191 text/html 196 text/html
192 application/pdf""", 197 application/pdf""",
193 ('bar\n', 198 ('bar\n',
194 [('bar.html', 'text/html', 199 [('bar.html', 'text/html',
195 '<html><body>bar</body></html>\n'), 200 '<html><body>bar</body></html>\n'),
196 ('foo.pdf', 'application/pdf', 'foo\n')], False)) 201 ('foo.pdf', 'application/pdf', 'foo\n')], False),
202 convert_html_with='dehtml')
203
204 # test with html conversion disabled
205 self.TestExtraction("""
206 multipart/mixed
207 text/html
208 application/pdf""",
209 (None,
210 [('bar.html', 'text/html',
211 '<html><body>bar</body></html>\n'),
212 ('foo.pdf', 'application/pdf', 'foo\n')], False),
213 convert_html_with=False)
197 214
198 def testMultipartAlternative(self): 215 def testMultipartAlternative(self):
199 self.TestExtraction(""" 216 self.TestExtraction("""
200 multipart/alternative 217 multipart/alternative
201 text/plain 218 text/plain
208 text/html 225 text/html
209 application/pdf""", 226 application/pdf""",
210 ('bar\n', 227 ('bar\n',
211 [('bar.html', 'text/html', 228 [('bar.html', 'text/html',
212 '<html><body>bar</body></html>\n'), 229 '<html><body>bar</body></html>\n'),
213 ('foo.pdf', 'application/pdf', 'foo\n')], False)) 230 ('foo.pdf', 'application/pdf', 'foo\n')], False),
231 convert_html_with='dehtml')
232
233 self.TestExtraction("""
234 multipart/alternative
235 text/html
236 application/pdf""",
237 (None,
238 [('bar.html', 'text/html',
239 '<html><body>bar</body></html>\n'),
240 ('foo.pdf', 'application/pdf', 'foo\n')], False),
241 convert_html_with=False)
242
243 def testMultipartAlternativeHtmlText(self):
244 # text should take priority over html when html is first
245 self.TestExtraction("""
246 multipart/alternative
247 text/html
248 text/plain
249 application/pdf""",
250 ('foo\n',
251 [('bar.html', 'text/html',
252 '<html><body>bar</body></html>\n'),
253 ('foo.pdf', 'application/pdf', 'foo\n')], False),
254 convert_html_with='dehtml')
255
256 # text should take priority over html when text is first
257 self.TestExtraction("""
258 multipart/alternative
259 text/plain
260 text/html
261 application/pdf""",
262 ('foo\n',
263 [('bar.html', 'text/html',
264 '<html><body>bar</body></html>\n'),
265 ('foo.pdf', 'application/pdf', 'foo\n')], False),
266 convert_html_with='dehtml')
267
268 # text should take priority over html when text is second and
269 # html is disabled
270 self.TestExtraction("""
271 multipart/alternative
272 text/html
273 text/plain
274 application/pdf""",
275 ('foo\n',
276 [('bar.html', 'text/html',
277 '<html><body>bar</body></html>\n'),
278 ('foo.pdf', 'application/pdf', 'foo\n')], False),
279 convert_html_with=False)
280
281 # text should take priority over html when text is first and
282 # html is disabled
283 self.TestExtraction("""
284 multipart/alternative
285 text/plain
286 text/html
287 application/pdf""",
288 ('foo\n',
289 [('bar.html', 'text/html',
290 '<html><body>bar</body></html>\n'),
291 ('foo.pdf', 'application/pdf', 'foo\n')], False),
292 convert_html_with=False)
214 293
215 def testDeepMultipartAlternative(self): 294 def testDeepMultipartAlternative(self):
216 self.TestExtraction(""" 295 self.TestExtraction("""
217 multipart/mixed 296 multipart/mixed
218 multipart/alternative 297 multipart/alternative

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