Back to index

plone3  3.1.7
test_default_mimetypes.py
Go to the documentation of this file.
00001 # test initialisation and setup
00002 
00003 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00004 from unittest import TestSuite, makeSuite
00005 
00006 class TestDefaultMimeTypes(ATSiteTestCase):
00007 
00008     def test_ATDocumentDefaultType(self):
00009         self.loginAsPortalOwner()
00010         # we create a new document: 
00011         self.portal.invokeFactory('Document', id='testdoc', title='TestDocument')
00012         obj = self.portal.testdoc
00013         # its text field should have the site wide default 'text/html'
00014         textfield = obj.getField('text')
00015         self.assertEqual(textfield.getContentType(obj), 'text/html')
00016         # but not the description field:
00017         descriptionfield = obj.getField('description')
00018         self.assertEqual(descriptionfield.getContentType(obj), 'text/plain')
00019         
00020         # then we change the sitewide default: 
00021         from Products.Archetypes.mimetype_utils import setDefaultContentType
00022         setDefaultContentType(self.portal, "text/x-web-markdown")
00023         self.assertEqual(textfield.getContentType(obj), 'text/html')
00024         # this should only affect new objects:
00025         self.failIf(textfield.getContentType(obj) == 'text/x-web-markdown')
00026         self.portal.invokeFactory('Document', id='testdoc2', title='TestDocument with new default')
00027         second_object = self.portal.testdoc2
00028         second_field = second_object.getField('text')
00029         self.failUnless(second_field.getContentType(second_object) == 'text/x-web-markdown')
00030 
00031 def test_suite():
00032     suite = TestSuite()
00033     suite.addTest(makeSuite(TestDefaultMimeTypes))
00034     return suite
00035