Back to index

plone3  3.1.7
test_atnewsitem.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 
00022 __author__ = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase, atctftestcase
00027 
00028 import time, transaction
00029 from Products.CMFCore.permissions import View
00030 from Products.CMFCore.permissions import ModifyPortalContent
00031 from Products.Archetypes.interfaces.layer import ILayerContainer
00032 from Products.Archetypes.atapi import *
00033 from Products.ATContentTypes.tests.utils import dcEdit
00034 
00035 from Products.ATContentTypes.content.newsitem import ATNewsItem
00036 from Products.ATContentTypes.tests.utils import NotRequiredTidyHTMLValidator
00037 from Products.ATContentTypes.interfaces import ITextContent
00038 from Products.ATContentTypes.interfaces import IImageContent
00039 from Products.ATContentTypes.interfaces import IATNewsItem
00040 from Interface.Verify import verifyObject
00041 
00042 # z3 imports
00043 from Products.ATContentTypes.interface import ITextContent as Z3ITextContent
00044 from Products.ATContentTypes.interface import IImageContent as Z3IImageContent
00045 from Products.ATContentTypes.interface import IATNewsItem as Z3IATNewsItem
00046 from zope.interface.verify import verifyObject as Z3verifyObject
00047 
00048 
00049 tests = []
00050 
00051 TEXT = "lorum ipsum"
00052 
00053 def editATCT(obj):
00054     dcEdit(obj)
00055     obj.setText(TEXT)
00056 
00057 class TestSiteATNewsItem(atcttestcase.ATCTTypeTestCase):
00058 
00059     klass = ATNewsItem
00060     portal_type = 'News Item'
00061     title = 'News Item'
00062     meta_type = 'ATNewsItem'
00063     icon = 'newsitem_icon.gif'
00064 
00065     def test_implementsTextContent(self):
00066         iface = ITextContent
00067         self.failUnless(iface.isImplementedBy(self._ATCT))
00068         self.failUnless(verifyObject(iface, self._ATCT))
00069 
00070     def test_implementsZ3TextContent(self):
00071         iface = Z3ITextContent
00072         self.failUnless(Z3verifyObject(iface, self._ATCT))
00073 
00074     def test_implementsImageContent(self):
00075         iface = IImageContent
00076         self.failUnless(iface.isImplementedBy(self._ATCT))
00077         self.failUnless(verifyObject(iface, self._ATCT))
00078 
00079     def test_implementsZ3ImageContent(self):
00080         iface = Z3IImageContent
00081         self.failUnless(Z3verifyObject(iface, self._ATCT))
00082 
00083     def test_implementsATNewsItem(self):
00084         iface = IATNewsItem
00085         self.failUnless(iface.isImplementedBy(self._ATCT))
00086         self.failUnless(verifyObject(iface, self._ATCT))
00087 
00088     def test_implementsZ3ATNewsItem(self):
00089         iface = Z3IATNewsItem
00090         self.failUnless(Z3verifyObject(iface, self._ATCT))
00091 
00092     def test_edit(self):
00093         new = self._ATCT
00094         editATCT(new)
00095 
00096     def test_get_size(self):
00097         atct = self._ATCT
00098         editATCT(atct)
00099         self.failUnlessEqual(atct.get_size(), len(TEXT))
00100 
00101 tests.append(TestSiteATNewsItem)
00102 
00103 class TestATNewsItemFields(atcttestcase.ATCTFieldTestCase):
00104 
00105     def afterSetUp(self):
00106         atcttestcase.ATCTFieldTestCase.afterSetUp(self)
00107         self._dummy = self.createDummy(klass=ATNewsItem)
00108 
00109     def test_textField(self):
00110         dummy = self._dummy
00111         field = dummy.getField('text')
00112 
00113         self.failUnless(ILayerContainer.isImplementedBy(field))
00114         self.failUnless(field.required == 0, 'Value is %s' % field.required)
00115         self.failUnless(field.default == '', 'Value is %s' % str(field.default))
00116         self.failUnless(field.searchable == 1, 'Value is %s' % field.searchable)
00117         self.failUnless(field.vocabulary == (),
00118                         'Value is %s' % str(field.vocabulary))
00119         self.failUnless(field.enforceVocabulary == 0,
00120                         'Value is %s' % field.enforceVocabulary)
00121         self.failUnless(field.multiValued == 0,
00122                         'Value is %s' % field.multiValued)
00123         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00124         self.failUnless(field.accessor == 'getText',
00125                         'Value is %s' % field.accessor)
00126         self.failUnless(field.mutator == 'setText',
00127                         'Value is %s' % field.mutator)
00128         self.failUnless(field.read_permission == View,
00129                         'Value is %s' % field.read_permission)
00130         self.failUnless(field.write_permission == ModifyPortalContent,
00131                         'Value is %s' % field.write_permission)
00132         self.failUnless(field.generateMode == 'veVc',
00133                         'Value is %s' % field.generateMode)
00134         self.failUnless(field.force == '', 'Value is %s' % field.force)
00135         self.failUnless(field.type == 'text', 'Value is %s' % field.type)
00136         self.failUnless(isinstance(field.storage, AnnotationStorage),
00137                         'Value is %s' % type(field.storage))
00138         self.failUnless(field.getLayerImpl('storage') == AnnotationStorage(migrate=True),
00139                         'Value is %s' % field.getLayerImpl('storage'))
00140         self.failUnless(ILayerContainer.isImplementedBy(field))
00141         self.failUnless(field.validators == NotRequiredTidyHTMLValidator,
00142                         'Value is %s' % repr(field.validators))
00143         self.failUnless(isinstance(field.widget, RichWidget),
00144                         'Value is %s' % id(field.widget))
00145         vocab = field.Vocabulary(dummy)
00146         self.failUnless(isinstance(vocab, DisplayList),
00147                         'Value is %s' % type(vocab))
00148         self.failUnless(tuple(vocab) == (), 'Value is %s' % str(tuple(vocab)))
00149 
00150         self.failUnless(field.primary == 1, 'Value is %s' % field.primary)
00151         self.failUnless(field.default_content_type is None,
00152                         'Value is %s' % field.default_content_type)
00153         self.failUnless(field.default_output_type == 'text/x-html-safe',
00154                         'Value is %s' % field.default_output_type)
00155         self.failUnless('text/html' in field.getAllowedContentTypes(dummy))
00156 
00157 tests.append(TestATNewsItemFields)
00158 
00159 class TestATNewsItemFunctional(atctftestcase.ATCTIntegrationTestCase):
00160     
00161     portal_type = 'News Item'
00162     views = ('newsitem_view', )
00163 
00164 tests.append(TestATNewsItemFunctional)
00165 
00166 import unittest
00167 def test_suite():
00168     suite = unittest.TestSuite()
00169     for test in tests:
00170         suite.addTest(unittest.makeSuite(test))
00171     return suite