]> granicus.if.org Git - python/commitdiff
Fix the change made for issue 1243654.
authorR. David Murray <rdmurray@bitdance.com>
Tue, 21 Dec 2010 18:07:59 +0000 (18:07 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Tue, 21 Dec 2010 18:07:59 +0000 (18:07 +0000)
Surprisingly, it turns out there was no test that exercised this code path.

Lib/email/generator.py
Lib/email/test/test_email.py

index 510f68b4408026155771a6235e027cdb1161e257..9d33f1cb870a97b584b60b3ae77b9dd453f40caf 100644 (file)
@@ -226,7 +226,8 @@ class Generator:
             # Create a boundary that doesn't appear in any of the
             # message texts.
             alltext = self._encoded_NL.join(msgtexts)
-            msg.set_boundary(self._make_boundary(alltext))
+            boundary = self._make_boundary(alltext)
+            msg.set_boundary(boundary)
         # If there's a preamble, write it out, with a trailing CRLF
         if msg.preamble is not None:
             self.write(msg.preamble + self._NL)
index e5eece2720ce984b5eaa02d01d0b7c45bcc6ebc9..a54c1a3447a89b0e674f0eda3f688019a4794f71 100644 (file)
@@ -180,6 +180,17 @@ class TestMessageAPI(TestEmailBase):
         self.assertRaises(errors.HeaderParseError,
                           msg.set_boundary, 'BOUNDARY')
 
+    def test_make_boundary(self):
+        msg = MIMEMultipart('form-data')
+        # Note that when the boundary gets created is an implementation
+        # detail and might change.
+        self.assertEqual(msg.items()[0][1], 'multipart/form-data')
+        # Trigger creation of boundary
+        msg.as_string()
+        self.assertEqual(msg.items()[0][1][:33],
+                        'multipart/form-data; boundary="==')
+        # XXX: there ought to be tests of the uniqueness of the boundary, too.
+
     def test_message_rfc822_only(self):
         # Issue 7970: message/rfc822 not in multipart parsed by
         # HeaderParser caused an exception when flattened.