Re: [Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-11-12 Thread Stephan Richter
On Saturday 12 November 2005 07:12, jürgen Kartnaller wrote:
> Ups, sorry here is the attachment.

Very nice work! Check it in!

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-11-12 Thread jürgen Kartnaller
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

Re: [Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-11-12 Thread Stephan Richter
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
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-11-11 Thread jürgen Kartnaller
Hi Tres.

I could now manage to have a relatively simple test (see attached file).

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

Jürgen


Tres Seaver wrote:
> Stephan Richter wrote:
> 
>>>On Wednesday 05 October 2005 17:00, jürgen Kartnaller wrote:
>>>
>>>
When more than one utility is selected for deleting in the site
management view, only the first selected utility is deleted.

The problem is that the content of regManager is changed inside the
while iteratating over it.
Here is the fix which works for me :
If this is applicable, can please someone check it into the trunk ?
The file is in zope.app.component.browser
>>>
>>>
>>>Could you create an issue in the bug collector for this? If you cannot 
>>>create 
>>>a unit test for it, then I will. :-)
> 
> 
> Stephan,
> 
> I was in the midst of writing a 'tools.txt' doctest which would have
> provided the basis for such a test when I wrote my "keening" post.  In
> case you missed the attacment, here it is again.
> 
> Tres.
> --
> ===
> Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
> Palladion Software   "Excellence by Design"http://palladion.com

-- 

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

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



Re: [Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-19 Thread Stephan Richter
On Tuesday 18 October 2005 10:46, Tres Seaver wrote:
> I was in the midst of writing a 'tools.txt' doctest which would have
> provided the basis for such a test when I wrote my "keening" post.  In
> case you missed the attacment, here it is again.

I was looking at the file actually before, but I would probably write many 
more stubs and not even do such a strong integration test.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-18 Thread jürgen Kartnaller
Stephan Richter wrote:
> On Wednesday 05 October 2005 17:00, jürgen Kartnaller wrote:
> 
>>When more than one utility is selected for deleting in the site
>>management view, only the first selected utility is deleted.
>>
>>The problem is that the content of regManager is changed inside the
>>while iteratating over it.
>>Here is the fix which works for me :
>>If this is applicable, can please someone check it into the trunk ?
>>The file is in zope.app.component.browser
> 
> 
> Could you create an issue in the bug collector for this? If you cannot create 
> a unit test for it, then I will. :-)

Hi Stephan.

It's in the collector now, so you can start creating the unit test :)

I'm looking forward to see this code because I'm completely stuck on this.
The problem to build such kind of tests is to setup a test environment
which contains enough context for the test case. And this really takes a
lot of time for a none zope guru.

Jürgen

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



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-18 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Stephan Richter wrote:
> On Wednesday 05 October 2005 17:00, jürgen Kartnaller wrote:
> 
>>When more than one utility is selected for deleting in the site
>>management view, only the first selected utility is deleted.
>>
>>The problem is that the content of regManager is changed inside the
>>while iteratating over it.
>>Here is the fix which works for me :
>>If this is applicable, can please someone check it into the trunk ?
>>The file is in zope.app.component.browser
> 
> 
> Could you create an issue in the bug collector for this? If you cannot create 
> a unit test for it, then I will. :-)

Stephan,

I was in the midst of writing a 'tools.txt' doctest which would have
provided the basis for such a test when I wrote my "keening" post.  In
case you missed the attacment, here it is again.

Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDVQrO+gerLs4ltQ4RAsHjAJ0V24tq2m9gRX+nGUKqGkNtzyy8ZACfcgk3
UGYvl9aEvV4aoXD6BYxNCxQ=
=JDy1
-END PGP SIGNATURE-


keening-20051013.tar.gz
Description: application/gzip
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-18 Thread Stephan Richter
On Friday 07 October 2005 13:44, Tres Seaver wrote:
> Hmmm, the code in src/zope/app/component/browser has no tests at all.
> There is a 'xxx_tests' directory, which looks to have a bunch of
> now-invalid tests, moved aside by Stephan during servicegeddon.  I'll CC
> him just in case some of those tests were supposed to come back online.

Eek, thanks for the reminder. I accidentally made those 3 X's lower case, so 
my search algorithm did not find them. Could you add an issue to the 
collector? I will bring the relevant tests back online.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-08 Thread jürgen Kartnaller
Thanks Tres,
I'll give it a try.

Jürgen

Tres Seaver wrote:
> jürgen Kartnaller wrote:
> 
>>>Hi Tres,
>>>I would really like to make a test for this but I have no idea how to start.
>>>
>>>It took me 10 minutes to fix the problem but I think it will take me 10
>>>hours to write the test.
>>>
>>>If you can point me to a starting direction or just give me an example
>>>test somewhere I will give it a try !
> 
> 
> Hmmm, the code in src/zope/app/component/browser has no tests at all.
> There is a 'xxx_tests' directory, which looks to have a bunch of
> now-invalid tests, moved aside by Stephan during servicegeddon.  I'll CC
> him just in case some of those tests were supposed to come back online.
> 
> For your bug, I would start by writing a doctest for the tools.py
> module, something like:
> 
>  1. Create a 'tests' subdirectory in the 'browser' directory, and
> give it an empty '__init__.py'::
> 
> $ mkdir src/zope/app/component/browser/tests
> $ cat > src/zope/app/component/browser/tests/__init__.py
> # Python package
> ^D
> 
>  2. Add a 'tests/test_tools.py' module, with boilerplate to run
> the doctests in 'tools.txt':
> 
> $ cat > src/zope/app/component/browser/tests/test_tools.py
> import unittest
> from zope.testing import doctest
> from zope.app.testing.placelesssetup import setUp
> from zope.app.testing.placelesssetup import tearDown
> 
> def test_suite():
> return unittest.TestSuite((
> doctest.DocFileSuite('../tools.txt',
>  setUp=setUp,
>  tearDown=tearDown),
> ))
> 
> if __name__ == "__main__":
> unittest.main(defaultTest='test_suite')
> ^D
> 
>  3. Start writing 'tools.txt', documenting the behavior of the
> methods of the SiteManagementView class.  You could write only
> a test for 'delete' first, which should fail until you apply
> your patch.  Look at 'src/zope/app/component/adapterregistry.txt'
> for an example doctest file.
> 
> $ vim src/zope/app/component/browser/tools.txt
> 
>  4. Run the tests, iteratively, during development:
> 
> $ python test.py -u zope.app.component.browser
> 
>  5. Check in the new tools.txt and tests/ directory:
> 
> $ svn add src/zope/app/component/browser/tools.txt
> $ svn add src/zope/app/component/browser/tests
> $ svn commit -m "Ensure that SiteManagerView.delete doesn't\
> bite it's own tail."
> 
> 
> Hope that helps,
> 
> 
> Tres.
> --
> ===
> Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
> Palladion Software   "Excellence by Design"http://palladion.com

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



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-07 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

jürgen Kartnaller wrote:
> Hi Tres,
> I would really like to make a test for this but I have no idea how to start.
> 
> It took me 10 minutes to fix the problem but I think it will take me 10
> hours to write the test.
> 
> If you can point me to a starting direction or just give me an example
> test somewhere I will give it a try !

Hmmm, the code in src/zope/app/component/browser has no tests at all.
There is a 'xxx_tests' directory, which looks to have a bunch of
now-invalid tests, moved aside by Stephan during servicegeddon.  I'll CC
him just in case some of those tests were supposed to come back online.

For your bug, I would start by writing a doctest for the tools.py
module, something like:

 1. Create a 'tests' subdirectory in the 'browser' directory, and
give it an empty '__init__.py'::

$ mkdir src/zope/app/component/browser/tests
$ cat > src/zope/app/component/browser/tests/__init__.py
# Python package
^D

 2. Add a 'tests/test_tools.py' module, with boilerplate to run
the doctests in 'tools.txt':

$ cat > src/zope/app/component/browser/tests/test_tools.py
import unittest
from zope.testing import doctest
from zope.app.testing.placelesssetup import setUp
from zope.app.testing.placelesssetup import tearDown

def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite('../tools.txt',
 setUp=setUp,
 tearDown=tearDown),
))

if __name__ == "__main__":
unittest.main(defaultTest='test_suite')
^D

 3. Start writing 'tools.txt', documenting the behavior of the
methods of the SiteManagementView class.  You could write only
a test for 'delete' first, which should fail until you apply
your patch.  Look at 'src/zope/app/component/adapterregistry.txt'
for an example doctest file.

$ vim src/zope/app/component/browser/tools.txt

 4. Run the tests, iteratively, during development:

$ python test.py -u zope.app.component.browser

 5. Check in the new tools.txt and tests/ directory:

$ svn add src/zope/app/component/browser/tools.txt
$ svn add src/zope/app/component/browser/tests
$ svn commit -m "Ensure that SiteManagerView.delete doesn't\
bite it's own tail."


Hope that helps,


Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDRrQU+gerLs4ltQ4RAiqgAJ92CMhb4xXbKwBecyHWITI0cd7v6QCgtWUW
pLrEv+UXgRcioeQvU6r7UI8=
=lfM7
-END PGP SIGNATURE-

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



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-06 Thread jürgen Kartnaller
Hi Tres,
I would really like to make a test for this but I have no idea how to start.

It took me 10 minutes to fix the problem but I think it will take me 10
hours to write the test.

If you can point me to a starting direction or just give me an example
test somewhere I will give it a try !

Jürgen

Tres Seaver wrote:
> jürgen Kartnaller wrote:
> 
>>>When more than one utility is selected for deleting in the site
>>>management view, only the first selected utility is deleted.
>>>
>>>The problem is that the content of regManager is changed inside the
>>>while iteratating over it.
>>>Here is the fix which works for me :
>>>If this is applicable, can please someone check it into the trunk ?
>>>The file is in zope.app.component.browser
>>>
>>>---
>>>
>>>Index: tools.py
>>>===
>>>--- tools.py (revision 38746)
>>>+++ tools.py (working copy)
>>>@@ -192,7 +192,8 @@
>>> tool = self.activeTool
>>> regManager = self.context[tool.folder].registrationManager
>>> names = self.request.form['selected']
>>>-for reg in regManager.values():
>>>+values=[v for v in regManager.values()]
>>>+for reg in values:
>>> if reg.provided.isOrExtends(tool.interface) and reg.name in
>>>names:
>>> component = reg.component
>>> reg.status = interfaces.registration.InactiveStatus
>>>
>>>---
>>>
>>>Jürgen
>>>
> 
> 
> +1 for this fix, which should be applied to the 3.1 and 3.0 branches, as
> well (assuming that they have the bug).  A unit test which verified that
> multiple deletions actually worked would be ideal, of course.
> 
> 
> Tres.
> --
> ===
> Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
> Palladion Software   "Excellence by Design"http://palladion.com

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



[Zope3-dev] Re: Deleting utilities in site management doesn't work correct

2005-10-05 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

jürgen Kartnaller wrote:
> When more than one utility is selected for deleting in the site
> management view, only the first selected utility is deleted.
> 
> The problem is that the content of regManager is changed inside the
> while iteratating over it.
> Here is the fix which works for me :
> If this is applicable, can please someone check it into the trunk ?
> The file is in zope.app.component.browser
> 
> ---
> 
> Index: tools.py
> ===
> --- tools.py  (revision 38746)
> +++ tools.py  (working copy)
> @@ -192,7 +192,8 @@
>  tool = self.activeTool
>  regManager = self.context[tool.folder].registrationManager
>  names = self.request.form['selected']
> -for reg in regManager.values():
> +values=[v for v in regManager.values()]
> +for reg in values:
>  if reg.provided.isOrExtends(tool.interface) and reg.name in
> names:
>  component = reg.component
>  reg.status = interfaces.registration.InactiveStatus
> 
> ---
> 
> Jürgen
> 

+1 for this fix, which should be applied to the 3.1 and 3.0 branches, as
well (assuming that they have the bug).  A unit test which verified that
multiple deletions actually worked would be ideal, of course.


Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDRG0Q+gerLs4ltQ4RAiIvAJ0XifbHSonFIHbbGH4rGY/j6COZOgCeMrVM
Vd+MTcRa/sLNIh87EBB0nR8=
=TnZf
-END PGP SIGNATURE-

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