|
1 | 1 | #!/usr/bin/env python
|
| 2 | +# coding=UTF-8 |
| 3 | + |
2 | 4 |
|
3 | 5 | import sys
|
4 | 6 | import unittest
|
@@ -29,35 +31,49 @@ def parseHeader(self, name, values):
|
29 | 31 | return getattr(self.parser, name_token)(name, values)
|
30 | 32 |
|
31 | 33 | def test_content_disposition(self):
|
| 34 | + i = 0 |
32 | 35 | for (hdrs, expected_val, expected_msgs) in [
|
33 |
| - # quoted-string |
| 36 | + # 0: quoted-string |
34 | 37 | (['attachment; filename="foo.txt"'],
|
35 | 38 | ('attachment', {'filename': 'foo.txt'}),
|
36 | 39 | []
|
37 | 40 | ),
|
38 |
| - # token |
| 41 | + # 1: token |
39 | 42 | (['attachment; filename=foo.txt'],
|
40 | 43 | ('attachment', {'filename': 'foo.txt'}),
|
41 | 44 | []
|
42 | 45 | ),
|
43 |
| - # inline |
| 46 | + # 2: inline |
44 | 47 | (['inline; filename=foo.txt'],
|
45 | 48 | ('inline', {'filename': 'foo.txt'}),
|
46 | 49 | []
|
47 | 50 | ),
|
48 |
| - # token |
| 51 | + # 3: token |
49 | 52 | (['attachment; filename=foo.txt, inline; filename=bar.txt'],
|
50 | 53 | ('inline', {'filename': 'bar.txt'}),
|
51 | 54 | [rs.SINGLE_HEADER_REPEAT]
|
52 | 55 | ),
|
| 56 | + # 4: filename* |
| 57 | + (["attachment; filename=foo.txt; filename*=UTF-8''a%cc%88.txt"], |
| 58 | + ('attachment', { |
| 59 | + 'filename': 'foo.txt', |
| 60 | + 'filename*': u'a\u0308.txt' |
| 61 | + }), |
| 62 | + [] |
| 63 | + ), |
53 | 64 | ]:
|
| 65 | + self.red.__init__() |
54 | 66 | val = self.parseHeader('Content-Disposition', hdrs)
|
55 |
| - self.assertEqual(expected_val, val) |
| 67 | + self.assertEqual(expected_val, val, |
| 68 | + "[%s] %s != %s" % (i, str(expected_val), str(val))) |
56 | 69 | diff = set(
|
57 | 70 | [n.__name__ for n in expected_msgs]).symmetric_difference(
|
58 | 71 | set(self.red.msg_classes)
|
59 | 72 | )
|
60 |
| - self.assertEqual(len(diff), 0, diff) |
| 73 | + self.assertEqual(len(diff), 0, |
| 74 | + "[%s] Mismatched messages: %s" % (i, diff) |
| 75 | + ) |
| 76 | + i += 1 |
61 | 77 |
|
62 | 78 |
|
63 | 79 | if __name__ == "__main__":
|
|
0 commit comments