[Python-checkins] python/dist/src/Lib/email/test test_email.py,1.4,1.5

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Tue, 20 Aug 2002 07:51:13 -0700


Update of /cvsroot/python/python/dist/src/Lib/email/test
In directory usw-pr-cvs1:/tmp/cvs-serv25594/email/test

Modified Files:
	test_email.py 
Log Message:
Added tests for SF patch #597593, syntactically invalid Content-Type: headers.


Index: test_email.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/test/test_email.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_email.py	20 Aug 2002 12:54:07 -0000	1.4
--- test_email.py	20 Aug 2002 14:51:10 -0000	1.5
***************
*** 429,438 ****
          msg = Message()
          msg['Content-Type'] = 'no-slash-in-this-string'
!         self.assertRaises(ValueError, msg.get_content_maintype)
  
      def test_get_content_subtype_error(self):
          msg = Message()
          msg['Content-Type'] = 'no-slash-in-this-string'
!         self.assertRaises(ValueError, msg.get_content_subtype)
  
  
--- 429,438 ----
          msg = Message()
          msg['Content-Type'] = 'no-slash-in-this-string'
!         self.assertEqual(msg.get_content_maintype(), 'text')
  
      def test_get_content_subtype_error(self):
          msg = Message()
          msg['Content-Type'] = 'no-slash-in-this-string'
!         self.assertEqual(msg.get_content_subtype(), 'plain')
  
  
***************
*** 1007,1010 ****
--- 1007,1031 ----
          finally:
              fp.close()
+ 
+     def test_invalid_content_type(self):
+         eq = self.assertEqual
+         neq = self.ndiffAssertEqual
+         msg = Message()
+         # RFC 2045, $5.2 says invalid yields text/plain
+         msg['Content-Type'] = 'text'
+         eq(msg.get_content_maintype(), 'text')
+         eq(msg.get_content_subtype(), 'plain')
+         eq(msg.get_content_type(), 'text/plain')
+         # Clear the old value and try something /really/ invalid
+         del msg['content-type']
+         msg['Content-Type'] = 'foo'
+         eq(msg.get_content_maintype(), 'text')
+         eq(msg.get_content_subtype(), 'plain')
+         eq(msg.get_content_type(), 'text/plain')
+         # Still, make sure that the message is idempotently generated
+         s = StringIO()
+         g = Generator(s)
+         g.flatten(msg)
+         neq(s.getvalue(), 'Content-Type: foo\n\n')