Back to index

plone3  3.1.7
test_attopic.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__ = 'Alec Mitchell'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase, atctftestcase
00027 from Products.ATContentTypes.tests.utils import dcEdit
00028 
00029 import transaction
00030 from Products.CMFCore.permissions import View
00031 from Products.Archetypes.interfaces.layer import ILayerContainer
00032 from Products.Archetypes.atapi import *
00033 
00034 from Products.Archetypes.Field import BooleanField
00035 from Products.ATContentTypes.content.topic import ATTopic
00036 from Products.ATContentTypes.content.topic import ChangeTopics
00037 from Products.ATContentTypes.content.folder import ATFolder
00038 from Products.ATContentTypes.tests.utils import EmptyValidator
00039 from Products.ATContentTypes.interfaces import IATTopic
00040 from Interface.Verify import verifyObject
00041 from OFS.IOrderSupport import IOrderedContainer as IZopeOrderedContainer
00042 
00043 from Products.CMFPlone.PloneBatch import Batch
00044 
00045 # z3 imports
00046 from Products.ATContentTypes.interface import IATTopic as Z3IATTopic
00047 from zope.interface.verify import verifyObject as Z3verifyObject
00048 
00049 
00050 ACQUIRE  = True
00051 LIMIT    = False
00052 COUNT  = '150'
00053 CUSTOM   = True
00054 FIELDS   = ('start','end', 'Creator')
00055 
00056 CRITERIA_SETUP = {'Integer Criterion':      #Meta Type
00057                         ('portal_type',     #Field
00058                          '10 10',            #Value
00059                          'min:max'),        #Direction
00060                   'String Criterion':
00061                         ('SearchableText',
00062                          'portal'),
00063                   'Friendly Date Criterion':
00064                         ('start',
00065                          '10',
00066                          'within_day',       #Operation
00067                          'ahead'),          #DateRange
00068                   'List Criterion':
00069                         ('Subject',
00070                          "value1\nportal\ntest",
00071                          'OR'),             #Operator
00072                   'Sort Criterion':
00073                         ('getId',
00074                          False),            #Reversed
00075                 }
00076 
00077 CRIT_MAP = {'Integer Criterion': 'ATSimpleIntCriterion',
00078             'String Criterion': 'ATSimpleStringCriterion',
00079             'Friendly Date Criterion': 'ATFriendlyDateCriteria',
00080             'List Criterion': 'ATListCriterion',
00081             'Sort Criterion': 'ATSortCriterion'}
00082 
00083 REV_CRIT_MAP = dict([[v,k] for k,v in CRIT_MAP.items()])
00084 
00085 def editATCT(obj):
00086     dcEdit(obj)
00087     obj.setAcquireCriteria(ACQUIRE)
00088     obj.setLimitNumber(LIMIT)
00089     obj.setItemCount(COUNT)
00090     #obj.setCustomView(CUSTOM)
00091     #obj.setCustomViewFields(FIELDS)
00092     for meta in CRITERIA_SETUP.keys():
00093         AT_META = CRIT_MAP[meta]
00094         CRIT_FIELD = CRITERIA_SETUP[meta][0]
00095         obj.addCriterion(CRIT_FIELD, AT_META)
00096     for crit in obj.listCriteria():
00097         CRIT_TYPE = crit.meta_type
00098         OLD_CRIT_TYPE = REV_CRIT_MAP[CRIT_TYPE]
00099         params = CRITERIA_SETUP[OLD_CRIT_TYPE][1:]
00100         if CRIT_TYPE not in ['ATSortCriterion','ATSimpleIntCriterion']:
00101             crit.setValue(params[0])
00102         if CRIT_TYPE == 'ATFriendlyDateCriteria':
00103             crit.setOperation(params[1])
00104             DATE_RANGE = (params[2] == 'ahead' and '+') or '-'
00105             crit.setDateRange(DATE_RANGE)
00106         if CRIT_TYPE == 'ATListCriterion':
00107             crit.setOperator(params[1])
00108         if CRIT_TYPE == 'ATSimpleIntCriterion':
00109             value = params[0].split(' ')
00110             crit.setValue(value[0])
00111             if len(value) > 1:
00112                 crit.setValue2(value[1])
00113             crit.setDirection(params[1])
00114         if CRIT_TYPE == 'ATSortCriterion':
00115             crit.setReversed(params[0])
00116 
00117 def convert_old_catalog_usage(criteria_items):
00118     """Convert old style query parameters into records"""
00119     if len(criteria_items) > 1:
00120         field = criteria_items[0][0]
00121         query_val = criteria_items[0][1]
00122         extra_param = criteria_items[1][1]
00123         if '_usage' in criteria_items[1][0]:
00124             usage = extra_param.split(':')
00125             extra_type = usage[0].strip()
00126             extra_param = ':'.join(usage[1:]).strip()
00127         else:
00128             extra_type = criteria_items[1][0].replace('%s_'%field,'')
00129         criteria_items = [(field, {'query': query_val, extra_type: extra_param})]
00130     return tuple(criteria_items)
00131 
00132 def convert_old_catalog_query(query):
00133     """Convert old style query to new record based query"""
00134     for k,v in query.items():
00135         q_field = q_type = q_param = None
00136         if '_usage' in k:
00137             q_field = k.replace('_usage','')
00138             usage = v.split(':')
00139             q_type = usage[0].strip()
00140             q_param = ':'.join(usage[1:]).strip()
00141         elif '_operator' in k:
00142             q_field = k.replace('_operator','')
00143             q_type = 'operator'
00144             q_param = v
00145         if q_field:
00146             new_val = query[q_field]
00147             if not isinstance(v, dict):
00148                 new_val = { 'query' : new_val }
00149             new_val[q_type] = q_param
00150             query[q_field] = new_val
00151             del query[k]
00152     return query
00153 
00154 tests = []
00155 
00156 class TestSiteATTopic(atcttestcase.ATCTTypeTestCase):
00157 
00158     klass = ATTopic
00159     portal_type = 'Topic'
00160     title = 'Collection'
00161     meta_type = 'ATTopic'
00162     icon = 'topic_icon.gif'
00163 
00164     def afterSetUp(self):
00165         self.setRoles(['Manager', 'Member'])
00166         self._ATCT = self._createType(self.folder, self.portal_type, 'ATCT')
00167         self.setRoles(['Member'])
00168 
00169     def test_implementsATTopic(self):
00170         iface = IATTopic
00171         self.failUnless(iface.isImplementedBy(self._ATCT))
00172         self.failUnless(verifyObject(iface, self._ATCT))
00173 
00174     def test_Z3implementsATTopic(self):
00175         iface = Z3IATTopic
00176         self.failUnless(Z3verifyObject(iface, self._ATCT))
00177 
00178     def test_isNotOrdered(self):
00179         iface = IZopeOrderedContainer
00180         self.failIf(iface.isImplementedBy(self._ATCT))
00181         self.failIf(iface.isImplementedByInstancesOf(self.klass))
00182 
00183     def test_Empty( self ):
00184         topic = self._ATCT
00185 
00186         query = topic.buildQuery()
00187         self.assertEquals( query, None )
00188 
00189     def test_canContainSubtopics(self):
00190         ttool = self.portal.portal_types
00191         fti = ttool.getTypeInfo(self.portal_type)
00192         self.failUnless(self.portal_type in fti.allowed_content_types,
00193                         'Topics should be allowed to contain topics')
00194 
00195     def test_Simple( self ):
00196         topic = self._ATCT
00197 
00198         topic.addCriterion( 'foo', 'ATSimpleStringCriterion' )
00199         self.failUnless('crit__foo_ATSimpleStringCriterion' in
00200             topic.objectIds(), topic.objectIds())
00201         topic.getCriterion( 'foo_ATSimpleStringCriterion' ).setValue( 'bar' )
00202 
00203         query = topic.buildQuery()
00204         self.assertEquals( len(query), 1 )
00205         self.assertEquals( query['foo'], 'bar' )
00206 
00207         topic.addCriterion( 'baz', 'ATSimpleIntCriterion' )
00208         topic.getCriterion( 'baz_ATSimpleIntCriterion' ).setValue( '43' )
00209 
00210         query = topic.buildQuery()
00211         self.assertEquals( len( query ), 2 )
00212         self.assertEquals( query[ 'foo' ], 'bar' )
00213         self.assertEquals( query[ 'baz' ], {'query': 43} )
00214 
00215     def test_nested( self ):
00216         topic = self._ATCT
00217 
00218         topic.addCriterion( 'foo', 'ATSimpleStringCriterion' )
00219         self.failUnless('crit__foo_ATSimpleStringCriterion' in
00220             topic.objectIds(), topic.objectIds())
00221         topic.getCriterion( 'foo_ATSimpleStringCriterion' ).setValue( 'bar' )
00222 
00223         self.setRoles(['Manager', 'Member'])
00224         topic.addSubtopic( 'qux' )
00225         self.setRoles(['Member'])
00226         subtopic = topic.qux
00227 
00228         subtopic.setAcquireCriteria(True)
00229 
00230         #Ensure an empty subtopic uses it's parents' queries
00231         self.failUnlessEqual(subtopic.buildQuery(), topic.buildQuery())
00232 
00233         subtopic.addCriterion( 'baz', 'ATSimpleStringCriterion' )
00234         self.failUnless('crit__baz_ATSimpleStringCriterion' in
00235             subtopic.objectIds(), subtopic.objectIds())
00236         subtopic.getCriterion( 'baz_ATSimpleStringCriterion' ).setValue( 'bam' )
00237 
00238         query = subtopic.buildQuery()
00239         self.assertEquals( len( query ), 2 )
00240         self.assertEquals( query['foo'], 'bar' )
00241         self.assertEquals( query['baz'], 'bam' )
00242 
00243         subtopic.setAcquireCriteria(False)
00244         query = subtopic.buildQuery()
00245         self.assertEquals( len( query ), 1 )
00246         self.assertEquals( query['baz'], 'bam' )
00247 
00248     def test_edit(self):
00249         new = self._ATCT
00250         editATCT(new)
00251 
00252     def test_hasSubTopics(self):
00253         #Ensure that has subtopics returns True if there are subtopics,
00254         #    false otherwise
00255         topic = self._ATCT
00256         self.failUnlessEqual(topic.hasSubtopics(), False)
00257         self.setRoles(['Manager', 'Member'])
00258         topic.invokeFactory('Topic', 'subtopic')
00259         self.setRoles(['Member'])
00260         self.failUnlessEqual(topic.hasSubtopics(), True)
00261 
00262     def test_queryCatalogBatching(self):
00263         # Ensure that has we return a proper batch if requested
00264         topic = self._ATCT
00265         self.failUnless(isinstance(topic.queryCatalog(batch=True),Batch))
00266         self.failIf(isinstance(topic.queryCatalog(),Batch))
00267         # try it with some content now
00268         crit = topic.addCriterion('portal_type', 'ATSimpleStringCriterion')
00269         crit.setValue('Folder')
00270         self.failUnless(isinstance(topic.queryCatalog(batch=True),Batch))
00271         self.failIf(isinstance(topic.queryCatalog(),Batch))
00272 
00273     def test_queryCatalogBatchingWithLimit(self):
00274         # Ensure that the number of results is the same with or without a
00275         # limit
00276         topic = self._ATCT
00277         crit = topic.addCriterion('portal_type', 'ATSimpleStringCriterion')
00278         crit.setValue('Folder')
00279         # set a sort criterion because sort_limit affects result batching.
00280         topic.setSortCriterion('created', False)
00281         # add a few folders
00282         for i in range(6):
00283             self.folder.invokeFactory('Folder', 'folder_%s'%i)
00284             getattr(self.folder, 'folder_%s'%i).reindexObject()
00285         num_items = len(topic.queryCatalog())
00286         # We better have some folders
00287         self.failUnless(num_items >= 6)
00288         self.assertEqual(topic.queryCatalog(batch=True).sequence_length, num_items)
00289         # Set some limits
00290         topic.setLimitNumber(True)
00291         topic.setItemCount(2)
00292         self.assertEqual(topic.queryCatalog(batch=True).sequence_length, num_items)
00293 
00294     def test_queryCatalogBrains(self):
00295         #Ensure that we feturn full objects when requested
00296         topic = self._ATCT
00297         crit = topic.addCriterion('portal_type', 'ATSimpleStringCriterion')
00298         crit.setValue('Folder')
00299         self.failUnless(isinstance(topic.queryCatalog(full_objects=True)[0], ATFolder))
00300         self.failIf(isinstance(topic.queryCatalog()[0], ATFolder))
00301 
00302     def test_queryCatalogLimitChangesBatchSize(self):
00303         #Ensure that a set limit overrides batch size
00304         topic = self._ATCT
00305         topic.setLimitNumber(True)
00306         topic.setItemCount(10)
00307         crit = topic.addCriterion('portal_type', 'ATSimpleStringCriterion')
00308         crit.setValue('Folder')
00309         # Add a bunch of folders.
00310         for i in range(1, 20):
00311             self.folder.invokeFactory('Folder', str(i))
00312         self.failUnless(isinstance(topic.queryCatalog(batch=True),Batch))
00313         # Check the batch length
00314         self.assertEqual(len(topic.queryCatalog(batch=True)), 10)
00315 
00316     def test_queryCatalogBSizeChangesBatchSize(self):
00317         #Ensure that a set limit overrides batch size
00318         topic = self._ATCT
00319         crit = topic.addCriterion('portal_type', 'ATSimpleStringCriterion')
00320         crit.setValue('Folder')
00321         # Add a bunch of folders.
00322         for i in range(1, 20):
00323             self.folder.invokeFactory('Folder', str(i))
00324         self.failUnless(isinstance(topic.queryCatalog(batch=True, b_size=5),Batch))
00325         # Check the batch length
00326         self.assertEqual(len(topic.queryCatalog(batch=True, b_size=5)), 5)
00327 
00328     def test_get_size(self):
00329         atct = self._ATCT
00330         self.failUnlessEqual(atct.get_size(), 1)
00331 
00332     def test_syndication_enabled_by_default(self):
00333         syn = self.portal.portal_syndication
00334         self.failUnless(syn.isSyndicationAllowed(self._ATCT))
00335 
00336     def test_schema_marshall(self):
00337         pass
00338 
00339     def test_sort_criterion_does_not_affect_available_fields(self):
00340         topic = self._ATCT
00341         # set a sort criterion
00342         topic.setSortCriterion('created', False)
00343         # It should still be available for other criteria
00344         self.failUnless([i for i in topic.listAvailableFields()
00345                          if i[0] == 'created'])
00346         # Add a normal criteria for the same field
00347         crit = topic.addCriterion('created', 'ATFriendlyDateCriteria')
00348         # It should no longer be available
00349         self.failIf([i for i in topic.listAvailableFields()
00350                      if i[0] == 'created'])
00351 
00352 
00353 tests.append(TestSiteATTopic)
00354 
00355 class TestATTopicFields(atcttestcase.ATCTFieldTestCase):
00356 
00357     def afterSetUp(self):
00358         atcttestcase.ATCTFieldTestCase.afterSetUp(self)
00359         self._dummy = self.createDummy(klass=ATTopic)
00360 
00361     def test_acquireCriteriaField(self):
00362         dummy = self._dummy
00363         field = dummy.getField('acquireCriteria')
00364         field_vocab = BooleanField._properties.get('vocabulary', ())
00365 
00366         self.failUnless(ILayerContainer.isImplementedBy(field))
00367         self.failUnless(field.required == 0, 'Value is %s' % field.required)
00368         self.failUnless(field.default == False, 'Value is %s' % str(field.default))
00369         self.failUnless(field.searchable == 0, 'Value is %s' % field.searchable)
00370         self.failUnless(field.vocabulary == field_vocab,
00371                         'Value is %s' % str(field.vocabulary))
00372         self.failUnless(field.enforceVocabulary == 0,
00373                         'Value is %s' % field.enforceVocabulary)
00374         self.failUnless(field.multiValued == 0,
00375                         'Value is %s' % field.multiValued)
00376         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00377         self.failUnless(field.accessor == 'getAcquireCriteria',
00378                         'Value is %s' % field.accessor)
00379         self.failUnless(field.mutator == 'setAcquireCriteria',
00380                         'Value is %s' % field.mutator)
00381         self.failUnless(field.read_permission == View,
00382                         'Value is %s' % field.read_permission)
00383         self.failUnless(field.write_permission == ChangeTopics,
00384                         'Value is %s' % field.write_permission)
00385         self.failUnless(field.generateMode == 'veVc',
00386                         'Value is %s' % field.generateMode)
00387         self.failUnless(field.force == '', 'Value is %s' % field.force)
00388         self.failUnless(field.type == 'boolean', 'Value is %s' % field.type)
00389         self.failUnless(isinstance(field.storage, AttributeStorage),
00390                         'Value is %s' % type(field.storage))
00391         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00392                         'Value is %s' % field.getLayerImpl('storage'))
00393         self.failUnless(field.validators == EmptyValidator,
00394                         'Value is %s' % str(field.validators))
00395         self.failUnless(isinstance(field.widget, BooleanWidget),
00396                         'Value is %s' % id(field.widget))
00397         vocab = field.Vocabulary(dummy)
00398         self.failUnless(isinstance(vocab, DisplayList),
00399                         'Value is %s' % type(vocab))
00400         self.failUnless(tuple(vocab) == tuple([x[0] for x in field_vocab]),
00401                         'Value is %s' % str(tuple(vocab)))
00402 
00403     def test_limitNumberField(self):
00404         dummy = self._dummy
00405         field = dummy.getField('limitNumber')
00406         field_vocab = BooleanField._properties.get('vocabulary', ())
00407 
00408         self.failUnless(ILayerContainer.isImplementedBy(field))
00409         self.failUnless(field.required == 0, 'Value is %s' % field.required)
00410         self.failUnless(field.default == False, 'Value is %s' % str(field.default))
00411         self.failUnless(field.searchable == 0, 'Value is %s' % field.searchable)
00412         self.failUnless(field.vocabulary == field_vocab,
00413                         'Value is %s' % str(field.vocabulary))
00414         self.failUnless(field.enforceVocabulary == 0,
00415                         'Value is %s' % field.enforceVocabulary)
00416         self.failUnless(field.multiValued == 0,
00417                         'Value is %s' % field.multiValued)
00418         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00419         self.failUnless(field.accessor == 'getLimitNumber',
00420                         'Value is %s' % field.accessor)
00421         self.failUnless(field.mutator == 'setLimitNumber',
00422                         'Value is %s' % field.mutator)
00423         self.failUnless(field.read_permission == View,
00424                         'Value is %s' % field.read_permission)
00425         self.failUnless(field.write_permission == ChangeTopics,
00426                         'Value is %s' % field.write_permission)
00427         self.failUnless(field.generateMode == 'veVc',
00428                         'Value is %s' % field.generateMode)
00429         self.failUnless(field.force == '', 'Value is %s' % field.force)
00430         self.failUnless(field.type == 'boolean', 'Value is %s' % field.type)
00431         self.failUnless(isinstance(field.storage, AttributeStorage),
00432                         'Value is %s' % type(field.storage))
00433         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00434                         'Value is %s' % field.getLayerImpl('storage'))
00435         self.failUnless(field.validators == EmptyValidator,
00436                         'Value is %s' % str(field.validators))
00437         self.failUnless(isinstance(field.widget, BooleanWidget),
00438                         'Value is %s' % id(field.widget))
00439         vocab = field.Vocabulary(dummy)
00440         self.failUnless(isinstance(vocab, DisplayList),
00441                         'Value is %s' % type(vocab))
00442         self.failUnless(tuple(vocab) == tuple([x[0] for x in field_vocab]),
00443                         'Value is %s' % str(tuple(vocab)))
00444 
00445     def test_itemCountField(self):
00446         dummy = self._dummy
00447         field = dummy.getField('itemCount')
00448 
00449         self.failUnless(ILayerContainer.isImplementedBy(field))
00450         self.failUnless(field.required == 0, 'Value is %s' % field.required)
00451         self.failUnless(field.default == 0, 'Value is %s' % str(field.default))
00452         self.failUnless(field.searchable == 0, 'Value is %s' % field.searchable)
00453         self.failUnless(field.vocabulary == (),
00454                         'Value is %s' % str(field.vocabulary))
00455         self.failUnless(field.enforceVocabulary == 0,
00456                         'Value is %s' % field.enforceVocabulary)
00457         self.failUnless(field.multiValued == 0,
00458                         'Value is %s' % field.multiValued)
00459         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00460         self.failUnless(field.accessor == 'getItemCount',
00461                         'Value is %s' % field.accessor)
00462         self.failUnless(field.mutator == 'setItemCount',
00463                         'Value is %s' % field.mutator)
00464         self.failUnless(field.read_permission == View,
00465                         'Value is %s' % field.read_permission)
00466         self.failUnless(field.write_permission == ChangeTopics,
00467                         'Value is %s' % field.write_permission)
00468         self.failUnless(field.generateMode == 'veVc',
00469                         'Value is %s' % field.generateMode)
00470         self.failUnless(field.force == '', 'Value is %s' % field.force)
00471         self.failUnless(field.type == 'integer', 'Value is %s' % field.type)
00472         self.failUnless(isinstance(field.storage, AttributeStorage),
00473                         'Value is %s' % type(field.storage))
00474         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00475                         'Value is %s' % field.getLayerImpl('storage'))
00476         self.failUnless(field.validators == EmptyValidator,
00477                         'Value is %s' % str(field.validators))
00478         self.failUnless(isinstance(field.widget, IntegerWidget),
00479                         'Value is %s' % id(field.widget))
00480         vocab = field.Vocabulary(dummy)
00481         self.failUnless(isinstance(vocab, DisplayList),
00482                         'Value is %s' % type(vocab))
00483         self.failUnless(tuple(vocab) == (), 'Value is %s' % str(tuple(vocab)))
00484 
00485     def test_customViewField(self):
00486         # XXX not in the current version
00487         return
00488         dummy = self._dummy
00489         field = dummy.getField('customView')
00490 
00491         self.failUnless(ILayerContainer.isImplementedBy(field))
00492         self.failUnless(field.required == 0, 'Value is %s' % field.required)
00493         self.failUnless(field.default == False, 'Value is %s' % str(field.default))
00494         self.failUnless(field.searchable == 0, 'Value is %s' % field.searchable)
00495         self.failUnless(field.vocabulary == (),
00496                         'Value is %s' % str(field.vocabulary))
00497         self.failUnless(field.enforceVocabulary == 0,
00498                         'Value is %s' % field.enforceVocabulary)
00499         self.failUnless(field.multiValued == 0,
00500                         'Value is %s' % field.multiValued)
00501         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00502         self.failUnless(field.accessor == 'getCustomView',
00503                         'Value is %s' % field.accessor)
00504         self.failUnless(field.mutator == 'setCustomView',
00505                         'Value is %s' % field.mutator)
00506         self.failUnless(field.read_permission == View,
00507                         'Value is %s' % field.read_permission)
00508         self.failUnless(field.write_permission == ChangeTopics,
00509                         'Value is %s' % field.write_permission)
00510         self.failUnless(field.generateMode == 'veVc',
00511                         'Value is %s' % field.generateMode)
00512         self.failUnless(field.force == '', 'Value is %s' % field.force)
00513         self.failUnless(field.type == 'boolean', 'Value is %s' % field.type)
00514         self.failUnless(isinstance(field.storage, AttributeStorage),
00515                         'Value is %s' % type(field.storage))
00516         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00517                         'Value is %s' % field.getLayerImpl('storage'))
00518         self.failUnless(field.validators == EmptyValidator,
00519                         'Value is %s' % str(field.validators))
00520         self.failUnless(isinstance(field.widget, BooleanWidget),
00521                         'Value is %s' % id(field.widget))
00522         vocab = field.Vocabulary(dummy)
00523         self.failUnless(isinstance(vocab, DisplayList),
00524                         'Value is %s' % type(vocab))
00525         self.failUnless(tuple(vocab) == (), 'Value is %s' % str(tuple(vocab)))
00526 
00527     def test_customViewFieldsField(self):
00528         # XXX not in the current version
00529         return
00530         dummy = self._dummy
00531         field = dummy.getField('customViewFields')
00532 
00533         self.failUnless(ILayerContainer.isImplementedBy(field))
00534         self.failUnless(field.required == 0, 'Value is %s' % field.required)
00535         self.failUnless(field.default == ('Title',), 'Value is %s' % str(field.default))
00536         self.failUnless(field.searchable == 0, 'Value is %s' % field.searchable)
00537         self.failUnless(field.vocabulary == 'listMetaDataFields',
00538                         'Value is %s' % str(field.vocabulary))
00539         self.failUnless(field.enforceVocabulary == True,
00540                         'Value is %s' % field.enforceVocabulary)
00541         self.failUnless(field.multiValued == 0,
00542                         'Value is %s' % field.multiValued)
00543         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00544         self.failUnless(field.accessor == 'getCustomViewFields',
00545                         'Value is %s' % field.accessor)
00546         self.failUnless(field.mutator == 'setCustomViewFields',
00547                         'Value is %s' % field.mutator)
00548         self.failUnless(field.read_permission == View,
00549                         'Value is %s' % field.read_permission)
00550         self.failUnless(field.write_permission == ChangeTopics,
00551                         'Value is %s' % field.write_permission)
00552         self.failUnless(field.generateMode == 'veVc',
00553                         'Value is %s' % field.generateMode)
00554         self.failUnless(field.force == '', 'Value is %s' % field.force)
00555         self.failUnless(field.type == 'lines', 'Value is %s' % field.type)
00556         self.failUnless(isinstance(field.storage, AttributeStorage),
00557                         'Value is %s' % type(field.storage))
00558         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00559                         'Value is %s' % field.getLayerImpl('storage'))
00560         self.failUnless(field.validators == EmptyValidator,
00561                         'Value is %s' % str(field.validators))
00562         self.failUnless(isinstance(field.widget, InAndOutWidget),
00563                         'Value is %s' % id(field.widget))
00564 
00565 tests.append(TestATTopicFields)
00566 
00567 class TestATTopicFunctional(atctftestcase.ATCTIntegrationTestCase):
00568 
00569     def afterSetUp(self):
00570         # adding topics is restricted
00571         self.setRoles(['Manager', 'Member',])
00572         atctftestcase.ATCTIntegrationTestCase.afterSetUp(self)
00573 
00574     def test_dynamic_view_without_view(self):
00575         # dynamic view magic should work
00576         response = self.publish('%s/' % self.obj_path, self.basic_auth)
00577         self.assertStatusEqual(response.getStatus(), 200) #
00578 
00579     portal_type = 'Topic'
00580     views = ('atct_topic_view', 'criterion_edit_form', 'atct_topic_subtopics')
00581 
00582 tests.append(TestATTopicFunctional)
00583 
00584 import unittest
00585 def test_suite():
00586     suite = unittest.TestSuite()
00587     for test in tests:
00588         suite.addTest(unittest.makeSuite(test))
00589     return suite