diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-04-16 13:21:49 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-04-16 13:21:49 (GMT) |
commit | e2c4cfce540b885dcce5a662b11eee3cb52bbf15 (patch) | |
tree | 8c6edd47ca0b1e92ab9ec8746806c9762dfafae9 /Lib/test/test_email/test_email.py | |
parent | 5145ed585901de0af2647b0554bebebe0ca20dda (diff) | |
parent | a2860e8b51d24807f3ef1cf17b2055fac3b4dd3c (diff) | |
download | cpython-e2c4cfce540b885dcce5a662b11eee3cb52bbf15.zip cpython-e2c4cfce540b885dcce5a662b11eee3cb52bbf15.tar.gz cpython-e2c4cfce540b885dcce5a662b11eee3cb52bbf15.tar.bz2 |
Merge: Improve message.py test coverage to 100%.
coverage.py reports 99% on branch coverage, but that appears to be
a bug or limitation in coverage.py.
Diffstat (limited to 'Lib/test/test_email/test_email.py')
-rw-r--r-- | Lib/test/test_email/test_email.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 632e0a9..d79f6f9 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -221,6 +221,10 @@ class TestMessageAPI(TestEmailBase): msg.set_payload('foo') eq(msg.get_payload(decode=True), b'foo') + def test_get_payload_n_raises_on_non_multipart(self): + msg = Message() + self.assertRaises(TypeError, msg.get_payload, 1) + def test_decoded_generator(self): eq = self.assertEqual msg = self._msgobj('msg_07.txt') @@ -376,6 +380,17 @@ class TestMessageAPI(TestEmailBase): msg.del_param('filename', 'content-disposition') self.assertEqual(msg['content-disposition'], 'attachment') + def test_del_param_on_nonexistent_header(self): + msg = Message() + msg.del_param('filename', 'content-disposition') + + def test_del_nonexistent_param(self): + msg = Message() + msg.add_header('Content-Type', 'text/plain', charset='utf-8') + existing_header = msg['Content-Type'] + msg.del_param('foobar', header='Content-Type') + self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"') + def test_set_type(self): eq = self.assertEqual msg = Message() @@ -506,6 +521,27 @@ class TestMessageAPI(TestEmailBase): self.assertEqual(msg.get_payload(decode=True), bytes(x, 'raw-unicode-escape')) + def test_broken_unicode_payload(self): + # This test improves coverage but is not a compliance test. + # The behavior in this situation is currently undefined by the API. + x = 'this is a br\xf6ken thing to do' + msg = Message() + msg['content-type'] = 'text/plain' + msg['content-transfer-encoding'] = '8bit' + msg.set_payload(x) + self.assertEqual(msg.get_payload(decode=True), + bytes(x, 'raw-unicode-escape')) + + def test_questionable_bytes_payload(self): + # This test improves coverage but is not a compliance test, + # since it involves poking inside the black box. + x = 'this is a quéstionable thing to do'.encode('utf-8') + msg = Message() + msg['content-type'] = 'text/plain; charset="utf-8"' + msg['content-transfer-encoding'] = '8bit' + msg._payload = x + self.assertEqual(msg.get_payload(decode=True), x) + # Issue 1078919 def test_ascii_add_header(self): msg = Message() @@ -546,6 +582,16 @@ class TestMessageAPI(TestEmailBase): "attachment; filename*=utf-8''Fu%C3%9Fballer%20%5Bfilename%5D.ppt", msg['Content-Disposition']) + def test_add_header_with_name_only_param(self): + msg = Message() + msg.add_header('Content-Disposition', 'inline', foo_bar=None) + self.assertEqual("inline; foo-bar", msg['Content-Disposition']) + + def test_add_header_with_no_value(self): + msg = Message() + msg.add_header('X-Status', None) + self.assertEqual('', msg['X-Status']) + # Issue 5871: reject an attempt to embed a header inside a header value # (header injection attack). def test_embeded_header_via_Header_rejected(self): @@ -4150,6 +4196,16 @@ Do you like this message? -Me """) + def test_set_param_requote(self): + msg = Message() + msg.set_param('title', 'foo') + self.assertEqual(msg['content-type'], 'text/plain; title="foo"') + msg.set_param('title', 'bar', requote=False) + self.assertEqual(msg['content-type'], 'text/plain; title=bar') + # tspecial is still quoted. + msg.set_param('title', "(bar)bell", requote=False) + self.assertEqual(msg['content-type'], 'text/plain; title="(bar)bell"') + def test_del_param(self): eq = self.ndiffAssertEqual msg = self._msgobj('msg_01.txt') |