[Zope-CMF] Help with tests

2009-06-07 Thread Charlie Clark
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@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

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


Re: [Zope-CMF] Help with tests

2009-06-07 Thread Tres Seaver
-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  tsea...@palladion.com
Palladion Software   Excellence by Designhttp://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@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

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


Re: [Zope-CMF] Help with tests

2009-06-07 Thread Charlie Clark

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@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

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


Re: [Zope-CMF] Help with tests

2009-06-07 Thread Charlie Clark

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@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

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