def test_sorting_criteria(self): """ """ total_objects = 5 self.create_test_objects("PressRelease", total=total_objects) assignment = osha_items.Assignment( **{ 'count': 5, 'header': 'Testing PressReleases portlet', 'portletlink': None, 'sort': 'sortable_title', 'state': ('published', ), 'subject': tuple(), 'types': ('PressRelease'), }) r = self.renderer( context=self.portal, assignment=assignment, ) objects = r._data() self.assertEquals(len(objects), total_objects) titles = [seminar.Title for seminar in objects] sorted_titles = titles sorted_titles.sort() self.assertEquals(titles, sorted_titles)
def test_categories(self): """ """ total_objects = 5 # test that subject filtering works: i = 0 for cat in ['cat1', 'cat2', 'cat3']: self.create_test_objects("PressRelease", subject=cat, start=i * total_objects, total=total_objects) i += 1 assignment = osha_items.Assignment( **{ 'count': total_objects, 'state': ('published', ), 'subject': (cat, ), 'header': 'Testing objects portlet', 'types': ('PressRelease'), }) r = self.renderer( context=self.portal, assignment=assignment, ) objects = r._data() self.assertEquals(len(objects), total_objects) for ob in objects: self.assertEquals(ob.Subject, (cat, ))
def test_count(self): """ Test with diffferent count values """ total_objects = 10 self.create_test_objects("PressRelease", total=total_objects) for count in range(0, 12): assignment = osha_items.Assignment( **{ 'count': count, 'header': 'Testing PressReleases Portlet', 'portletlink': None, 'sort': 'effective', 'state': ('published', ), 'subject': tuple(), 'types': ('PressRelease'), }) r = self.renderer( context=self.portal, assignment=assignment, ) objects = r._data() self.assertEquals(len(objects), count > total_objects and total_objects or count) if count == 0: self.assertEquals(r.available, False) else: self.assertEquals(r.available, True)
def test_portal_types(self): """ Test that only objects of a certain types is returned""" for portal_type in ['PressRelease', 'Folder', 'Document']: assignment = osha_items.Assignment( **{ 'count': 5, 'header': 'Testing PressReleases Portlet', 'portletlink': None, 'sort': 'effective', 'state': ('published', ), 'subject': tuple(), 'types': (portal_type), }) r = self.renderer( context=self.portal, assignment=assignment, ) # Create test data. total_objects = 5 self.create_test_objects(portal_type, total=total_objects) # Test that the portlet returns the correct amount of objects objects = r._data() self.assertEquals(len(objects), 5) # Test that it's actually objects being returned. for seminar in objects: self.assertEquals(seminar.portal_type, portal_type)
def test_invoke_edit_view(self): mapping = PortletAssignmentMapping() request = self.folder.REQUEST mapping['foo'] = osha_items.Assignment() editview = component.getMultiAdapter((mapping['foo'], request), name='edit') self.failUnless(isinstance(editview, osha_items.EditForm))
def test_renderer(self): context = self.folder request = self.folder.REQUEST view = self.folder.restrictedTraverse('@@plone') manager = component.getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal) assignment = osha_items.Assignment() renderer = component.getMultiAdapter( (context, request, view, manager, assignment), IPortletRenderer) self.failUnless(isinstance(renderer, osha_items.Renderer))
def renderer(self, context=None, request=None, view=None, manager=None, assignment=None): """ """ context = context or self.folder request = request or self.folder.REQUEST view = view or self.folder.restrictedTraverse('@@plone') manager = manager or component.getUtility( IPortletManager, name='plone.rightcolumn', context=self.portal) assignment = assignment or osha_items.Assignment() return component.getMultiAdapter( (context, request, view, manager, assignment), IPortletRenderer)
def test_portlet_interfaces(self): portlet = osha_items.Assignment() self.failUnless(IPortletAssignment.providedBy(portlet)) self.failUnless(IPortletDataProvider.providedBy(portlet.data))