Changeset 1276

Show
Ignore:
Timestamp:
04/18/08 15:55:41 (8 months ago)
Author:
sgillies
Message:

Working browser views with tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pleiades.vocabulary/trunk/pleiades/vocabulary/browser/configure.zcml

    r1273 r1276  
    44  > 
    55 
    6   <browser:view 
     6  <browser:page 
    77    for="*" 
    88    name="vocabulary_macros" 
    9     class=".macros.ThesaurusMacros" 
     9    class=".vocabulary.VocabularyMacros" 
     10    template="vocabulary_macros.pt" 
    1011    permission="zope.View" 
    1112    /> 
  • pleiades.vocabulary/trunk/pleiades/vocabulary/browser/vocabularies_index.pt

    r1275 r1276  
    7575            header_macro view_macros/header | header_macro | base_macros/header; 
    7676            body_macro view_macros/body | body_macro | base_macros/body; 
    77             thesaurilisting_macro context/thesauri_macros/macros/thesaurilisting | folderlisting | base_macros/folderlisting; 
     77            thesaurilisting_macro context/vocabulary_macros/macros/thesaurilisting | folderlisting | base_macros/folderlisting; 
    7878            footer_macro view_macros/footer | footer_macro | base_macros/footer; 
    7979            errors python:request.get('errors', {})"> 
  • pleiades.vocabulary/trunk/pleiades/vocabulary/browser/vocabulary_view.pt

    r1274 r1276  
    55      xmlns:metal="http://xml.zope.org/namespaces/metal" 
    66      xmlns:i18n="http://xml.zope.org/namespaces/i18n" 
    7       metal:use-macro="here/main_template/macros/master" 
     7      metal:use-macro="context/main_template/macros/master" 
    88      i18n:domain="plone"> 
    99 
     
    1111 
    1212  <metal:javascript_head fill-slot="javascript_head_slot"> 
    13     <tal:block define="macro here/archetypes_custom_js/macros/javascript_head | nothing" 
     13    <tal:block define="macro context/archetypes_custom_js/macros/javascript_head | nothing" 
    1414               condition="macro"> 
    1515      <metal:block use-macro="macro" /> 
     
    2121      create additional defines for each slot it fills. 
    2222    </tal:comment> 
    23     <tal:js define="fields python:here.Schema().viewableFields(here); 
    24                     js python:here.getUniqueWidgetAttr(fields, 'helper_js')" 
     23    <tal:js define="fields python:context.Schema().viewableFields(context); 
     24                    js python:context.getUniqueWidgetAttr(fields, 'helper_js')" 
    2525            condition="js" 
    2626            repeat="item js"> 
     
    3131      </script> 
    3232    </tal:js> 
    33     <tal:block define="portal_type python:here.getPortalTypeName().lower().replace(' ', '_'); 
     33    <tal:block define="portal_type python:context.getPortalTypeName().lower().replace(' ', '_'); 
    3434                       view_template python:'%s_view' % portal_type; 
    35                        view_macros python:path('here/%s/macros|nothing' % view_template); 
     35                       view_macros python:path('context/%s/macros|nothing' % view_template); 
    3636                       macro view_macros/js | nothing" 
    3737               condition="macro"> 
     
    4747      create additional defines for each slot it fills. 
    4848    </tal:comment> 
    49     <tal:css define="fields python:here.Schema().viewableFields(here); 
    50                      css python:here.getUniqueWidgetAttr(fields, 'helper_css')" 
     49    <tal:css define="fields python:context.Schema().viewableFields(context); 
     50                     css python:context.getUniqueWidgetAttr(fields, 'helper_css')" 
    5151             condition="css" 
    5252             repeat="item css"> 
     
    5757      </style> 
    5858    </tal:css> 
    59     <tal:block define="portal_type python:here.getPortalTypeName().lower().replace(' ', '_'); 
     59    <tal:block define="portal_type python:context.getPortalTypeName().lower().replace(' ', '_'); 
    6060                       view_template python:'%s_view' % portal_type; 
    61                        view_macros python:path('here/%s/macros|nothing' % view_template); 
     61                       view_macros python:path('context/%s/macros|nothing' % view_template); 
    6262                       macro view_macros/css | nothing" 
    6363               condition="macro"> 
     
    6969    <metal:fill fill-slot="main"> 
    7070      <metal:main_macro define-macro="main" 
    71             tal:define="portal_type python:here.getPortalTypeName().lower().replace(' ', '_'); 
    72             base_macros here/base/macros; 
     71            tal:define="portal_type python:context.getPortalTypeName().lower().replace(' ', '_'); 
     72            base_macros context/base/macros; 
    7373            view_template python:'%s_view' % portal_type; 
    74             view_macros python:path('here/%s/macros|nothing' % view_template); 
    75             header_macro here/thesaurus_macros/macros/header | base_macros/header; 
     74            view_macros python:path('context/%s/macros|nothing' % view_template); 
     75            header_macro context/thesaurus_macros/macros/header | base_macros/header; 
    7676            body_macro view_macros/body | body_macro | base_macros/body; 
    77             termlisting_macro here/thesaurus_macros/macros/termlisting | folderlisting | base_macros/folderlisting; 
     77            termlisting_macro context/vocabulary_macros/macros/termlisting | folderlisting | base_macros/folderlisting; 
    7878            footer_macro view_macros/footer | footer_macro | base_macros/footer; 
    7979            errors python:request.get('errors', {}); 
  • pleiades.vocabulary/trunk/pleiades/vocabulary/configure.zcml

    r1266 r1276  
    55  i18n_domain="pleiades.policy" 
    66  > 
     7 
     8  <include package="zope.app.component" file="meta.zcml"/> 
     9  <include package="zope.app.security" file="meta.zcml"/>  
     10  <include package="zope.app.security"/> 
    711 
    812  <five:registerPackage package="." initialize=".initialize" /> 
     
    1620    /> 
    1721 
     22  <include package=".browser"/> 
     23 
    1824</configure> 
  • pleiades.vocabulary/trunk/pleiades/vocabulary/tests/base.py

    r1268 r1276  
    4242    we can put common utility or setup code in here. 
    4343    """ 
     44 
     45 
     46class PleiadesVocabularyFunctionalTestCase(ptc.FunctionalTestCase): 
     47    """We use this base class for all the tests in this package. If necessary, 
     48    we can put common utility or setup code in here. 
     49    """ 
  • pleiades.vocabulary/trunk/pleiades/vocabulary/tests/test_doctests.py

    r1275 r1276  
    88def test_suite(): 
    99    return unittest.TestSuite([ 
    10         ztc.ZopeDocFileSuite( 
     10        ztc.FunctionalDocFileSuite( 
    1111            'vocab-views.txt', 
    1212            package='pleiades.vocabulary.tests', 
    13             test_class=base.PleiadesVocabularyTestCase, 
     13            test_class=base.PleiadesVocabularyFunctionalTestCase, 
    1414            optionflags=optionflags 
    1515            ) 
  • pleiades.vocabulary/trunk/pleiades/vocabulary/tests/vocab-views.txt

    r1275 r1276  
    33============================== 
    44 
    5 Query the catalog using the spatialcatalog view 
     5First, we must perform some setup. We use the testbrowser that is shipped 
     6with Five, as this provides proper Zope 2 integration. Most of the  
     7documentation, though, is in the underlying zope.testbrower package. 
    68 
    7     >>> r = http(r""" 
    8     ... GET /vocabulary/vocabularies_index HTTP/1.1 
    9     ... Authorization: Basic mgr:mgrpw 
    10     ... """, handle_errors=False) 
    11     >>> r.getStatus() 
    12     200 
    13     >>> print r.getBody() 
    14     '' 
     9    >>> from Products.Five.testbrowser import Browser 
     10    >>> browser = Browser() 
     11    >>> portal_url = self.portal.absolute_url() 
     12 
     13The following is useful when writing and debugging testbrowser tests. It lets 
     14us see all error messages in the error_log. 
     15 
     16    >>> self.portal.error_log._ignored_exceptions = () 
     17 
     18With that in place, we can go to the portal front page and log in. We will 
     19do this using the default user from PloneTestCase: 
     20 
     21    >>> from Products.PloneTestCase.setup import portal_owner, default_password 
     22 
     23    >>> browser.open(portal_url) 
     24 
     25We have the login portlet, so let's use that. 
     26 
     27    >>> browser.getControl(name='__ac_name').value = portal_owner 
     28    >>> browser.getControl(name='__ac_password').value = default_password 
     29    >>> browser.getControl(name='submit').click() 
     30 
     31Here, we set the value of the fields on the login form and then simulate a 
     32submit click. 
     33 
     34We then test that we are still on the portal front page: 
     35 
     36    >>> browser.url == portal_url 
     37    True 
     38     
     39And we ensure that we get the friendly logged-in message: 
     40 
     41    >>> "You are now logged in" in browser.contents 
     42    True 
     43 
     44Test index of vocabularies 
     45 
     46    >>> browser.handleErrors = False 
     47    >>> vocab_url = self.portal.vocabulary.absolute_url() 
     48    >>> browser.open("%s/vocabularies_index" % vocab_url) 
     49    >>> 'name-accuracy' in browser.contents 
     50    True 
     51 
     52Test view of one vocabulary 
     53 
     54    >>> vocab_url = self.portal.vocabulary.absolute_url() 
     55    >>> browser.open("%s/vocabulary_view?t=name-accuracy" % vocab_url) 
     56    >>> 'a string of characters in an ancient (primary)' in browser.contents 
     57    True 
     58