Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: CMF

Help with tests

 

 

Zope cmf RSS feed   Index | Next | Previous | View Threaded


charlie at begeistert

Jun 7, 2009, 5:39 AM

Post #1 of 4 (403 views)
Permalink
Help with tests

Hi,

I'm having a little trouble with writing the tests for my formlib
folder contents view replacement. The basic tests (based on yuppie's
doctests) are fine but incomplete. I'm now integrating batching and am
getting caught on view permissions for DummyContent objects.

This is the test:

def _make_batch(self):
from Products.CMFCore.tests.base.dummy import DummyContent
batch_size = 25
for i in range(batch_size + 2):
content_id = "Dummy%s" % i
content_obj = DummyContent(content_id)
content_obj.portal_type = "Dummy Content"
obj = self.folder._setObject(content_id, content_obj)
content_obj.manage_setLocalRoles('user_foo', ['Owner'])

def test_check_batching(self):
self._make_batch()
batch_size = 25
view = ContentsView(self.folder, TestRequest())
self.assertEquals(view._getBatchObj().sequence_length,
batch_size)
self.assertEquals(view.navigation_next['title'], "NEXT N
ITEMS")

and this is error:

File "/Users/charlieclark/cmf-svn/CMF.buildout/trunk/src/Zope2/src/
AccessControl/ZopeGuards.py", line 71, in guarded_getitem
if getSecurityManager().validate(object, object, None, v):
Unauthorized: (item 0): You are not allowed to access 'Dummy0' in this
context

Obviously I don't have the permission to access my newly created
objects. So how do I go about fixing this for my tests? I can't find a
comparable example in the rest of the CMF tests? Is it best to fix the
permissions of the objects so that are viewable be "anonymous" or
should I assign my view to my user? And while I'm at it, am I creating
my dummy objects in the right way? I remember Tres saying something
about this recently.

Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


tseaver at palladion

Jun 7, 2009, 6:07 AM

Post #2 of 4 (374 views)
Permalink
Re: Help with tests [In reply to]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Charlie Clark wrote:
> Hi,
>
> I'm having a little trouble with writing the tests for my formlib
> folder contents view replacement. The basic tests (based on yuppie's
> doctests) are fine but incomplete. I'm now integrating batching and am
> getting caught on view permissions for DummyContent objects.
>
> This is the test:
>
> def _make_batch(self):
> from Products.CMFCore.tests.base.dummy import DummyContent
> batch_size = 25
> for i in range(batch_size + 2):
> content_id = "Dummy%s" % i
> content_obj = DummyContent(content_id)
> content_obj.portal_type = "Dummy Content"
> obj = self.folder._setObject(content_id, content_obj)
> content_obj.manage_setLocalRoles('user_foo', ['Owner'])
>
> def test_check_batching(self):
> self._make_batch()
> batch_size = 25
> view = ContentsView(self.folder, TestRequest())
> self.assertEquals(view._getBatchObj().sequence_length,
> batch_size)
> self.assertEquals(view.navigation_next['title'], "NEXT N
> ITEMS")
>
> and this is error:
>
> File "/Users/charlieclark/cmf-svn/CMF.buildout/trunk/src/Zope2/src/
> AccessControl/ZopeGuards.py", line 71, in guarded_getitem
> if getSecurityManager().validate(object, object, None, v):
> Unauthorized: (item 0): You are not allowed to access 'Dummy0' in this
> context
>
> Obviously I don't have the permission to access my newly created
> objects. So how do I go about fixing this for my tests? I can't find a
> comparable example in the rest of the CMF tests? Is it best to fix the
> permissions of the objects so that are viewable be "anonymous" or
> should I assign my view to my user? And while I'm at it, am I creating
> my dummy objects in the right way? I remember Tres saying something
> about this recently.

Do you need to set up a security manager with 'user_foo', grep for
'newSecurityManager' in other CMF tests.


Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver[at]palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFKK7uJ+gerLs4ltQ4RAuETAJ4k+2UXnme76ex4th3wvkp5IgqyJgCdE5Us
w4dVMlK3UgdZBMrZlmt7yyQ=
=/E3e
-----END PGP SIGNATURE-----

_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


charlie at begeistert

Jun 7, 2009, 6:26 AM

Post #3 of 4 (379 views)
Permalink
Re: Help with tests [In reply to]

Am 07.06.2009 um 15:07 schrieb Tres Seaver:

> Do you need to set up a security manager with 'user_foo', grep for
> 'newSecurityManager' in other CMF tests.


Hi Tres,

I've tried that but am not having much success:

def test_check_batching(self):
user = self.uf.getUserById('user_foo') # should be the owner
of the objects
user = user.__of__(self.uf)
newSecurityManager(None, user)
self._make_batch()
batch_size = 25
view = ContentsView(self.folder, TestRequest())
self.assertEquals(view._getBatchObj().sequence_length,
batch_size)
self.assertEquals(view.navigation_next['title'], "PREVIOUS N
ITEMS")
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


charlie at begeistert

Jun 7, 2009, 6:29 AM

Post #4 of 4 (375 views)
Permalink
Re: Help with tests [In reply to]

Am 07.06.2009 um 15:26 schrieb Charlie Clark:

> Hi Tres,
>
> I've tried that but am not having much success:


Scratch that - invoking an unrestricted user seems to do the trick:

def test_check_batching(self):
newSecurityManager(None,
UnrestrictedUser('user_foo', '', ['Manager'], ''))
self._make_batch()
batch_size = 25
view = ContentsView(self.folder, TestRequest())
self.assertEquals(view._getBatchObj().sequence_length,
batch_size)
self.assertEquals(view.navigation_next['title'], "PREVIOUS N
ITEMS")

Is this okay? At least it lets me work on the rest of the tests.

Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



_______________________________________________
Zope-CMF maillist - Zope-CMF[at]lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests

Zope cmf RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.