Back to index

plone3  3.1.7
test_NewsItem.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for NewsItem module.
00014 
00015 $Id: test_NewsItem.py 68344 2006-05-29 14:19:25Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from Products.CMFCore.testing import ConformsToContent
00022 from Products.CMFCore.tests.base.content import BASIC_HTML
00023 from Products.CMFCore.tests.base.content import BASIC_STRUCTUREDTEXT
00024 from Products.CMFCore.tests.base.content import DOCTYPE
00025 from Products.CMFCore.tests.base.content import ENTITY_IN_TITLE
00026 from Products.CMFCore.tests.base.testcase import RequestTest
00027 
00028 
00029 class NewsItemTests(ConformsToContent, unittest.TestCase):
00030 
00031     def _getTargetClass(self):
00032         from Products.CMFDefault.NewsItem import NewsItem
00033 
00034         return NewsItem
00035 
00036     def _makeOne(self, *args, **kw):
00037         return self._getTargetClass()(*args, **kw)
00038 
00039     def test_z3interfaces(self):
00040         from zope.interface.verify import verifyClass
00041         from Products.CMFDefault.interfaces import IDocument
00042         from Products.CMFDefault.interfaces import IMutableDocument
00043         from Products.CMFDefault.interfaces import IMutableNewsItem
00044         from Products.CMFDefault.interfaces import INewsItem
00045 
00046         verifyClass(IDocument, self._getTargetClass())
00047         # XXX: different signature
00048         # verifyClass(IMutableDocument, self._getTargetClass())
00049         verifyClass(IMutableNewsItem, self._getTargetClass())
00050         verifyClass(INewsItem, self._getTargetClass())
00051 
00052     def test_Empty_html(self):
00053         d = self._makeOne('empty', text_format='html')
00054 
00055         self.assertEqual( d.Title(), '' )
00056         self.assertEqual( d.Description(), '' )
00057         self.assertEqual( d.Format(), 'text/html' )
00058         self.assertEqual( d.text_format, 'html' )
00059         self.assertEqual( d.text, '' )
00060 
00061     def test_Empty_stx(self):
00062         d = self._makeOne('foo', text_format='structured-text')
00063 
00064         self.assertEqual( d.Title(), '' )
00065         self.assertEqual( d.Description(), '' )
00066         self.assertEqual( d.Format(), 'text/plain' )
00067         self.assertEqual( d.text_format, 'structured-text' )
00068         self.assertEqual( d.text, '' )
00069 
00070     def test_Init_with_stx( self ):
00071         d = self._makeOne('foo', text_format='structured-text',
00072                           title='Foodoc')
00073 
00074         self.assertEqual( d.Title(), 'Foodoc' )
00075         self.assertEqual( d.Description(), '' )
00076         self.assertEqual( d.Format(), 'text/plain' )
00077         self.assertEqual( d.text_format, 'structured-text' )
00078         self.assertEqual( d.text, '' )
00079 
00080     def test_default_format( self ):
00081         d = self._makeOne('foo', text='')
00082 
00083         self.assertEqual( d.Format(), 'text/plain' )
00084         self.assertEqual( d.text_format, 'structured-text' )
00085 
00086 
00087 class NewsItemPUTTests(RequestTest):
00088 
00089     def _getTargetClass(self):
00090         from Products.CMFDefault.NewsItem import NewsItem
00091 
00092         return NewsItem
00093 
00094     def _makeOne(self, *args, **kw):
00095         return self._getTargetClass()(*args, **kw)
00096 
00097     def test_Init(self):
00098         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
00099         d = self._makeOne('foo', text='')
00100         d.PUT(self.REQUEST, self.RESPONSE)
00101 
00102         self.assertEqual( d.Title(), 'My Document' )
00103         self.assertEqual( d.Description(), 'A document by me' )
00104         self.assertEqual( d.Format(), 'text/plain' )
00105         self.assertEqual( d.text_format, 'structured-text' )
00106         self.assertEqual( len(d.Contributors()), 3 )
00107         self.failUnless( d.cooked_text.find('<p>') >= 0 )
00108 
00109     def test_PUT_basic_html(self):
00110         self.REQUEST['BODY']=BASIC_HTML
00111         d = self._makeOne('foo')
00112         d.PUT(self.REQUEST, self.RESPONSE)
00113 
00114         self.assertEqual( d.Title(), 'Title in tag' )
00115         self.assertEqual( d.Description(), 'Describe me' )
00116         self.assertEqual( d.Format(), 'text/html' )
00117         self.assertEqual( d.text_format, 'html' )
00118         self.assertEqual( d.text.find('</body>'), -1 )
00119         self.assertEqual( len(d.Contributors()), 3 )
00120 
00121     def test_PUT_uppered_html(self):
00122         self.REQUEST['BODY'] = BASIC_HTML.upper()
00123         d = self._makeOne('foo')
00124         d.PUT(self.REQUEST, self.RESPONSE)
00125 
00126         self.assertEqual( d.Title(), 'TITLE IN TAG' )
00127         self.assertEqual( d.Description(), 'DESCRIBE ME' )
00128         self.assertEqual( d.Format(), 'text/html' )
00129         self.assertEqual( d.text_format, 'html' )
00130         self.assertEqual( d.text.find('</BODY'), -1 )
00131         self.assertEqual( len(d.Contributors()), 3 )
00132 
00133     def test_PUT_entity_in_title(self):
00134         self.REQUEST['BODY'] = ENTITY_IN_TITLE
00135         d = self._makeOne('foo')
00136         d.PUT(self.REQUEST, self.RESPONSE)
00137 
00138         self.assertEqual( d.Title(), '&Auuml;rger' )
00139 
00140     def test_PUT_html_with_doctype(self):
00141         self.REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
00142         d = self._makeOne('foo')
00143         d.PUT(self.REQUEST, self.RESPONSE)
00144 
00145         self.assertEqual( d.Description(), 'Describe me' )
00146 
00147     def test_PUT_html_without_newlines(self):
00148         self.REQUEST['BODY'] = ''.join(BASIC_HTML.split('\n'))
00149         d = self._makeOne('foo')
00150         d.PUT(self.REQUEST, self.RESPONSE)
00151 
00152         self.assertEqual( d.Title(), 'Title in tag' )
00153         self.assertEqual( d.Description(), 'Describe me' )
00154         self.assertEqual( d.Format(), 'text/html' )
00155         self.assertEqual( d.text_format, 'html' )
00156         self.assertEqual( d.text.find('</body>'), -1 )
00157         self.assertEqual( len(d.Contributors()), 3 )
00158 
00159     def test_PUT_structured_text(self):
00160         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
00161         d = self._makeOne('foo')
00162         d.PUT( self.REQUEST, self.RESPONSE )
00163 
00164         self.assertEqual( d.Title(), 'My Document')
00165         self.assertEqual( d.Description(), 'A document by me')
00166         self.assertEqual( d.Format(), 'text/plain' )
00167         self.assertEqual( d.text_format, 'structured-text' )
00168         self.assertEqual( len(d.Contributors()), 3 )
00169         self.failUnless( d.cooked_text.find('<p>') >= 0 )
00170 
00171 
00172 def test_suite():
00173     return unittest.TestSuite((
00174         unittest.makeSuite(NewsItemTests),
00175         unittest.makeSuite(NewsItemPUTTests),
00176         ))
00177 
00178 if __name__ == '__main__':
00179     unittest.main(defaultTest='test_suite')