Exemple #1
0
 def test_workflow_transition_from_custom(self):
     registerDummyRenderer('templates/edit_acl.pt')
     from repoze.workflow.testing import DummyWorkflow
     from zope.interface import Interface
     from zope.interface import directlyProvides
     workflow = DummyWorkflow()
     def state_info(context, request):
         return [{'name': 'foo', 'current': True, 'transitions': True},
                 {'name': 'bar', 'current': False, 'transitions': True}]
     workflow.state_info = state_info
     def get_dummy_workflow(*args, **kw):
         return workflow
     import karl.views.acl
     old_f = karl.views.acl.get_context_workflow
     karl.views.acl.get_context_workflow = get_dummy_workflow
     try:
         context = testing.DummyModel()
         context.state = 'foo'
         context.__custom_acl__ = []
         directlyProvides(Interface)
         request = testing.DummyRequest()
         request.POST['form.security_state'] = 1
         request.POST['security_state'] = 'bar'
         self._callFUT(context, request)
         self.assertEqual(workflow.transitioned[0]['to_state'], 'bar')
         self.assertEqual(workflow.resetted, [context,])
         self.failIf(hasattr(context, '__custom_acl__'))
     finally:
         karl.views.acl.get_context_workflow = old_f
Exemple #2
0
 def test_show_workflow_custom_acl(self):
     from repoze.workflow.testing import DummyWorkflow
     from zope.interface import Interface
     from zope.interface import directlyProvides
     workflow = DummyWorkflow()
     def state_info(context, request):
         return [{'name': 'foo', 'current': True, 'transitions': True},
                 {'name': 'bar', 'current': False, 'transitions': True}]
     workflow.state_info = state_info
     def get_dummy_workflow(*args, **kw):
         return workflow
     import karl.views.acl
     old_f = karl.views.acl.get_context_workflow
     karl.views.acl.get_context_workflow = get_dummy_workflow
     try:
         context = testing.DummyModel()
         context.state = 'foo'
         context.__custom_acl__ = []
         directlyProvides(Interface)
         request = testing.DummyRequest()
         renderer = karl.testing.registerDummyRenderer('templates/edit_acl.pt')
         self._callFUT(context, request)
         self.assertEqual(renderer.security_state, 'CUSTOM')
         self.assertEqual(renderer.security_states, ['CUSTOM', 'foo', 'bar'])
     finally:
         karl.views.acl.get_context_workflow = old_f
Exemple #3
0
    def test_workflow_transition_from_custom(self):
        registerDummyRenderer('templates/edit_acl.pt')
        from repoze.workflow.testing import DummyWorkflow
        from zope.interface import Interface
        from zope.interface import directlyProvides
        workflow = DummyWorkflow()

        def state_info(context, request):
            return [{
                'name': 'foo',
                'current': True,
                'transitions': True
            }, {
                'name': 'bar',
                'current': False,
                'transitions': True
            }]

        workflow.state_info = state_info

        def get_dummy_workflow(*args, **kw):
            return workflow

        import karl.views.acl
        old_f = karl.views.acl.get_context_workflow
        karl.views.acl.get_context_workflow = get_dummy_workflow
        try:
            context = testing.DummyModel()
            context.state = 'foo'
            context.__custom_acl__ = []
            directlyProvides(Interface)
            request = testing.DummyRequest()
            request.POST['form.security_state'] = 1
            request.POST['security_state'] = 'bar'
            self._callFUT(context, request)
            self.assertEqual(workflow.transitioned[0]['to_state'], 'bar')
            self.assertEqual(workflow.resetted, [
                context,
            ])
            self.failIf(hasattr(context, '__custom_acl__'))
        finally:
            karl.views.acl.get_context_workflow = old_f
Exemple #4
0
    def test_show_workflow_custom_acl(self):
        from repoze.workflow.testing import DummyWorkflow
        from zope.interface import Interface
        from zope.interface import directlyProvides
        workflow = DummyWorkflow()

        def state_info(context, request):
            return [{
                'name': 'foo',
                'current': True,
                'transitions': True
            }, {
                'name': 'bar',
                'current': False,
                'transitions': True
            }]

        workflow.state_info = state_info

        def get_dummy_workflow(*args, **kw):
            return workflow

        import karl.views.acl
        old_f = karl.views.acl.get_context_workflow
        karl.views.acl.get_context_workflow = get_dummy_workflow
        try:
            context = testing.DummyModel()
            context.state = 'foo'
            context.__custom_acl__ = []
            directlyProvides(Interface)
            request = testing.DummyRequest()
            renderer = karl.testing.registerDummyRenderer(
                'templates/edit_acl.pt')
            self._callFUT(context, request)
            self.assertEqual(renderer.security_state, 'CUSTOM')
            self.assertEqual(renderer.security_states,
                             ['CUSTOM', 'foo', 'bar'])
        finally:
            karl.views.acl.get_context_workflow = old_f
Exemple #5
0
    def _mk_dummy_site(self):
        import datetime
        from karl.content.interfaces import IBlogEntry
        from karl.content.interfaces import ICalendarEvent
        from karl.content.interfaces import ICommunityFile
        from karl.content.interfaces import IWikiPage
        from karl.models.interfaces import IComment
        from karl.testing import DummyCommunity
        from karl.testing import DummyModel
        from karl.testing import DummyRoot
        from repoze.workflow.testing import registerDummyWorkflow
        from repoze.workflow.testing import DummyWorkflow
        from zope.interface import directlyProvides

        site = DummyRoot()
        site.tags = DummyTags()
        communities = site['communities'] = DummyModel()

        big_endians = communities['big_endians'] = DummyCommunity()
        big_endians.title = 'Big Endians'
        big_endians.member_names = ['fred', 'martin', 'daniela']
        big_endians.moderator_names = ['fred', 'daniela']
        big_endians.created = datetime.datetime(2010, 5, 12, 2, 42)
        big_endians.creator = 'daniela'
        big_endians.content_modified = datetime.datetime(2010, 6, 12, 2, 42)
        big_endians.__custom_acl__ = True

        content = big_endians['wiki1'] = DummyModel()
        content.created = datetime.datetime(2010, 5, 12, 3, 42)
        content.creator = 'daniela'
        directlyProvides(content, IWikiPage)

        content = big_endians['wiki2'] = DummyModel()
        content.created = datetime.datetime(1975, 7, 7, 7, 23)
        content.creator = 'fred'
        directlyProvides(content, IWikiPage)

        little_endians = communities['little_endians'] = DummyCommunity()
        little_endians.title = 'Little Endians'
        little_endians.member_names = ['dusty', 'roberta', 'nina']
        little_endians.moderator_names = ['nina']
        little_endians.created = datetime.datetime(2010, 5, 13, 6, 23)
        little_endians.creator = 'nina'
        little_endians.content_modified = datetime.datetime(2010, 6, 12, 3, 42)
        little_endians._p_deactivate = lambda: None
        little_endians.state = 'public'

        content = little_endians['blog1'] = DummyModel()
        content.created = datetime.datetime.now()
        content.creator = 'nina'
        directlyProvides(content, IBlogEntry)

        content['comment1'] = DummyModel()
        content = content['comment1']
        content.created = datetime.datetime.now()
        content.creator = 'roberta'
        directlyProvides(content, IComment)

        content = little_endians['file1'] = DummyModel()
        content.created = datetime.datetime.now()
        content.creator = 'dusty'
        directlyProvides(content, ICommunityFile)

        content = little_endians['event1'] = DummyModel()
        content.created = datetime.datetime.now()
        content.creator = 'dusty'
        directlyProvides(content, ICalendarEvent)

        registerDummyWorkflow('security', DummyWorkflow())

        return site