Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
plone.portlet.collection.tests.test_portlet_collection.TestCollectionQuery Class Reference
Inheritance diagram for plone.portlet.collection.tests.test_portlet_collection.TestCollectionQuery:
Inheritance graph
[legend]
Collaboration diagram for plone.portlet.collection.tests.test_portlet_collection.TestCollectionQuery:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def renderer
def testSimpleQuery
def testRandomQuery

Public Attributes

 collection

Private Member Functions

def _createType

Detailed Description

Definition at line 89 of file test_portlet_collection.py.


Member Function Documentation

def plone.portlet.collection.tests.test_portlet_collection.TestCollectionQuery._createType (   self,
  context,
  portal_type,
  id,
  kwargs 
) [private]
Helper method to create a new type

Definition at line 96 of file test_portlet_collection.py.

00096 
00097     def _createType(self, context, portal_type, id, **kwargs):
00098         """Helper method to create a new type
00099         """
00100         ttool = getToolByName(context, 'portal_types')
00101         cat = self.portal.portal_catalog
00102 
00103         fti = ttool.getTypeInfo(portal_type)
00104         fti.constructInstance(context, id, **kwargs)
00105         obj = getattr(context.aq_inner.aq_explicit, id)
00106         cat.indexObject(obj)
00107         return obj

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file test_portlet_collection.py.

00091 
00092     def afterSetUp(self):
00093         self.setRoles(('Manager',))
00094         #make a collection
00095         self.collection = self._createType(self.folder, 'Topic', 'collection')

Here is the call graph for this function:

def plone.portlet.collection.tests.test_portlet_collection.TestCollectionQuery.renderer (   self,
  context = None,
  request = None,
  view = None,
  manager = None,
  assignment = None 
)

Definition at line 108 of file test_portlet_collection.py.

00108 
00109     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00110         context = context or self.folder
00111         request = request or self.folder.REQUEST
00112         view = view or self.folder.restrictedTraverse('@@plone')
00113         manager = manager or getUtility(IPortletManager, name='plone.leftcolumn', context=self.portal)
00114         assignment = assignment
00115         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 139 of file test_portlet_collection.py.

00139 
00140     def testRandomQuery(self):
00141         # we're being perhaps a bit too clever in random mode with the internals of the
00142         # LazyMap returned by the collection query, so let's try a bunch of scenarios
00143         # to make sure they work
00144         
00145         # set up our portlet renderer
00146         mapping = PortletAssignmentMapping()
00147         request = self.folder.REQUEST
00148         mapping['foo'] = collection.Assignment(header=u"title",
00149                                                random=True,
00150                                                target_collection='/Members/test_user_1_/collection')
00151         collectionrenderer = self.renderer(context=None, request=None, view=None, manager=None, assignment=mapping['foo'])
00152 
00153         # add some folders
00154         for i in range(6):
00155             self.folder.invokeFactory('Folder', 'folder_%s'%i)
00156             getattr(self.folder, 'folder_%s'%i).reindexObject()
00157 
00158         # collection with no criteria -- should return empty list, without error
00159         self.assertEqual(len(collectionrenderer.results()), 0)
00160 
00161         # let's make sure the results aren't being memoized
00162         old_func = self.folder.collection.queryCatalog
00163         global collection_was_called
00164         collection_was_called = False
00165         def mark_collection_called(**kw):
00166             global collection_was_called
00167             collection_was_called = True
00168         self.folder.collection.queryCatalog = mark_collection_called
00169         collectionrenderer.results()
00170         self.folder.collection.queryCatalog = old_func
00171         self.failUnless(collection_was_called)
00172         
00173         # collection with simple criterion -- should return 1 (random) folder
00174         crit = self.folder.collection.addCriterion('portal_type', 'ATSimpleStringCriterion')
00175         crit.setValue('Folder')
00176         self.assertEqual(len(collectionrenderer.results()), 1)
00177         
00178         # collection with multiple criteria -- should behave similarly
00179         crit = self.folder.collection.addCriterion('Creator', 'ATSimpleStringCriterion')
00180         crit.setValue('test_user_1_')
00181         collectionrenderer.results()
00182         
00183         # collection with sorting -- should behave similarly (sort is ignored internally)
00184         self.folder.collection.setSortCriterion('modified', False)
00185         self.assertEqual(len(collectionrenderer.results()), 1)
00186         
00187         # same criteria, now with limit set to 2 -- should return 2 (random) folders
00188         collectionrenderer.data.limit = 2
00189         self.assertEqual(len(collectionrenderer.results()), 2)
00190         
00191         # make sure there's no error if the limit is greater than the # of results found
00192         collectionrenderer.data.limit = 10
00193         self.failUnless(len(collectionrenderer.results()) >= 6)
00194         
        

Here is the call graph for this function:

Definition at line 116 of file test_portlet_collection.py.

00116 
00117     def testSimpleQuery(self):
00118         # set up our collection to search for Folders
00119         crit = self.folder.collection.addCriterion('portal_type', 'ATSimpleStringCriterion')
00120         crit.setValue('Folder')
00121 
00122         # add a few folders
00123         for i in range(6):
00124             self.folder.invokeFactory('Folder', 'folder_%s'%i)
00125             getattr(self.folder, 'folder_%s'%i).reindexObject()
00126 
00127         # the folders are returned by the topic
00128         collection_num_items = len(self.folder.collection.queryCatalog())
00129         # We better have some folders
00130         self.failUnless(collection_num_items >= 6)
00131 
00132         mapping = PortletAssignmentMapping()
00133         request = self.folder.REQUEST
00134         mapping['foo'] = collection.Assignment(header=u"title", target_collection='/Members/test_user_1_/collection')
00135         collectionrenderer = self.renderer(context=None, request=None, view=None, manager=None, assignment=mapping['foo'])
00136 
00137         # we want the portlet to return us the same results as the collection
00138         self.assertEquals(collection_num_items, len(collectionrenderer.results()))
        

Here is the call graph for this function:


Member Data Documentation

Definition at line 94 of file test_portlet_collection.py.


The documentation for this class was generated from the following file: