def test_doActionFor_mixture(self):

        wftool = self.site.portal_workflow
        wf = self._getDummyWorkflow()
        
        # This time, disallow Authenticated and Manager
        wf.states['confidential'].permission_roles = {'View': ('Authenticated', 'Manager'),}
       
        dummy = DummyContent() 
        
        # Now, if the item is normally granted to these roles
        dummy.manage_permission('View', ['Authenticated', 'Manager', 'Owner',], acquire=1)

        dummy = self.site._setObject('dummy', dummy)
        
        # These are the roles we know about
        self.assertEqual(['Anonymous', 'Authenticated', 'Manager', 'Owner'], sorted(dummy.validRoles()))
        
        self.assertEqual(wf._getStatusOf(dummy),
                         {'state': 'nonconfidential', 'comments': ''})
        
        # Then in the non-confidential state (no permissions ticked) we still have that role
        self.assertEquals(['Authenticated', 'Manager', 'Owner'], sorted(rolesForPermissionOn('View', dummy)))
                          
        wf.doActionFor(dummy, 'make_confidential', comment='foo' )
        self.assertEqual(wf._getStatusOf(dummy),
                         {'state': 'confidential', 'comments': 'foo'})
        
        # But after moving to confidential, which disallows Anonymous and Authenticated,
        # we are left with Owner and Manager
        self.assertEquals(['Owner'], sorted(rolesForPermissionOn('View', dummy)))
Beispiel #2
0
    def test_search_restrict_inactive(self):
        catalog = self._makeOne()
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob',)

        self.loginWithRoles('Blob')

        # already expired
        dummy.effective = now-4
        dummy.expires = now-2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))

        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now+3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now+3, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': (now-3, now-1), 'range': 'min:max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': (now-3, now-1), 'range': 'minmax'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-2, 'range': None})))
Beispiel #3
0
    def test_search_restrict_manager(self):
        catalog = self._makeOne()
        now = DateTime()
        dummy = DummyContent(catalog=1)

        self.loginManager()

        # already expired
        dummy.effective = now-4
        dummy.expires = now-2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(1, len(catalog.searchResults()))

        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-1, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-1, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': (now-3, now-1), 'range': 'min:max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': (now-3, now-1), 'range': 'minmax'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-2})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-2, 'range': None})))
Beispiel #4
0
    def test_manageDelObjects(self):
        test = self._makeOne('test')
        foo = DummyContent('foo')

        test._setObject('foo', foo)
        foo.reset()
        test.manage_delObjects( ids=['foo'] )
        self.failIf( foo.after_add_called )
        self.failUnless( foo.before_delete_called )
Beispiel #5
0
    def test_manageDelObjects( self ):

        test = self.root.test
        foo = DummyContent( 'foo' )

        test._setObject( 'foo', foo )
        foo.reset()
        test.manage_delObjects( ids=[ 'foo' ] )
        assert not foo.after_add_called
        assert foo.before_delete_called
Beispiel #6
0
    def test_search_member_wo_valid_roles(self):
        catalog = self._makeOne()
        catalog.addIndex('allowedRolesAndUsers', 'KeywordIndex')
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob',)
        catalog.catalog_object(dummy, '/dummy')

        self.loginWithRoles('Waggle')

        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))
Beispiel #7
0
    def test_manageDelObjects(self):
        acl_users = self.site._setObject('acl_users', DummyUserFolder())
        newSecurityManager(None, acl_users.all_powerful_Oz)
        test = self._makeOne('test')
        foo = DummyContent('foo')

        test._setObject('foo', foo)
        foo.reset()
        test.manage_delObjects(ids=['foo'])
        self.assertFalse(foo.after_add_called)
        self.assertTrue(foo.before_delete_called)
Beispiel #8
0
 def __init__(self, id='dummy', opaqueItem=None, *args, **kw):
     OriginalDummyContent.__init__(self, id, *args, **kw)
     if opaqueItem is None:
         self.opaqueItem = 'noncallable'
         self.opaqueItemsId = 'opaqueItem'
     elif isinstance(opaqueItem, basestring):
         Hooks(self, opaqueItem)
         self.opaqueItemsId = opaqueItem
     else:
         opaqueItem(self, 'opaqueItem')
         self.opaqueItemsId = 'opaqueItem'
Beispiel #9
0
 def __init__(self, id="dummy", opaqueItem=None, *args, **kw):
     OriginalDummyContent.__init__(self, id, *args, **kw)
     if opaqueItem is None:
         self.opaqueItem = "noncallable"
         self.opaqueItemsId = "opaqueItem"
     elif isinstance(opaqueItem, basestring):
         Hooks(self, opaqueItem)
         self.opaqueItemsId = opaqueItem
     else:
         opaqueItem(self, "opaqueItem")
         self.opaqueItemsId = "opaqueItem"
Beispiel #10
0
    def test_mergedLocalRolesManipulation(self):
        # The _mergedLocalRoles function used to return references to
        # actual local role settings and it was possible to manipulate them
        # by changing the return value. http://www.zope.org/Collectors/CMF/376
        from Products.CMFCore.tests.base.dummy import DummyContent
        from Products.CMFCore.utils import _mergedLocalRoles
        obj = DummyContent()
        obj.manage_addLocalRoles('dummyuser1', ['Manager', 'Owner'])
        self.assertEqual(len(obj.get_local_roles_for_userid('dummyuser1')), 2)

        merged_roles = _mergedLocalRoles(obj)
        merged_roles['dummyuser1'].append('FOO')

        # The values on the object itself should still the the same
        self.assertEqual(len(obj.get_local_roles_for_userid('dummyuser1')), 2)
Beispiel #11
0
    def test_304_response_from_cpm(self):
        # test that we get a 304 response from the cpm via this template
        mod_time = DateTime()
        cpm = DummyCachingManagerWithPolicy()
        getSiteManager().registerUtility(cpm, ICachingPolicyManager)
        content = DummyContent(id='content')
        content.modified_date = mod_time
        content = content.__of__(self.app)
        script = self._makeOne('testDTML', 'testDTML.dtml')
        script = script.__of__(content)
        self.REQUEST.environ['IF_MODIFIED_SINCE'
                            ] = '%s;' % rfc1123_date(mod_time + 3600)
        data = script(content, self.REQUEST, self.RESPONSE)

        self.assertEqual(data, '')
        self.assertEqual(self.RESPONSE.getStatus(), 304)
Beispiel #12
0
    def test_304_response_from_cpm(self):
        # test that we get a 304 response from the cpm via this template

        from webdav.common import rfc1123_date

        mod_time = DateTime()
        self.root.caching_policy_manager = DummyCachingManagerWithPolicy()
        content = DummyContent(id="content")
        content.modified_date = mod_time
        content = content.__of__(self.root)
        script = self._makeOne("testDTML", "testDTML.dtml")
        script = script.__of__(content)
        self.REQUEST.environ["IF_MODIFIED_SINCE"] = "%s;" % rfc1123_date(mod_time + 3600)
        data = script(content, self.REQUEST, self.RESPONSE)

        self.assertEqual(data, "")
        self.assertEqual(self.RESPONSE.getStatus(), 304)
    def test_doActionFor_anonymous(self):

        wftool = self.site.portal_workflow
        wf = self._getDummyWorkflow()

        dummy = DummyContent()
        
        # Now, if the item is normally granted to anonymous...
        dummy.manage_permission('View', ['Anonymous'], acquire=1)

        dummy = self.site._setObject('dummy', dummy)
        
        # These are the roles we know about
        self.assertEquals(['Anonymous', 'Authenticated', 'Manager', 'Owner'], sorted(dummy.validRoles()))
        
        self.assertEqual( wf._getStatusOf(dummy),
                          {'state': 'confidential', 'comments': ''} )
        
        self.assertEquals(['Manager', 'Owner'], sorted(rolesForPermissionOn('View', dummy)))
Beispiel #14
0
    def test_deletePropagation(self):
        test = self._makeOne('test')
        foo = DummyContent('foo')
        foo.reset()
        self.failIf(foo.after_add_called)
        self.failIf(foo.before_delete_called)

        test._setObject('foo', foo)
        self.failUnless(foo.after_add_called)
        self.failIf(foo.before_delete_called)

        foo.reset()
        test._delObject('foo')
        self.failIf(foo.after_add_called)
        self.failUnless(foo.before_delete_called)

        foo.reset()
        test._setObject('foo', foo)
        test._delOb('foo')  # doesn't propagate
        self.failUnless(foo.after_add_called)
        self.failIf(foo.before_delete_called)
Beispiel #15
0
    def afterSetUp(self):
        setSite(self.app.site)
        self.site = self.app.site
        self.site._setObject('topic', Topic('topic'))
        self.topic = self.site.topic
        self.topic.addCriterion('modified', 'Friendly Date Criterion')
        self.topic.addCriterion('portal_type', 'String Criterion')
        type_crit = self.topic.getCriterion('portal_type')
        type_crit.edit(value='Dummy Content')
        self.criterion = self.topic.getCriterion('modified')
        self.now = DateTime()

        for i in self.day_diffs:
            dummy_id = 'dummy%i' % i
            self.site._setObject(dummy_id, DummyContent(id=dummy_id,
                                                        catalog=1))
            dummy_ob = getattr(self.site, dummy_id)
            dummy_ob.modified_date = self.now + i
            dummy_ob.reindexObject()
    def test_wrapping3(self):
        # DummyContent does not implement IIndexableObject
        # wrapper registered - should look this up
        from Products.CMFCore.interfaces import ICatalogTool
        from Products.CMFCore.interfaces import IIndexableObject

        def FakeWrapper(object, catalog):
            return object

        sm = getSiteManager()
        sm.registerAdapter(FakeWrapper, (IContentish, ICatalogTool),
                           IIndexableObject)

        dummy = DummyContent(catalog=1)
        ctool = self._makeOne()
        ctool.addIndex('meta_type', 'FieldIndex')
        ctool.catalog_object(dummy, '/dummy')
        query = {'meta_type': 'Dummy'}
        self.assertEqual(1, len(ctool._catalog.searchResults(query)))
Beispiel #17
0
    def test_checkTransitionGuard(self):
        wtool = self.wtool
        wf = self._getDummyWorkflow()
        dummy = self.site._setObject('dummy', DummyContent())
        wtool.notifyCreated(dummy)
        self.assertEqual(wf._getStatusOf(dummy), {
            'state': 'private',
            'comments': ''
        })

        # Check
        self.assertTrue(
            wf._checkTransitionGuard(wf.transitions['publish'], dummy))

        # Check with kwargs propagation
        self.assertTrue(
            wf._checkTransitionGuard(wf.transitions['publish'],
                                     dummy,
                                     arg1=1,
                                     arg2=2))
Beispiel #18
0
    def test_deletePropagation(self):

        test = self.root.test
        foo = DummyContent('foo')

        foo.reset()
        assert not foo.after_add_called
        assert not foo.before_delete_called
        test._setObject('foo', foo)
        assert foo.after_add_called
        assert not foo.before_delete_called

        foo.reset()
        test._delObject('foo')
        assert not foo.after_add_called
        assert foo.before_delete_called

        foo.reset()
        test._setObject('foo', foo)
        test._delOb('foo')  # doesn't propagate
        assert foo.after_add_called
        assert not foo.before_delete_called
Beispiel #19
0
    def setUp(self):

        SecurityTest.setUp(self)

        root = self.root
        root._setObject('portal_discussion', DiscussionTool())
        self.discussion_tool = root.portal_discussion
        root._setObject('portal_catalog', CatalogTool())
        self.catalog_tool = root.portal_catalog
        root._setObject('portal_url', URLTool())
        self.url_tool = root.portal_url
        root._setObject('portal_workflow', WorkflowTool())
        self.workflow_tool = root.portal_workflow
        root._setObject('portal_types', TypesTool())
        types_tool = self.types_tool = root.portal_types
        try:
            root._delObject('test')
        except AttributeError:
            pass
        root._setObject('test', DummyContent('test', catalog=1))
Beispiel #20
0
    def setUp(self):
        RequestTest.setUp(self)
        self.root.manage_addProduct['CMFDefault'].manage_addCMFSite('site')
        self.site = self.root.site
        self.site._setObject('topic', Topic('topic'))
        self.topic = self.site.topic
        self.topic.addCriterion('modified', 'Friendly Date Criterion')
        self.topic.addCriterion('portal_type', 'String Criterion')
        type_crit = self.topic.getCriterion('portal_type')
        type_crit.edit(value='Dummy Content')
        self.criterion = self.topic.getCriterion('modified')
        self.now = DateTime()

        for i in self.day_diffs:
            dummy_id = 'dummy%i' % i
            self.site._setObject(dummy_id, DummyContent(id=dummy_id,
                                                        catalog=1))
            dummy_ob = getattr(self.site, dummy_id)
            dummy_ob.modified_date = self.now + i
            dummy_ob.reindexObject()
    def test_mergedLocalRolesManipulation(self):
        # The _mergedLocalRoles function used to return references to
        # actual local role settings and it was possible to manipulate them
        # by changing the return value. http://www.zope.org/Collectors/CMF/376
        from Products.CMFCore.tests.base.dummy import DummyContent
        from Products.CMFCore.utils import _mergedLocalRoles
        obj = DummyContent()
        obj.manage_addLocalRoles('dummyuser1', ['Manager', 'Owner'])
        self.assertEqual(len(obj.get_local_roles_for_userid('dummyuser1')), 2)

        merged_roles = _mergedLocalRoles(obj)
        merged_roles['dummyuser1'].append('FOO')

        # The values on the object itself should still the the same
        self.assertEqual(len(obj.get_local_roles_for_userid('dummyuser1')), 2)
Beispiel #22
0
    def test_catalogUnindexAndIndex(self):
        #
        # Test is a new object does get cataloged upon _setObject
        # and uncataloged upon manage_deleteObjects
        #
        test = self._makeOne('test')
        ttool = self.site._setObject( 'portal_types', TypesTool() )
        ctool = self.site._setObject( 'portal_catalog', CatalogTool() )
        self.assertEqual( len(ctool), 0 )

        test._setObject( 'foo', DummyContent( 'foo' , catalog=1 ) )
        foo = test.foo
        self.failUnless( foo.after_add_called )
        self.failIf( foo.before_delete_called )
        self.assertEqual( len(ctool), 1 )

        foo.reset()
        test._delObject('foo')
        self.failIf( foo.after_add_called )
        self.failUnless( foo.before_delete_called )
        self.assertEqual( len(ctool), 0 )
Beispiel #23
0
    def test_deletePropagation(self):
        acl_users = self.site._setObject('acl_users', DummyUserFolder())
        newSecurityManager(None, acl_users.all_powerful_Oz)
        test = self._makeOne('test')
        foo = DummyContent('foo')
        foo.reset()
        self.assertFalse(foo.after_add_called)
        self.assertFalse(foo.before_delete_called)

        test._setObject('foo', foo)
        self.assertTrue(foo.after_add_called)
        self.assertFalse(foo.before_delete_called)

        foo.reset()
        test._delObject('foo')
        self.assertFalse(foo.after_add_called)
        self.assertTrue(foo.before_delete_called)

        foo.reset()
        test._setObject('foo', foo)
        test._delOb('foo')  # doesn't propagate
        self.assertTrue(foo.after_add_called)
        self.assertFalse(foo.before_delete_called)
Beispiel #24
0
    def test_deletePropagation(self):
        test = self._makeOne('test')
        foo = DummyContent('foo')
        foo.reset()
        self.failIf( foo.after_add_called )
        self.failIf( foo.before_delete_called )

        test._setObject('foo', foo)
        self.failUnless( foo.after_add_called )
        self.failIf( foo.before_delete_called )

        foo.reset()
        test._delObject('foo')
        self.failIf( foo.after_add_called )
        self.failUnless( foo.before_delete_called )

        foo.reset()
        test._setObject('foo', foo)
        test._delOb('foo')    # doesn't propagate
        self.failUnless( foo.after_add_called )
        self.failIf( foo.before_delete_called )
Beispiel #25
0
    def test_search_inactive(self):
        catalog = CatalogTool()
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob', )

        self.loginWithRoles('Blob')

        # not yet effective
        dummy.effective = now + 1
        dummy.expires = now + 2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))

        # already expired
        dummy.effective = now - 2
        dummy.expires = now - 1
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))
Beispiel #26
0
    def test_listActions_passes_all_context_information_to_TIs(self):
        from zope.interface import implements
        from Products.CMFCore.interfaces import ITypeInformation
        from Products.CMFCore.tests.base.dummy import DummyContent

        class ActionTesterTypeInfo:
            implements(ITypeInformation)
            id = 'Dummy Content'

            def listActions(self, info=None, obj=None):
                self._action_info = info
                self._action_obj = obj
                return ()

        ti = ActionTesterTypeInfo()
        tool = self._makeOne()
        setattr( tool, 'Dummy Content', ti )

        dummy = DummyContent('dummy')
        tool.listActions('fake_info', dummy)

        self.assertEqual(ti._action_info, 'fake_info')
        self.assertEqual(ti._action_obj, dummy)
Beispiel #27
0
    def test_deletePropagation( self ):

        test = self.root.test
        foo = DummyContent( 'foo' )

        foo.reset()
        assert not foo.after_add_called
        assert not foo.before_delete_called
        test._setObject( 'foo', foo )
        assert foo.after_add_called
        assert not foo.before_delete_called

        foo.reset()
        test._delObject( 'foo' )
        assert not foo.after_add_called
        assert foo.before_delete_called

        foo.reset()
        test._setObject( 'foo', foo )
        test._delOb( 'foo' )    # doesn't propagate
        assert foo.after_add_called
        assert not foo.before_delete_called
Beispiel #28
0
    def test_contentPasteAllowedTypes(self):
        #
        #   Does _verifyObjectPaste check allowed content types?
        #
        test = self.root.test
        self.root._setObject('portal_types', TypesTool())

        types_tool = self.root.portal_types
        types_tool._setObject('Dummy Content', DummyFTI)
        types_tool._setObject(
            'Folder',
            FTI(id='Folder',
                title='Folder or Directory',
                meta_type=PortalFolder.meta_type,
                product='CMFCore',
                factory='manage_addPortalFolder',
                filter_content_types=0))

        test._setObject('sub1', PortalFolder('sub1', ''))
        sub1 = test.sub1
        sub1._setObject('dummy', DummyContent('dummy'))

        test._setObject('sub2', PortalFolder('sub2', ''))
        sub2 = test.sub2
        sub2.all_meta_types = extra_meta_types()

        # Copy/paste should work fine
        cookie = sub1.manage_copyObjects(ids=('dummy', ))
        sub2.manage_pasteObjects(cookie)

        # Disallow adding of Dummy Content
        types_tool.Folder.manage_changeProperties(filter_content_types=1)

        # Now copy/paste should raise a ValueError
        cookie = sub1.manage_copyObjects(ids=('dummy', ))
        self.assertRaises(ValueError, sub2.manage_pasteObjects, cookie)
Beispiel #29
0
    def test_contentPasteAllowedTypes(self):
        #
        #   _verifyObjectPaste() should honor allowed content types
        #
        from Products.CMFCore.PortalFolder import PortalFolder

        test = self.root.test

        self.root._setObject('portal_types', TypesTool())
        types_tool = self.root.portal_types

        fti = FTIDATA_DUMMY[0].copy()
        types_tool._setObject('Dummy Content', FTI(**fti))
        types_tool._setObject('Folder', FTI(**fti))

        test._setObject('sub1', PortalFolder('sub1', ''))
        sub1 = test.sub1
        sub1._setObject('dummy', DummyContent('dummy'))

        test._setObject('sub2', PortalFolder('sub2', ''))
        sub2 = test.sub2
        sub2.all_meta_types = extra_meta_types()

        # Allow adding of Dummy Content
        types_tool.Folder.manage_changeProperties(filter_content_types=False)

        # Copy/paste should work fine
        cookie = sub1.manage_copyObjects(ids=('dummy', ))
        sub2.manage_pasteObjects(cookie)

        # Disallow adding of Dummy Content
        types_tool.Folder.manage_changeProperties(filter_content_types=True)

        # Now copy/paste should raise a ValueError
        cookie = sub1.manage_copyObjects(ids=('dummy', ))
        self.assertRaises(ValueError, sub2.manage_pasteObjects, cookie)
Beispiel #30
0
    def test_deletePropagation(self):
        acl_users = self.site._setObject('acl_users', DummyUserFolder())
        newSecurityManager(None, acl_users.all_powerful_Oz)
        test = self._makeOne('test')
        foo = DummyContent('foo')
        foo.reset()
        self.assertFalse(foo.after_add_called)
        self.assertFalse(foo.before_delete_called)

        test._setObject('foo', foo)
        self.assertTrue(foo.after_add_called)
        self.assertFalse(foo.before_delete_called)

        foo.reset()
        test._delObject('foo')
        self.assertFalse(foo.after_add_called)
        self.assertTrue(foo.before_delete_called)

        foo.reset()
        test._setObject('foo', foo)
        test._delOb('foo')    # doesn't propagate
        self.assertTrue(foo.after_add_called)
        self.assertFalse(foo.before_delete_called)
Beispiel #31
0
    def test_search_inactive(self):
        catalog = self._makeOne()
        catalog.addIndex('allowedRolesAndUsers', 'KeywordIndex')
        catalog.addIndex('effective', 'DateIndex')
        catalog.addIndex('expires', 'DateIndex')
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob',)

        self.loginWithRoles('Blob')

        # not yet effective
        dummy.effective = now+1
        dummy.expires = now+2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))

        # already expired
        dummy.effective = now-2
        dummy.expires = now-1
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))
Beispiel #32
0
    def test_search_inactive(self):
        catalog = self._makeOne()
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob',)

        self.loginWithRoles('Blob')

        # not yet effective
        dummy.effective = now+1
        dummy.expires = now+2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))

        # already expired
        dummy.effective = now-2
        dummy.expires = now-1
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(0, len(catalog.searchResults()))
Beispiel #33
0
 def _makeDummyContent(self, id, *args, **kw):
     return self.site._setObject(id, DummyContent(id, *args, **kw))
Beispiel #34
0
    def test_events(self):

        events = []

        @adapter(IBeforeTransitionEvent)
        def _handleBefore(event):
            events.append(event)

        provideHandler(_handleBefore)

        @adapter(IAfterTransitionEvent)
        def _handleAfter(event):
            events.append(event)

        provideHandler(_handleAfter)

        wftool = self.site.portal_workflow
        wf = self._getDummyWorkflow()

        dummy = self.site._setObject('dummy', DummyContent())
        wftool.notifyCreated(dummy)
        wf.doActionFor(dummy, 'publish', comment='foo', test='bar')

        self.assertEquals(4, len(events))

        evt = events[0]
        self.failUnless(IBeforeTransitionEvent.providedBy(evt))
        self.assertEquals(dummy, evt.object)
        self.assertEquals('private', evt.old_state.id)
        self.assertEquals('private', evt.new_state.id)
        self.assertEquals(None, evt.transition)
        self.assertEquals({}, evt.status)
        self.assertEquals(None, evt.kwargs)

        evt = events[1]
        self.failUnless(IAfterTransitionEvent.providedBy(evt))
        self.assertEquals(dummy, evt.object)
        self.assertEquals('private', evt.old_state.id)
        self.assertEquals('private', evt.new_state.id)
        self.assertEquals(None, evt.transition)
        self.assertEquals({'state': 'private', 'comments': ''}, evt.status)
        self.assertEquals(None, evt.kwargs)

        evt = events[2]
        self.failUnless(IBeforeTransitionEvent.providedBy(evt))
        self.assertEquals(dummy, evt.object)
        self.assertEquals('private', evt.old_state.id)
        self.assertEquals('published', evt.new_state.id)
        self.assertEquals('publish', evt.transition.id)
        self.assertEquals({'state': 'private', 'comments': ''}, evt.status)
        self.assertEquals({'test': 'bar', 'comment': 'foo'}, evt.kwargs)

        evt = events[3]
        self.failUnless(IAfterTransitionEvent.providedBy(evt))
        self.assertEquals(dummy, evt.object)
        self.assertEquals('private', evt.old_state.id)
        self.assertEquals('published', evt.new_state.id)
        self.assertEquals('publish', evt.transition.id)
        self.assertEquals({
            'state': 'published',
            'comments': 'foo'
        }, evt.status)
        self.assertEquals({'test': 'bar', 'comment': 'foo'}, evt.kwargs)
Beispiel #35
0
 def setUp( self ):
     self.dummy=DummyContent('Dummy')
Beispiel #36
0
    def _makeContent(self, *args, **kw):
        from Products.CMFCore.tests.base.dummy import DummyContent

        return DummyContent(*args, **kw)
Beispiel #37
0
 def _make_one(self, name="DummyItem"):
     content = DummyContent(name)
     content.portal_type = "Dummy Content"
     self.folder._setObject(name, content)
Beispiel #38
0
 def setUp(self):
     SecurityTest.setUp(self)
     self.root._setObject('portal_uidannotation', UniqueIdAnnotationTool())
     self.root._setObject('dummy', DummyContent(id='dummy'))
Beispiel #39
0
 def setUp(self):
     SecurityTest.setUp(self)
     setUpEvents()
     self.root._setObject('portal_uidannotation', self._getTargetClass()())
     self.root._setObject('dummy', DummyContent(id='dummy'))
Beispiel #40
0
    def test_search_restrict_visible(self):
        catalog = CatalogTool()
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob',)

        self.loginWithRoles('Blob')

        # visible
        dummy.effective = now-2
        dummy.expires = now+2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(1, len(catalog.searchResults()))

        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now-1, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now-1, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now+1, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now+1, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': (now-1, now+1), 'range': 'min:max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': (now-1, now+1), 'range': 'minmax'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-2, 'range': None})))

        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now-3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now-3, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now+3, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now+3, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': (now-3, now+3), 'range': 'min:max'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': (now-3, now+3), 'range': 'minmax'})))

        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-1, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-1, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now+1, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now+1, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': (now-1, now+1), 'range': 'min:max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': (now-1, now+1), 'range': 'minmax'})))

        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now+3, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now+3, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': (now-3, now+3), 'range': 'min:max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': (now-3, now+3), 'range': 'minmax'})))

        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now-1, 'range': 'max'},
            expires={'query': now+1, 'range': 'min'})))

        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now+1, 'range': 'max'},
            expires={'query': now+3, 'range': 'min'})))
Beispiel #41
0
    def test_search_restrict_visible(self):
        catalog = self._makeOne()
        catalog.addIndex('allowedRolesAndUsers', 'KeywordIndex')
        catalog.addIndex('effective', 'DateIndex')
        catalog.addIndex('expires', 'DateIndex')
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob',)

        self.loginWithRoles('Blob')

        # visible
        dummy.effective = now-2
        dummy.expires = now+2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(1, len(catalog.searchResults()))

        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now-1, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now-1, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now+1, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now+1, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': (now-1, now+1), 'range': 'min:max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': (now-1, now+1), 'range': 'minmax'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-2, 'range': None})))

        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now-3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now-3, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now+3, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now+3, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': (now-3, now+3), 'range': 'min:max'})))
        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': (now-3, now+3), 'range': 'minmax'})))

        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-1, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-1, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now+1, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now+1, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': (now-1, now+1), 'range': 'min:max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': (now-1, now+1), 'range': 'minmax'})))

        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'min'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now-3, 'range': 'max'})))
        self.assertEqual(0, len(catalog.searchResults(
            expires={'query': now+3, 'range': 'min'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': now+3, 'range': 'max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': (now-3, now+3), 'range': 'min:max'})))
        self.assertEqual(1, len(catalog.searchResults(
            expires={'query': (now-3, now+3), 'range': 'minmax'})))

        self.assertEqual(1, len(catalog.searchResults(
            effective={'query': now-1, 'range': 'max'},
            expires={'query': now+1, 'range': 'min'})))

        self.assertEqual(0, len(catalog.searchResults(
            effective={'query': now+1, 'range': 'max'},
            expires={'query': now+3, 'range': 'min'})))
Beispiel #42
0
    def test_search_restrict_visible(self):
        catalog = CatalogTool()
        now = DateTime()
        dummy = DummyContent(catalog=1)
        dummy._View_Permission = ('Blob', )

        self.loginWithRoles('Blob')

        # visible
        dummy.effective = now - 2
        dummy.expires = now + 2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(1, len(catalog.searchResults()))

        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': now - 1,
                    'range': 'min'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': now - 1,
                    'range': 'max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': now + 1,
                    'range': 'min'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': now + 1,
                    'range': 'max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': (now - 1, now + 1),
                    'range': 'min:max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': (now - 1, now + 1),
                    'range': 'minmax'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now - 2,
                    'range': None
                })))

        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': now - 3,
                    'range': 'min'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': now - 3,
                    'range': 'max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': now + 3,
                    'range': 'min'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': now + 3,
                    'range': 'max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': (now - 3, now + 3),
                    'range': 'min:max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': (now - 3, now + 3),
                    'range': 'minmax'
                })))

        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now - 1,
                    'range': 'min'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': now - 1,
                    'range': 'max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now + 1,
                    'range': 'min'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': now + 1,
                    'range': 'max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': (now - 1, now + 1),
                    'range': 'min:max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': (now - 1, now + 1),
                    'range': 'minmax'
                })))

        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now - 3,
                    'range': 'min'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': now - 3,
                    'range': 'max'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': now + 3,
                    'range': 'min'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now + 3,
                    'range': 'max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': (now - 3, now + 3),
                    'range': 'min:max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': (now - 3, now + 3),
                    'range': 'minmax'
                })))

        self.assertEqual(
            1,
            len(
                catalog.searchResults(effective={
                    'query': now - 1,
                    'range': 'max'
                },
                                      expires={
                                          'query': now + 1,
                                          'range': 'min'
                                      })))

        self.assertEqual(
            0,
            len(
                catalog.searchResults(effective={
                    'query': now + 1,
                    'range': 'max'
                },
                                      expires={
                                          'query': now + 3,
                                          'range': 'min'
                                      })))
Beispiel #43
0
 def _make_one(self, name="DummyItem"):
     content = DummyContent(name)
     content.portal_type = "Dummy Content"
     self.folder._setObject(name, content)
Beispiel #44
0
    def test_search_restrict_manager(self):
        catalog = CatalogTool()
        now = DateTime()
        dummy = DummyContent(catalog=1)

        self.loginManager()

        # already expired
        dummy.effective = now - 4
        dummy.expires = now - 2
        catalog.catalog_object(dummy, '/dummy')
        self.assertEqual(1, len(catalog._catalog.searchResults()))
        self.assertEqual(1, len(catalog.searchResults()))

        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now - 3,
                    'range': 'min'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': now - 1,
                    'range': 'min'
                })))
        self.assertEqual(
            0,
            len(
                catalog.searchResults(expires={
                    'query': now - 3,
                    'range': 'max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now - 1,
                    'range': 'max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': (now - 3, now - 1),
                    'range': 'min:max'
                })))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': (now - 3, now - 1),
                    'range': 'minmax'
                })))
        self.assertEqual(
            1, len(catalog.searchResults(expires={'query': now - 2})))
        self.assertEqual(
            1,
            len(
                catalog.searchResults(expires={
                    'query': now - 2,
                    'range': None
                })))
Beispiel #45
0
 def test_proxied_attributes(self):
     obj = DummyContent('foo')
     obj.title = 'Foo'
     w = self._makeOne({}, obj)
     self.assertEqual(w.getId(), 'foo')
     self.assertEqual(w.Title(), 'Foo')
Beispiel #46
0
 def test_vars(self):
     obj = DummyContent()
     w = self._makeOne({'bar': 1, 'baz': 2}, obj)
     self.assertEqual(w.bar, 1)
     self.assertEqual(w.baz, 2)
Beispiel #47
0
 def _makeContent(self, *args, **kw):
     return DummyContent(*args, **kw)
Beispiel #48
0
 def test___str__(self):
     obj = DummyContent('foo')
     w = self._makeOne({}, obj)
     self.assertEqual(str(w), str(obj))
    def setUp(self):
        from Products.CMFCore import CachingPolicyManager

        PlacelessSetup.setUp(self)
        RequestTest.setUp(self)
        FSDVTest.setUp(self)
        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('permissions.zcml', Products.Five)
        zcml.load_config('configure.zcml', Products.CMFCore)
        zcml.load_string(_TRAVERSE_ZCML)

        now = DateTime()

        # Create a fake portal and the tools we need
        self.portal = DummySite(id='portal').__of__(self.root)
        self.portal._setObject('portal_types', DummyTool())

        # This is a FSPageTemplate that will be used as the View for
        # our content objects. It doesn't matter what it returns.
        path = os.path.join(self.skin_path_name, 'testPT2.pt')
        self.portal._setObject('dummy_view',
                               FSPageTemplate('dummy_view', path))

        uf = self.root.acl_users
        password = '******'
        uf.userFolderAddUser(portal_owner, password, ['Manager'], [])
        user = uf.getUserById(portal_owner)
        if not hasattr(user, 'aq_base'):
            user = user.__of__(uf)
        newSecurityManager(None, user)
        owner_auth = '%s:%s' % (portal_owner, password)
        self.auth_header = "Basic %s" % base64.encodestring(owner_auth)

        self.portal._setObject('doc1', DummyContent('doc1'))
        self.portal._setObject('doc2', DummyContent('doc2'))
        self.portal._setObject('doc3', DummyContent('doc3'))
        self.portal.doc1.modified_date = now
        self.portal.doc2.modified_date = now
        self.portal.doc3.modified_date = now

        CachingPolicyManager.manage_addCachingPolicyManager(self.portal)
        cpm = self.portal.caching_policy_manager

        # This policy only applies to doc1. It will not emit any ETag header
        # but it enables If-modified-since handling.
        cpm.addPolicy(policy_id='policy_no_etag',
                      predicate='python:object.getId()=="doc1"',
                      mtime_func='',
                      max_age_secs=0,
                      no_cache=0,
                      no_store=0,
                      must_revalidate=0,
                      vary='',
                      etag_func='',
                      enable_304s=1)

        # This policy only applies to doc2. It will emit an ETag with
        # the constant value "abc" and also enable if-modified-since handling.
        cpm.addPolicy(policy_id='policy_etag',
                      predicate='python:object.getId()=="doc2"',
                      mtime_func='',
                      max_age_secs=0,
                      no_cache=0,
                      no_store=0,
                      must_revalidate=0,
                      vary='',
                      etag_func='string:abc',
                      enable_304s=1)

        # This policy only applies to doc3. Etags with constant values of
        # "abc" are emitted, but if-modified-since handling is turned off.
        cpm.addPolicy(policy_id='policy_disabled',
                      predicate='python:object.getId()=="doc3"',
                      mtime_func='',
                      max_age_secs=0,
                      no_cache=0,
                      no_store=0,
                      must_revalidate=0,
                      vary='',
                      etag_func='string:abc',
                      enable_304s=0)