Back to index

plone3  3.1.7
test_baseschema.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 
00026 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00027 
00028 # need this to initialize new BU for tests
00029 from Products.Archetypes.tests.test_classgen import Dummy
00030 
00031 from Products.Archetypes import PloneMessageFactory as _
00032 from Products.Archetypes.atapi import *
00033 from Products.Archetypes.config import PKG_NAME, LANGUAGE_DEFAULT
00034 from Products.Archetypes.interfaces.layer import ILayerContainer
00035 from Products.CMFCore import permissions
00036 from Products.Archetypes.ExtensibleMetadata import FLOOR_DATE
00037 from Products.Archetypes.ExtensibleMetadata import CEILING_DATE
00038 from Products.validation import ValidationChain
00039 
00040 from DateTime import DateTime
00041 
00042 Dummy.schema = BaseSchema
00043 
00044 EmptyValidator = ValidationChain('isEmpty')
00045 EmptyValidator.appendSufficient('isEmpty')
00046 
00047 class BaseSchemaTest(ATSiteTestCase):
00048 
00049     def afterSetUp(self):
00050         ATSiteTestCase.afterSetUp(self)
00051         registerType(Dummy, 'Archetypes')
00052         content_types, constructors, ftis = process_types(listTypes(), PKG_NAME)
00053         portal = self.portal
00054         dummy = Dummy(oid='dummy')
00055         # put dummy in context of portal
00056         dummy = dummy.__of__(portal)
00057         portal.dummy = dummy
00058 
00059         dummy.initializeArchetype()
00060         self._dummy = dummy
00061 
00062 
00063     def test_id(self):
00064         dummy = self._dummy
00065         field = dummy.getField('id')
00066 
00067         self.failUnless(ILayerContainer.isImplementedBy(field))
00068         self.failUnless(field.required == 0)
00069         self.failUnless(field.default == None)
00070         self.failUnless(field.searchable == 0)
00071         self.failUnless(field.vocabulary == ())
00072         self.failUnless(field.enforceVocabulary == 0)
00073         self.failUnless(field.multiValued == 0)
00074         self.failUnless(field.isMetadata == 0)
00075         self.failUnless(field.accessor == 'getId')
00076         self.failUnless(field.mutator == 'setId')
00077         self.failUnless(field.read_permission == permissions.View)
00078         self.failUnless(field.write_permission ==
00079                         permissions.ModifyPortalContent)
00080         self.failUnless(field.generateMode == 'veVc')
00081         self.failUnless(field.force == '')
00082         self.failUnless(field.type == 'string')
00083         self.failUnless(isinstance(field.storage, AttributeStorage))
00084         self.failUnless(field.getLayerImpl('storage') == AttributeStorage())
00085         self.failUnless(ILayerContainer.isImplementedBy(field))
00086         self.failUnless(field.validators == EmptyValidator)
00087         self.failUnless(isinstance(field.widget, IdWidget))
00088         vocab = field.Vocabulary(dummy)
00089         self.failUnless(isinstance(vocab, DisplayList))
00090         self.failUnless(tuple(vocab) == ())
00091 
00092     def test_title(self):
00093         dummy = self._dummy
00094         field = dummy.getField('title')
00095 
00096         self.failUnless(ILayerContainer.isImplementedBy(field))
00097         self.failUnless(field.required == 1)
00098         self.failUnless(field.default == '')
00099         self.failUnless(field.searchable == 1)
00100         self.failUnless(field.vocabulary == ())
00101         self.failUnless(field.enforceVocabulary == 0)
00102         self.failUnless(field.multiValued == 0)
00103         self.failUnless(field.isMetadata == 0)
00104         self.failUnless(field.accessor == 'Title')
00105         self.failUnless(field.mutator == 'setTitle')
00106         self.failUnless(field.read_permission == permissions.View)
00107         self.failUnless(field.write_permission ==
00108                         permissions.ModifyPortalContent)
00109         self.failUnless(field.generateMode == 'veVc')
00110         self.failUnless(field.force == '')
00111         self.failUnless(field.type == 'string')
00112         self.failUnless(isinstance(field.storage, AttributeStorage))
00113         self.failUnless(field.getLayerImpl('storage') == AttributeStorage())
00114         self.failUnless(field.validators == ())
00115         self.failUnless(isinstance(field.widget, StringWidget))
00116         vocab = field.Vocabulary(dummy)
00117         self.failUnless(isinstance(vocab, DisplayList))
00118         self.failUnless(tuple(vocab) == ())
00119 
00120     ### Metadata Properties
00121 
00122     def test_allowdiscussion(self):
00123         dummy = self._dummy
00124         field = dummy.getField('allowDiscussion')
00125 
00126         self.failUnless(ILayerContainer.isImplementedBy(field))
00127         self.failUnless(field.required == 0)
00128         self.failUnless(field.default == None)
00129         self.failUnless(field.searchable == 0)
00130         self.failUnless(field.multiValued == 0)
00131         self.failUnless(field.isMetadata == 1)
00132         self.failUnless(field.accessor == 'isDiscussable')
00133         self.failUnless(field.mutator == 'allowDiscussion')
00134         self.failUnless(field.edit_accessor == 'editIsDiscussable')
00135         self.failUnless(field.read_permission == permissions.View)
00136         self.failUnless(field.write_permission ==
00137                         permissions.ModifyPortalContent)
00138         self.failUnless(field.generateMode == 'mVc')
00139         self.failUnless(field.force == '')
00140         self.failUnless(field.type == 'boolean')
00141         self.failUnless(isinstance(field.storage, MetadataStorage))
00142         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00143         self.failUnless(field.validators == EmptyValidator)
00144         self.failUnless(isinstance(field.widget, BooleanWidget))
00145 
00146     def test_subject(self):
00147         dummy = self._dummy
00148         field = dummy.getField('subject')
00149 
00150         self.failUnless(ILayerContainer.isImplementedBy(field))
00151         self.failUnless(field.required == 0)
00152         self.failUnless(field.default == ())
00153         self.failUnless(field.searchable == 1)
00154         vocab = field.vocabulary
00155         self.failUnless(vocab == ())
00156         self.failUnless(field.enforceVocabulary == 0)
00157         self.failUnless(field.multiValued == 1)
00158         self.failUnless(field.isMetadata == 1)
00159         self.failUnless(field.accessor == 'Subject')
00160         self.failUnless(field.mutator == 'setSubject')
00161         self.failUnless(field.read_permission == permissions.View)
00162         self.failUnless(field.write_permission ==
00163                         permissions.ModifyPortalContent)
00164         self.failUnless(field.generateMode == 'mVc')
00165         self.failUnless(field.force == '')
00166         self.failUnless(field.type == 'lines')
00167         self.failUnless(isinstance(field.storage, MetadataStorage))
00168         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00169         self.failUnless(field.validators == EmptyValidator)
00170         self.failUnless(isinstance(field.widget, KeywordWidget))
00171         vocab = field.Vocabulary(dummy)
00172         self.failUnless(isinstance(vocab, DisplayList))
00173         self.failUnless(tuple(vocab) == ())
00174 
00175     def test_description(self):
00176         dummy = self._dummy
00177         field = dummy.getField('description')
00178 
00179         self.failUnless(ILayerContainer.isImplementedBy(field))
00180         self.failUnless(field.required == 0)
00181         self.failUnless(field.default == '')
00182         self.failUnless(field.searchable == 1)
00183         vocab = field.vocabulary
00184         self.failUnless(vocab == ())
00185         self.failUnless(field.enforceVocabulary == 0)
00186         self.failUnless(field.multiValued == 0)
00187         self.failUnless(field.isMetadata == 1)
00188         self.failUnless(field.accessor == 'Description')
00189         self.failUnless(field.mutator == 'setDescription')
00190         self.failUnless(field.read_permission == permissions.View)
00191         self.failUnless(field.write_permission ==
00192                         permissions.ModifyPortalContent)
00193         self.failUnless(field.generateMode == 'mVc')
00194         self.failUnless(field.force == '')
00195         self.failUnless(field.type == 'text')
00196         self.failUnless(isinstance(field.storage, MetadataStorage))
00197         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00198         self.failUnless(field.validators == EmptyValidator)
00199         self.failUnless(isinstance(field.widget, TextAreaWidget))
00200         vocab = field.Vocabulary(dummy)
00201         self.failUnless(isinstance(vocab, DisplayList))
00202         self.failUnless(tuple(vocab) == ())
00203 
00204     def test_contributors(self):
00205         dummy = self._dummy
00206         field = dummy.getField('contributors')
00207 
00208         self.failUnless(ILayerContainer.isImplementedBy(field))
00209         self.failUnless(field.required == 0)
00210         self.failUnless(field.default == ())
00211         self.failUnless(field.searchable == 0)
00212         vocab = field.vocabulary
00213         self.failUnless(vocab == ())
00214         self.failUnless(field.enforceVocabulary == 0)
00215         self.failUnless(field.multiValued == 0)
00216         self.failUnless(field.isMetadata == 1)
00217         self.failUnless(field.accessor == 'Contributors')
00218         self.failUnless(field.mutator == 'setContributors')
00219         self.failUnless(field.read_permission == permissions.View)
00220         self.failUnless(field.write_permission ==
00221                         permissions.ModifyPortalContent)
00222         self.failUnless(field.generateMode == 'mVc')
00223         self.failUnless(field.force == '')
00224         self.failUnless(field.type == 'lines')
00225         self.failUnless(isinstance(field.storage, MetadataStorage))
00226         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00227         self.failUnless(field.validators == EmptyValidator)
00228         self.failUnless(isinstance(field.widget, LinesWidget))
00229         vocab = field.Vocabulary(dummy)
00230         self.failUnless(isinstance(vocab, DisplayList))
00231         self.failUnless(tuple(vocab) == ())
00232 
00233     def test_effectivedate(self):
00234         dummy = self._dummy
00235         field = dummy.getField('effectiveDate')
00236 
00237         self.failUnless(ILayerContainer.isImplementedBy(field))
00238         self.failUnless(field.required == 0)
00239         self.failUnlessEqual(field.default, None)
00240         self.failUnlessEqual(dummy.effective(), FLOOR_DATE)
00241         self.failUnless(field.searchable == 0)
00242         vocab = field.vocabulary
00243         self.failUnless(vocab == ())
00244         self.failUnless(field.enforceVocabulary == 0)
00245         self.failUnless(field.multiValued == 0)
00246         self.failUnless(field.isMetadata == 1)
00247         self.failUnless(field.mutator == 'setEffectiveDate')
00248         self.failUnless(field.read_permission == permissions.View)
00249         self.failUnless(field.write_permission ==
00250                         permissions.ModifyPortalContent)
00251         self.failUnless(field.generateMode == 'mVc')
00252         self.failUnless(field.force == '')
00253         self.failUnless(field.type == 'datetime')
00254         self.failUnless(isinstance(field.storage, MetadataStorage))
00255         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00256         self.failUnless(field.validators == EmptyValidator)
00257         self.failUnless(isinstance(field.widget, CalendarWidget))
00258         vocab = field.Vocabulary(dummy)
00259         self.failUnless(isinstance(vocab, DisplayList))
00260         self.failUnless(tuple(vocab) == ())
00261 
00262     def test_expirationdate(self):
00263         dummy = self._dummy
00264         field = dummy.getField('expirationDate')
00265 
00266         self.failUnless(ILayerContainer.isImplementedBy(field))
00267         self.failUnless(field.required == 0)
00268         self.failUnlessEqual(field.default, None)
00269         self.failUnlessEqual(dummy.expires(), CEILING_DATE)
00270         self.failUnless(field.searchable == 0)
00271         vocab = field.vocabulary
00272         self.failUnless(vocab == ())
00273         self.failUnless(field.enforceVocabulary == 0)
00274         self.failUnless(field.multiValued == 0)
00275         self.failUnless(field.isMetadata == 1)
00276         self.failUnless(field.mutator == 'setExpirationDate')
00277         self.failUnless(field.read_permission == permissions.View)
00278         self.failUnless(field.write_permission ==
00279                         permissions.ModifyPortalContent)
00280         self.failUnless(field.generateMode == 'mVc')
00281         self.failUnless(field.force == '')
00282         self.failUnless(field.type == 'datetime')
00283         self.failUnless(isinstance(field.storage, MetadataStorage))
00284         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00285         self.failUnless(field.validators == EmptyValidator)
00286         self.failUnless(isinstance(field.widget, CalendarWidget))
00287         vocab = field.Vocabulary(dummy)
00288         self.failUnless(isinstance(vocab, DisplayList))
00289         self.failUnless(tuple(vocab) == ())
00290 
00291     def test_language(self):
00292         default=LANGUAGE_DEFAULT
00293         dummy = self._dummy
00294         field = dummy.getField('language')
00295 
00296         self.failUnless(ILayerContainer.isImplementedBy(field))
00297         self.failUnless(field.required == 0)
00298         self.failUnless(field.default == LANGUAGE_DEFAULT)
00299         self.failUnless(field.searchable == 0)
00300         vocab = field.vocabulary
00301         self.failUnless(vocab == 'languages')
00302         self.failUnless(field.enforceVocabulary == 0)
00303         self.failUnless(field.multiValued == 0)
00304         self.failUnless(field.isMetadata == 1)
00305         self.failUnless(field.accessor == 'Language')
00306         self.failUnless(field.mutator == 'setLanguage')
00307         self.failUnless(field.read_permission == permissions.View)
00308         self.failUnless(field.write_permission ==
00309                         permissions.ModifyPortalContent)
00310         self.failUnless(field.generateMode == 'mVc')
00311         self.failUnless(field.force == '')
00312         self.failUnless(field.type == 'string')
00313         self.failUnless(isinstance(field.storage, MetadataStorage))
00314         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00315         self.failUnless(field.validators == EmptyValidator)
00316         self.failUnless(isinstance(field.widget, LanguageWidget))
00317         vocab = field.Vocabulary(dummy)
00318         self.failUnless(isinstance(vocab, DisplayList))
00319         self.failUnless(vocab == dummy.languages())
00320 
00321     def test_rights(self):
00322         dummy = self._dummy
00323         field = dummy.getField('rights')
00324 
00325         self.failUnless(ILayerContainer.isImplementedBy(field))
00326         self.failUnless(field.required == 0)
00327         self.failUnless(field.default == '')
00328         self.failUnless(field.searchable == 0)
00329         vocab = field.vocabulary
00330         self.failUnless(vocab == ())
00331         self.failUnless(field.enforceVocabulary == 0)
00332         self.failUnless(field.multiValued == 0)
00333         self.failUnless(field.isMetadata == 1)
00334         self.failUnless(field.accessor == 'Rights')
00335         self.failUnless(field.mutator == 'setRights')
00336         self.failUnless(field.read_permission == permissions.View)
00337         self.failUnless(field.write_permission ==
00338                         permissions.ModifyPortalContent)
00339         self.failUnless(field.generateMode == 'mVc')
00340         self.failUnless(field.force == '')
00341         self.failUnless(field.type == 'text')
00342         self.failUnless(isinstance(field.storage, MetadataStorage))
00343         self.failUnless(field.getLayerImpl('storage') == MetadataStorage())
00344         self.failUnless(field.validators == EmptyValidator)
00345         self.failUnless(isinstance(field.widget, TextAreaWidget))
00346         vocab = field.Vocabulary(dummy)
00347         self.failUnless(isinstance(vocab, DisplayList))
00348         self.failUnless(tuple(vocab) == ())
00349 
00350     # metadata utility accessors (DublinCore)
00351     def test_EffectiveDate(self):
00352         dummy = self._dummy
00353         self.failUnless(dummy.EffectiveDate() == 'None')
00354         now = DateTime()
00355         dummy.setEffectiveDate(now)
00356         self.failUnless(dummy.EffectiveDate() == now.ISO())
00357 
00358     def test_ExpiresDate(self):
00359         dummy = self._dummy
00360         self.failUnless(dummy.ExpirationDate() == 'None')
00361         now = DateTime()
00362         dummy.setExpirationDate(now)
00363         self.failUnless(dummy.ExpirationDate() == now.ISO())
00364 
00365     def test_Date(self):
00366         dummy = self._dummy
00367         self.failUnless(isinstance(dummy.Date(), str))
00368         dummy.setEffectiveDate(DateTime())
00369         self.failUnless(isinstance(dummy.Date(), str))
00370 
00371     def test_contentEffective(self):
00372         dummy = self._dummy
00373         now = DateTime()
00374         then = DateTime() + 1000
00375         self.failUnless(dummy.contentEffective(now))
00376         dummy.setExpirationDate(then)
00377         self.failUnless(dummy.contentEffective(now))
00378         dummy.setEffectiveDate(now)
00379         self.failUnless(dummy.contentEffective(now))
00380         dummy.setEffectiveDate(then)
00381         self.failIf(dummy.contentEffective(now))
00382 
00383     def test_contentExpired(self):
00384         dummy = self._dummy
00385         now = DateTime()
00386         then = DateTime() + 1000
00387         self.failIf(dummy.contentExpired())
00388         dummy.setExpirationDate(then)
00389         self.failIf(dummy.contentExpired())
00390         dummy.setExpirationDate(now)
00391         self.failUnless(dummy.contentExpired())
00392 
00393 
00394 def test_suite():
00395     from unittest import TestSuite, makeSuite
00396     suite = TestSuite()
00397     suite.addTest(makeSuite(BaseSchemaTest))
00398     return suite