Ignore:
Timestamp:
Apr 20, 2012 10:04:56 AM (12 years ago)
Author:
potar
Message:

Merged tests branch

Location:
quintagroup.plonetabs/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonetabs/trunk

    • Property svn:mergeinfo
      •  

        old new  
        11/quintagroup.plonetabs/branches/plone4:3076-3243 
         2/quintagroup.plonetabs/branches/tests:3394-3436 
  • quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/test_controlpanel.py

    r917 r3437  
    66 
    77from Products.CMFCore.utils import getToolByName 
    8 from Products.CMFCore.ActionInformation import Action, ActionCategory 
     8from Products.CMFCore.ActionInformation import Action 
    99 
    1010from quintagroup.plonetabs import messageFactory as _ 
    1111from quintagroup.plonetabs.browser.interfaces import IPloneTabsControlPanel 
    12 from quintagroup.plonetabs.browser.plonetabs import PloneTabsControlPanel as ptp 
     12from quintagroup.plonetabs.browser.plonetabs \ 
     13                                      import PloneTabsControlPanel as ptp 
    1314from quintagroup.plonetabs.tests.base import PloneTabsTestCase 
    1415from quintagroup.plonetabs.tests.data import PORTAL_ACTIONS 
    1516 
     17 
    1618class TestControlPanelHelperMethods(PloneTabsTestCase): 
    1719    """Test here configlet helper methods""" 
    18      
    1920    def afterSetUp(self): 
    2021        super(TestControlPanelHelperMethods, self).afterSetUp() 
     
    2526        self.panel = panel.__of__(self.portal) 
    2627        self.tool = getToolByName(self.portal, 'portal_actions') 
    27      
     28 
    2829    def test_redirect(self): 
    2930        response = self.portal.REQUEST.RESPONSE 
    3031        method = self.panel.redirect 
    31         portal_url =  getMultiAdapter((self.portal, self.portal.REQUEST), 
     32        portal_url = getMultiAdapter((self.portal, self.portal.REQUEST), 
    3233                                      name=u"plone_portal_state").portal_url() 
    3334        url = '%s/@@plonetabs-controlpanel' % portal_url 
     
    3536        self.assertEquals(response.headers.get('location', ''), url, 
    3637            'Redirect method is not working properly.') 
    37          
     38 
    3839        # check query string and anchor hash 
    3940        method('http://quintagroup.com', 'q=test', 'hash_code') 
     
    4142            'http://quintagroup.com?q=test#hash_code', 
    4243            'Redirect method is not working properly.') 
    43      
     44 
    4445    def test_fixExpression(self): 
    4546        method = self.panel.fixExpression 
    4647        self.assertEquals(method('/slash'), 'string:${portal_url}/slash') 
    47         self.assertEquals(method('https://test.com'), 'string:https://test.com') 
     48        self.assertEquals(method('https://test.com'), 
     49                                 'string:https://test.com') 
    4850        self.assertEquals(method('python:True'), 'python:True') 
    4951        self.assertEquals(method('hello'), 'string:${object_url}/hello') 
    50      
     52 
    5153    def test_copyAction(self): 
    5254        data = PORTAL_ACTIONS[0][1]['children'][0][1] 
     
    5557        self.assertEquals(len(info.keys()), 6) 
    5658        self.assertEquals(info['description'], 'The most important place') 
    57      
     59 
    5860    def test_validateActionFields(self): 
    5961        method = self.panel.validateActionFields 
     
    6365        self.assertEquals(errors, {}, 
    6466            'There should be no errors for valid data.') 
    65          
    66         bad_data = {'id':'', 
     67 
     68        bad_data = {'id': '', 
    6769                    'title': ' ', 
    6870                    'available_expr': 'bad_type:test', 
    6971                    'url_expr': 'bad_type:test'} 
    70          
     72 
    7173        # Revert PloneTestCase's optimization 
    7274        # because this breaks our test 
     75        from Products.CMFCore.Expression import getEngine 
     76        from Products.CMFCore.Expression import Expression 
     77 
    7378        def __init__(self, text): 
    7479            self.text = text 
    7580            if text.strip(): 
    7681                self._v_compiled = getEngine().compile(text) 
    77         from Products.CMFCore.Expression import Expression 
     82 
    7883        optimized__init__ = Expression.__init__ 
    7984        Expression.__init__ = __init__ 
     
    8186        # rollback our patch 
    8287        Expression.__init__ = optimized__init__ 
    83          
     88 
    8489        self.assertEquals(len(errors.keys()), 4, 
    8590            'validateActionFields method is not working properly.') 
    86      
     91        #### pyflakes.scripts.pyflakes ends. 
     92 
    8793    def test_processErrors(self): 
    8894        method = self.panel.processErrors 
    89         errors = {'error':'error message'} 
     95        errors = {'error': 'error message'} 
    9096        self.assertEquals(method(errors), errors, 
    9197            'processErrors method is not working properly.') 
     
    9399            {'pre_error_post': 'error message'}, 
    94100            'processErrors method is not working properly.') 
    95      
     101 
    96102    def test_parseEditForm(self): 
    97103        method = self.panel.parseEditForm 
     
    110116                             'visible': True}), 
    111117            'parseEditForm method is not working properly.') 
    112          
     118 
    113119        del form['orig_id'] 
    114120        self.failUnlessRaises(KeyError, method, form) 
    115      
     121 
    116122    def test_parseAddForm(self): 
    117123        method = self.panel.parseAddForm 
     
    129135                             'available_expr': 'expr2'}), 
    130136            'parseAddForm method is not working properly.') 
    131          
     137 
    132138        del form['id'] 
    133139        self.failUnlessRaises(KeyError, method, form) 
    134      
     140 
    135141    def test_getActionCategory(self): 
    136142        method = self.panel.getActionCategory 
    137143        self.purgeActions() 
    138144        self.failUnlessRaises(KeyError, method, 'portal_tabs') 
    139          
     145 
    140146        self.setupActions(self.tool) 
    141147        self.assertEquals(method('portal_tabs').id, 'portal_tabs', 
    142148            'getActionCategory is not working properly.') 
    143      
     149 
    144150    def test_getOrCreateCategory(self): 
    145151        method = self.panel.getOrCreateCategory 
     
    147153        self.assertEquals(method('portal_tabs').id, 'portal_tabs', 
    148154            'getOrCreateCategory is not working properly.') 
    149      
     155 
    150156    def test_setSiteProperties(self): 
    151157        self.panel.setSiteProperties(title='Test Title') 
     
    153159        self.assertEquals(sp.getProperty('title'), 'Test Title', 
    154160            'setSiteProperties method is not working properly.') 
    155      
     161 
    156162    def test_renderViewlet(self): 
    157163        # register test viewlet and it's manager 
     
    161167        from zope.publisher.interfaces.browser import IDefaultBrowserLayer 
    162168        from zope.publisher.interfaces.browser import IBrowserView 
     169 
    163170        class TestViewlet(ViewletBase): 
    164171            def __of__(self, obj): 
    165172                return self 
     173 
    166174            def render(self): 
    167175                return 'test viewlet' 
     176 
    168177        provideAdapter( 
    169178            TestViewlet, 
     
    176185            IViewletManager, 
    177186            name=u'test_manager') 
    178          
     187 
    179188        self.assertEquals( 
    180189            self.panel.renderViewlet('test_manager', 'test_viewlet'), 
    181190            'test viewlet', 
    182191            'renderViewlet method is not workig properly') 
    183      
     192 
    184193    def test_addAction(self): 
    185194        self.purgeActions() 
    186         self.panel.addAction('new_category', {'id':'id1', 'title':'Test'}) 
     195        self.panel.addAction('new_category', {'id': 'id1', 'title': 'Test'}) 
    187196        self.failUnless('id1' in self.tool.new_category.objectIds(), 
    188197            'addAction method is not workig properly') 
    189      
     198 
    190199    def test_updateAction(self): 
    191200        method = self.panel.updateAction 
    192          
    193         self.purgeActions() 
    194         self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id':'new'}) 
    195          
     201 
     202        self.purgeActions() 
     203        self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'}) 
     204 
    196205        self.setupActions(self.tool) 
    197206        # we need to commit transaction because 
     
    199208        import transaction 
    200209        transaction.savepoint() 
    201         method('home', 'portal_tabs', {'id':'new_home'}) 
     210        method('home', 'portal_tabs', {'id': 'new_home'}) 
    202211        self.failUnless('new_home' in self.tool.portal_tabs.objectIds(), 
    203212            'updateAction method is not workig properly') 
    204      
     213 
    205214    def test_deleteAction(self): 
    206215        self.purgeActions() 
     
    209218        self.failIf('home' in self.tool.portal_tabs.objectIds(), 
    210219             'deleteAction method is not workig properly') 
    211      
     220 
    212221    def test_moveAction(self): 
    213222        self.purgeActions() 
     
    223232class TestControlPanelAPIMethods(PloneTabsTestCase): 
    224233    """Test here interface methods of control panel class""" 
    225      
     234 
    226235    def afterSetUp(self): 
    227236        super(TestControlPanelAPIMethods, self).afterSetUp() 
     
    232241        self.panel = panel.__of__(self.portal) 
    233242        self.tool = getToolByName(self.portal, 'portal_actions') 
    234      
     243 
    235244    def test_interface(self): 
    236245        self.failUnless(IPloneTabsControlPanel.implementedBy(ptp), 
     
    238247        self.failUnless(verifyClass(IPloneTabsControlPanel, ptp), 
    239248            'PloneTabs control panel does not implement required interface.') 
    240      
     249 
    241250    def test_getPageTitle(self): 
    242251        self.assertEquals(self.panel.getPageTitle(), 
     
    247256              mapping={'cat_name': 'notexists'}), 
    248257            'getPageTitle method is broken') 
    249      
     258 
    250259    def test_hasActions(self): 
    251260        method = self.panel.hasActions 
     
    254263        self.failIf(method(), 
    255264            'There should be no portal_tab actions in portal') 
    256          
     265 
    257266        # setup our own actions 
    258267        self.setupActions(self.tool) 
    259268        self.failUnless(method(), 
    260269            'There should be portal_tab actions in portal') 
    261      
     270 
    262271    def test_getPortalActions(self): 
    263272        method = self.panel.getPortalActions 
     
    266275        self.assertEquals(len(method()), 0, 
    267276            'There should be no actions in portal_tabs category.') 
    268          
     277 
    269278        # setup our own actions 
    270279        self.setupActions(self.tool) 
    271280        self.assertEquals(len(method()), 2, 
    272281            'There should be 2 actions in portal_tabs category.') 
    273          
     282 
    274283        # marginal arguments 
    275284        self.assertEquals(len(method('notexistent_category')), 0, 
    276285            'There should be no actions for not existed category.') 
    277      
     286 
    278287    def test_isGeneratedTabs(self): 
    279288        method = self.panel.isGeneratedTabs 
     
    282291        sp.manage_changeProperties(disable_folder_sections=True) 
    283292        self.failIf(method(), 'But folder sections are disabled...') 
    284      
     293 
    285294    def test_isNotFoldersGenerated(self): 
    286295        method = self.panel.isNotFoldersGenerated 
     
    289298        sp.manage_changeProperties(disable_nonfolderish_sections=True) 
    290299        self.failIf(method(), 'But non folderish sections are disabled...') 
    291      
     300 
    292301    def test_getActionsList(self): 
    293302        method = self.panel.getActionsList 
     
    299308        self.failUnless('class="editform"' in method(), 
    300309            'There are no actions in actions list template.') 
    301      
     310 
    302311    def test_getAutoGenereatedSection(self): 
    303312        method = self.panel.getAutoGenereatedSection 
     
    308317            'There should be form in autogenerated tabs template ' 
    309318            'for portal_tabs category.') 
    310      
     319 
    311320    def test_getGeneratedTabs(self): 
    312321        self.panel.getGeneratedTabs() 
     
    316325            'Mon, 26 Jul 1996 05:00:00 GMT', 
    317326            'Expiration header is not set properly.') 
    318      
     327 
    319328    def test_getRootTabs(self): 
    320329        method = self.panel.getRootTabs 
     
    323332        self.assertEquals(len(method()), 0, 
    324333            'There should be no root elements for navigation.') 
    325          
     334 
    326335        # now add some testing content 
    327336        self.setupContent(self.portal) 
    328337        self.assertEquals(len(method()), 2, 
    329338            'There should be 2 elements in portal root for navigation.') 
    330          
     339 
    331340        # now switch off autogeneration 
    332341        sp = getToolByName(self.portal, 'portal_properties').site_properties 
     
    335344            'There should be no root elements for navigation when ' 
    336345            'tabs autogeneration is switched off.') 
    337      
     346 
    338347    def test_getCategories(self): 
    339348        method = self.panel.getCategories 
     
    342351        self.assertEquals(len(method()), 0, 
    343352            'There should be no categories in portal_actions tool.') 
    344          
     353 
    345354        # now setup actions 
    346355        self.setupActions(self.tool) 
    347356        self.assertEquals(method(), ['portal_tabs', 'new_category'], 
    348357            'There should be exactly 2 categories in portal_actions tool.') 
    349      
     358 
    350359    def test_portal_tabs(self): 
    351360        method = self.panel.portal_tabs 
     
    354363        self.assertEquals(len(method()), 0, 
    355364            'There should be no portal tabs.') 
    356          
     365 
    357366        # cleanup memoize cache 
    358367        # cause actions method of portal context state is caching it's 
    359368        # results in request and we have the same request for every call 
    360369        self.purgeCache(self.portal.REQUEST) 
    361          
     370 
    362371        # add actions 
    363372        self.setupActions(self.tool) 
    364373        self.assertEquals(len(method()), 2, 
    365374            'There should be 2 portal tabs.') 
    366          
     375 
    367376        # add content 
    368377        self.setupContent(self.portal) 
    369378        self.assertEquals(len(method()), 4, 
    370379            'There should be 4 portal tabs.') 
    371      
     380 
    372381    def test_selected_portal_tab(self): 
    373382        self.assertEquals(self.panel.selected_portal_tab(), 'index_html', 
     
    381390class TestControlPanelManageMethods(PloneTabsTestCase): 
    382391    """Test here management methods of control panel class""" 
    383      
     392 
    384393    def afterSetUp(self): 
    385394        super(TestControlPanelManageMethods, self).afterSetUp() 
     
    390399        self.panel = panel.__of__(self.portal) 
    391400        self.tool = getToolByName(self.portal, 'portal_actions') 
    392          
     401 
    393402        # purge standard set of actions and set our own testing ones 
    394403        self.purgeActions() 
    395404        self.setupActions(self.tool) 
    396      
     405 
    397406    def test_manage_setAutogeneration(self): 
    398407        self.setupContent(self.portal) 
     
    405414        self.failIf(sp.disable_folder_sections) 
    406415        self.failUnless(sp.disable_nonfolderish_sections) 
    407      
     416 
    408417    def test_manage_addAction(self): 
    409418        self.purgeActions() 
     
    418427        self.failIf(postback, 
    419428            'There should be redirect after successfull adding.') 
    420      
     429 
    421430    def test_manage_editAction(self): 
    422431        method = self.panel.manage_editAction 
     
    432441        import transaction 
    433442        transaction.savepoint() 
    434          
     443 
    435444        postback = method(form, {}) 
    436445        self.failUnless('id_new' in self.tool.portal_tabs.objectIds()) 
    437446        self.failIf(postback, 
    438447            'There should be redirect after successfull edition.') 
    439          
     448 
    440449        form['category'] = 'non_existent' 
    441450        self.failUnlessRaises(KeyError, method, form, {}) 
    442      
     451 
    443452    def test_manage_deleteAction(self): 
    444453        self.purgeActions() 
     
    453462        self.panel.manage_deleteAction(form, {}) 
    454463        self.failIf('home' in self.tool.portal_tabs.objectIds()) 
    455      
     464 
    456465    def test_manage_moveUpAction(self): 
    457466        self.purgeActions() 
     
    467476        self.assertEquals( 
    468477            self.tool.portal_tabs.getObjectPosition('quintagroup'), 0) 
    469      
     478 
    470479    def test_manage_moveDownAction(self): 
    471480        self.purgeActions() 
     
    487496    suite.addTest(unittest.makeSuite(TestControlPanelAPIMethods)) 
    488497    suite.addTest(unittest.makeSuite(TestControlPanelManageMethods)) 
    489      
     498 
    490499    # these tests are implemented as Selenium KSS Tests 
    491500    # using kss.demo package, and KSS plugins are tested by means of 
Note: See TracChangeset for help on using the changeset viewer.