Ups, sorry here is the attachment.

Jürgen

Stephan Richter wrote:
> On Friday 11 November 2005 12:00, jürgen Kartnaller wrote:
> 
>>I could now manage to have a relatively simple test (see attached file).
> 
> 
> No file attached in my E-mail. :-(
> 
> 
>>I also found and fixed some other problems I encountered with the
>>utility registration.
>>
>>Can you please have a look at the test implementation and let me know if
>>this look ok.
>>
>>This test will not work with the current implementation of the
>>SiteManagementView !
>>I already fixed some problems in my sandbox.
>>
>>Problems solved :
>>- adding a utility without name
>>- renaming utilities to a name another already renamed utility had
>>- deleting more than one utility
>>- better message support
>>   - show the message at the utility not just on top of the page
>>   - show UserError exception as message
> 
> 
> Sounds very exciting! :-) Thanks a lot for your work! I will also review your 
> file, once I get it.
> 
> Regards,
> Stephan


-- 

---------------------------------------------------
Jürgen Kartnaller   mailto:juergen_at_kartnaller.at
                    http://www.kartnaller.at
                    http://www.mcb-bregenz.at
---------------------------------------------------

==============
The Tools View
==============

  >>> from zope import interface

First we define a utility to work with :

  >>> from zope.app.content.interfaces import IContentType
  >>> from zope.app.component.interfaces.registration import IRegisterable
  >>> class IFooUtil(interface.Interface):
  ...     pass
  >>> class FooUtil(object):
  ...     __parent__ = None
  ...     __name__ = u''
  ...     interface.implements(IFooUtil, IRegisterable, IContentType)

  >>> from zope.app.component.browser import tools
  >>> from zope import component

  >>> toolConfig = tools.ToolConfiguration(IFooUtil, 'FooUtil')
  >>> component.provideUtility(toolConfig, tools.IToolConfiguration, 'IFooUtil')

We need a factory to create our new utility :

  >>> from zope.component.interfaces import IFactory
  >>> from zope.component.factory import Factory

  >>> from zope.app.security import protectclass
  >>> protectclass.protectName(Factory, '__call__', 'zope.public')

  >>> factory = Factory(FooUtil, 
  ...                   'Utility for foo',
  ...                   'This factory creates a foo utility.')
  >>> component.provideUtility(factory, IFactory, 'IFooUtil')

Let's now invoke our site management :

  >>> from zope.publisher.browser import TestRequest
  >>> request = TestRequest()
  >>> request.form['activeTool']='IFooUtil'

  >>> from zope.app import zapi
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u''
  >>> request.form['ADD-TOOL-SUBMIT']='submit'
  >>> request.form['type_name']='IFooUtil'
  >>> request.form['id']='foo1'
  >>> view.update()
  u''
  >>> util = component.getUtility(IFooUtil, 'foo1')
  >>> util is not None
  True
  >>> current_tools = view.getTools()
  >>> len(current_tools)
  1
  >>> current_tools[0]['instances'][0]['name']
  'foo1'

Registering with the same name
------------------------------

  >>> print view.update()
  The given tool name is already being used.

  >>> request.form['id']='foo2'
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u''
  >>> current_tools = view.getTools()
  >>> current_tools[0]['instances'][0]['name']
  'foo1'
  >>> current_tools[0]['instances'][1]['name']
  'foo2'

Creating a utility without a name
---------------------------------

  >>> request.form['id']=''
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u''
  >>> current_tools = view.getTools()
  >>> current_tools[0]['instances'][0]['name']
  'foo1'
  >>> current_tools[0]['instances'][1]['name']
  'foo2'
  >>> current_tools[0]['instances'][2]['name']
  u''

Renaming utilities
------------------

  >>> request = TestRequest()
  >>> request.form['activeTool']='IFooUtil'
  >>> request.form['RENAME-SUBMIT']='submit'

First we rename a single utility :

  >>> request.form['old_names']=['foo1']
  >>> request.form['new_names']=['JohnDoe']
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u'Tools successfully renamed.'
  >>> current_tools = view.getTools()
  >>> current_tools[0]['instances'][0]['name']
  'JohnDoe'
  >>> current_tools[0]['instances'][1]['name']
  'foo2'
  >>> current_tools[0]['instances'][2]['name']
  u''

  >>> request.form['old_names']=['JohnDoe', 'foo2']
  >>> request.form['new_names']=['foo1', 'Tres']
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u'Tools successfully renamed.'
  >>> current_tools = view.getTools()
  >>> current_tools[0]['instances'][0]['name']
  'foo1'
  >>> current_tools[0]['instances'][1]['name']
  'Tres'
  >>> current_tools[0]['instances'][2]['name']
  u''

Deleting utilities
------------------

  >>> request = TestRequest()
  >>> request.form['activeTool']='IFooUtil'
  >>> request.form['DELETE-SUBMIT']='submit'

First we try without a selected utility :

  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u'No tools selected.'

Now select one utility :

  >>> request.form['selected']=['']
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u'Tools successfully deleted.'
  >>> current_tools = view.getTools()
  >>> current_tools[0]['instances'][0]['name']
  'foo1'
  >>> current_tools[0]['instances'][1]['name']
  'Tres'

Select all the remaining utilities :

  >>> request.form['selected']=['foo1', 'Tres']
  >>> view = tools.SiteManagementView(zapi.getSiteManager(), request)
  >>> view.update()
  u'Tools successfully deleted.'
  >>> view.getTools()[0]['instances']
  []

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to