Ignore:
Timestamp:
Nov 16, 2010 5:56:56 PM (13 years ago)
Author:
fenix
Message:

added tests for portlets stats and properties stats views

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.analytics/trunk/quintagroup/analytics/tests.py

    r3019 r3020  
    33 
    44from AccessControl.SecurityManagement import newSecurityManager 
    5 from zope.component import testing, queryMultiAdapter 
    65from Testing import ZopeTestCase as ztc 
    7  
    86from Products.Five import zcml 
    97from Products.Five import fiveconfigure 
     8from zope.component import testing, queryMultiAdapter, getUtility 
     9 
    1010from Products.PloneTestCase import PloneTestCase as ptc 
    1111from Products.PloneTestCase import setup as ptc_setup 
    1212from Products.PloneTestCase.layer import PloneSite 
     13from plone.portlets.interfaces import IPortletType 
     14 
    1315import quintagroup.analytics 
     16 
    1417ptc.setupPloneSite() 
    1518 
     
    8689    layer = Installed 
    8790 
    88 #TO DO:===================================================================== 
    89 #      add tests for every views methods; 
    90 #      add doc tests to validate if all needed elements are present on page; 
    9191 
    9292class TestQAInstallation(TestCase): 
     
    331331                              [chart_tag, self.view.getChart()])) 
    332332 
     333class LegacyPortlets(TestCase): 
     334    """Test all legasy_portlets view methods.""" 
     335 
     336 
     337    def afterSetUp(self): 
     338        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST), 
     339                                       name='legacy_portlets') 
     340 
     341    def test_getPortlets(self): 
     342        """Tests method that returns portlets info.""" 
     343 
     344        # this is true for Plone 4 
     345        self.assert_(self.view.getPortlets() == []) 
     346 
     347    def test_getAllPortletExpressions(self): 
     348        """Tests method that returns portlets expressions.""" 
     349 
     350        # this is true for Plone 4 
     351        self.assert_(self.view.getAllPortletExpressions() == []) 
     352 
     353class TestPropertiesStats(TestCase): 
     354    """Tests all properties_stats view methods.""" 
     355 
     356    def afterSetUp(self): 
     357        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST), 
     358                                       name='properties_stats') 
     359 
     360    def test_getPropsList(self): 
     361        self.view.propname = 'title' 
     362        result = [u'Plone site', u'Welcome to Plone', 
     363                  u'News', u'Events', u'Users'] 
     364 
     365        for title in result: 
     366            self.assert_(title in [prop_info['slots'] 
     367                     for prop_info in self.view.getPropsList()]) 
     368 
     369 
     370class TestPortletsStats(TestCase): 
     371    """Tests all properties_stats view methods.""" 
     372 
     373    def afterSetUp(self): 
     374        self.view = queryMultiAdapter((self.portal, self.portal.REQUEST), 
     375                                       name='portlets_stats') 
     376 
     377    def test_getPropsList(self): 
     378        """Tests method that collects portlet information from site.""" 
     379 
     380        self.loginAsPortalOwner() 
     381        portlet = getUtility(IPortletType, name='portlets.Calendar') 
     382        mapping = \ 
     383          self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn') 
     384        mapping.restrictedTraverse('+/' + portlet.addview)() 
     385 
     386        plone_portlets_info = filter(lambda info:info['path'] == '/plone', 
     387                                     self.view.getPropsList()) 
     388        lslots = plone_portlets_info[0]['left_slots'] 
     389        self.assert_(filter(lambda info: info['title'] == 'Calendar', lslots)) 
     390 
     391 
    333392def test_suite(): 
    334393    from unittest import TestSuite, makeSuite 
     
    361420    test_suite.addTest(makeSuite(TestOwnershipByState)) 
    362421    test_suite.addTest(makeSuite(TestTypeByState)) 
     422    test_suite.addTest(makeSuite(LegacyPortlets)) 
     423    test_suite.addTest(makeSuite(TestPropertiesStats)) 
     424    test_suite.addTest(makeSuite(TestPortletsStats)) 
    363425    return test_suite 
    364426 
Note: See TracChangeset for help on using the changeset viewer.