Example #1
0
 def test_adjust_proposal_states_already_correct_state(self):
     register_workflows(self.config)
     self.config.include('arche.testing.catalog')
     request = testing.DummyRequest()
     self.config = testing.setUp(registry=self.config.registry,
                                 request=request)
     agenda_item = self._agenda_item_with_proposals_fixture()
     prop1 = agenda_item['prop1']
     prop2 = agenda_item['prop2']
     prop1.set_workflow_state(request, 'voting')
     prop2.set_workflow_state(request, 'voting')
     prop2.set_workflow_state(request, 'approved')
     agenda_item['poll'] = poll = self._cut()
     poll.proposal_uids = (
         prop1.uid,
         prop2.uid,
     )
     adjust_states = {
         prop1.uid: 'denied',
         prop2.uid: 'approved',
     }
     poll.adjust_proposal_states(adjust_states)
     self.assertEqual(prop1.get_workflow_state(), 'denied')
     #No change here, but no exception raised either
     self.assertEqual(prop2.get_workflow_state(), 'approved')
Example #2
0
 def test_render_poll_state_info(self):
     from voteit.core.models.poll import Poll
     from voteit.core.views.api import APIView
     from voteit.core.testing_helpers import register_workflows
     register_workflows(self.config)
     self.config.include('pyramid_chameleon')
     self.config.registry.settings[
         'default_timezone_name'] = "Europe/Stockholm"
     self.config.include('voteit.core.models.date_time_util')
     self.config.scan('voteit.core.views.components.main')
     #root = active_poll_fixture(self.config)
     #poll = root['meeting']['ai']['poll']
     poll = Poll()
     from voteit.core.models.date_time_util import utcnow
     poll.set_field_value('start_time', utcnow())
     poll.set_field_value('end_time', utcnow())
     request = testing.DummyRequest()
     #obj = self._cut(poll, request)
     api = APIView(poll, request)
     res = render_view_action(poll,
                              request,
                              'main',
                              'poll_state_info',
                              api=api)
     #obj.get_poll_state_info(poll)
     self.assertIn('The poll starts', res)
Example #3
0
    def test_close_poll(self):
        register_workflows(self.config)
        request = testing.DummyRequest()
        self.config = testing.setUp(registry=self.config.registry,
                                    request=request)
        self.config.include('arche.testing.catalog')
        agenda_item = self._agenda_item_with_proposals_fixture()
        prop1 = agenda_item['prop1']
        prop2 = agenda_item['prop2']
        agenda_item['poll'] = poll = self._cut()
        poll.proposal_uids = (
            prop1.uid,
            prop2.uid,
        )

        class _MockPollPlugin(PollPlugin):
            def handle_close(self):
                pass

            def change_states_of(self):
                return {prop1.uid: 'voting', prop2.uid: 'voting'}

        self.config.registry.registerAdapter(_MockPollPlugin, (IPoll, ),
                                             IPollPlugin, 'mock_poll_plugin')
        poll.set_field_value('poll_plugin', 'mock_poll_plugin')
        poll.close_poll()
        #Should have been adjusted if everything went according to plan
        self.assertEqual(prop2.get_workflow_state(), 'voting')
Example #4
0
 def test_poll_state_change(self):
     register_workflows(self.config)
     root = self._fixture()
     meeting = root['m']
     ai = meeting['ai']
     meeting.set_workflow_state(self.request, 'upcoming')
     meeting.set_workflow_state(self.request, 'ongoing')
     ai.set_workflow_state(self.request, 'upcoming')
     ai.set_workflow_state(self.request, 'ongoing')
     from voteit.core.models.proposal import Proposal
     ai['p1'] = p1 = Proposal()
     ai['p2'] = p2 = Proposal()
     self.config.include('voteit.feed')
     from voteit.core.models.poll import Poll
     poll = Poll()
     poll.proposal_uids = (p1.uid, p2.uid)
     self.config.include('voteit.core.plugins.majority_poll')
     poll.set_field_value('poll_plugin', u'majority_poll')
     ai['p'] = poll
     poll.set_workflow_state(self.request, 'upcoming')
     poll.set_workflow_state(self.request, 'ongoing')
     adapter = self.config.registry.queryAdapter(meeting, IFeedHandler)
     self.assertEqual(len(adapter.feed_storage), 1)
     self.assertEqual(adapter.feed_storage[len(adapter.feed_storage)-1].tags, ('poll', 'ongoing',))
     poll.set_workflow_state(self.request, 'closed')
     self.assertEqual(len(adapter.feed_storage), 2)
     self.assertEqual(adapter.feed_storage[len(adapter.feed_storage)-1].tags, ('poll', 'closed',))
Example #5
0
 def test_with_nonexistent_user(self):
     register_security_policies(self.config)
     register_workflows(self.config)
     root = _fixture(self.config)
     context = root['meeting']
     obj = self._cut(context)
     node = None
     self.assertRaises(colander.Invalid, obj, node, "@admin says that naming @nonexistent should raise Invalid")
Example #6
0
 def test_with_at_links(self):
     register_security_policies(self.config)
     register_workflows(self.config)
     root = _fixture(self.config)
     context = root['meeting']
     obj = self._cut(context)
     node = None
     self.assertEqual(obj(node, "@admin says to @tester that this shouldn't be valid."), None)
Example #7
0
 def test_timestamp_added_on_close(self):
     register_workflows(self.config)
     self.config.scan('voteit.core.subscribers.timestamps') #To add subscriber
     request = testing.DummyRequest()
     obj = self._cut()
     obj.set_workflow_state(request, 'ongoing')
     self.assertFalse(isinstance(obj.end_time, datetime))
     obj.set_workflow_state(request, 'closed')
     self.assertTrue(isinstance(obj.end_time, datetime))
Example #8
0
 def test_closing_meeting_callback(self):
     register_workflows(self.config)
     request = testing.DummyRequest()
     obj = self._cut()
     obj['ai'] = self._ai()
     obj.set_workflow_state(request, 'ongoing')
     obj['ai'].set_workflow_state(request, 'upcoming')
     obj['ai'].set_workflow_state(request, 'ongoing')
     self.assertRaises(HTTPForbidden, obj.set_workflow_state, request, 'closed')
Example #9
0
    def test_wf_state_change(self):
        register_workflows(self.config)
        root = self._fixture()
        meeting = root['m']

        meeting.set_workflow_state(self.request, 'upcoming')

        adapter = self.config.registry.queryAdapter(meeting, ILogHandler)
        self.assertEqual(len(adapter.log_storage), 1)
        self.assertEqual(adapter.log_storage[0].tags, ('workflow', ))
Example #10
0
    def test_wf_state_change(self):
        register_workflows(self.config)
        root = self._fixture()
        meeting = root["m"]

        meeting.set_workflow_state(self.request, "upcoming")

        adapter = self.config.registry.queryAdapter(meeting, ILogHandler)
        self.assertEqual(len(adapter.log_storage), 1)
        self.assertEqual(adapter.log_storage[0].tags, ("workflow",))
 def test_with_at_links(self):
     register_security_policies(self.config)
     register_workflows(self.config)
     root = _fixture(self.config)
     context = root['meeting']
     obj = self._cut(context)
     node = None
     self.assertEqual(
         obj(node, "@admin says to @tester that this shouldn't be valid."),
         None)
Example #12
0
 def test_timestamp_added_on_close(self):
     register_workflows(self.config)
     self.config.scan(
         'voteit.core.subscribers.timestamps')  #To add subscriber
     request = testing.DummyRequest()
     obj = self._cut()
     obj.set_workflow_state(request, 'ongoing')
     self.assertFalse(isinstance(obj.end_time, datetime))
     obj.set_workflow_state(request, 'closed')
     self.assertTrue(isinstance(obj.end_time, datetime))
Example #13
0
 def test_closing_meeting_callback(self):
     register_workflows(self.config)
     request = testing.DummyRequest()
     obj = self._cut()
     obj['ai'] = self._ai()
     obj.set_workflow_state(request, 'ongoing')
     obj['ai'].set_workflow_state(request, 'upcoming')
     obj['ai'].set_workflow_state(request, 'ongoing')
     self.assertRaises(HTTPForbidden, obj.set_workflow_state, request,
                       'closed')
 def test_with_nonexistent_user(self):
     register_security_policies(self.config)
     register_workflows(self.config)
     root = _fixture(self.config)
     context = root['meeting']
     obj = self._cut(context)
     node = None
     self.assertRaises(
         colander.Invalid, obj, node,
         "@admin says that naming @nonexistent should raise Invalid")
Example #15
0
    def test_closing_meeting_with_ongoing_ais(self):
        """ Closing a meeting with ongoing agenda items should raise an exception. """
        register_workflows(self.config)
        request = testing.DummyRequest()
        ai = self._ai()
        ai.set_workflow_state(request, 'upcoming')
        ai.set_workflow_state(request, 'ongoing')
        obj = self._cut()
        obj['ai'] = ai

        obj.set_workflow_state(request, 'ongoing')
        self.assertRaises(Exception, obj.set_workflow_state, 'closed')
Example #16
0
    def test_with_user_outside_of_meeting_context(self):
        from voteit.core.models.user import User

        register_security_policies(self.config)
        register_workflows(self.config)
        root = _fixture(self.config)
        context = root['meeting']
        #New user
        root.users['new'] = User()
        obj = self._cut(context)
        node = None
        self.assertRaises(colander.Invalid, obj, node, "@new doesn't exist in this meeting so this shouldn't work")
Example #17
0
 def test_closing_meeting_with_ongoing_ais(self):
     """ Closing a meeting with ongoing agenda items should raise an exception. """
     register_workflows(self.config)
     request = testing.DummyRequest()
     ai = self._ai()
     ai.set_workflow_state(request, 'upcoming')
     ai.set_workflow_state(request, 'ongoing')
     obj = self._cut()
     obj['ai'] = ai
     
     obj.set_workflow_state(request, 'ongoing')
     self.assertRaises(Exception, obj.set_workflow_state, 'closed')
Example #18
0
 def test_ongoing_wo_proposal(self):
     request = testing.DummyRequest()
     self.config = testing.setUp(registry = self.config.registry, request = request)
     register_workflows(self.config)
     poll = self._make_obj()
     ai = find_interface(poll, IAgendaItem)
     ai.set_workflow_state(request, 'upcoming')
     ai.set_workflow_state(request, 'ongoing')
     # remove all proposals on poll
     poll.set_field_value('proposals', set())
     poll.set_workflow_state(request, 'upcoming')
     self.assertRaises(HTTPForbidden, poll.set_workflow_state, request, 'ongoing')
Example #19
0
 def test_workflow_state_to_ongoing(self):
     """ When you try to set state to ongoing on poll and 
         agenda item is not ongoing an exception should be raised.
     """
     register_workflows(self.config)
     request = testing.DummyRequest()
     obj = self._make_obj()
     obj.set_workflow_state(request, 'upcoming')
     self.assertRaises(Exception, obj.set_workflow_state, 'ongoing')
     ai = find_interface(obj, IAgendaItem)
     ai.set_workflow_state(request, 'upcoming')
     ai.set_workflow_state(request, 'ongoing')
     obj.set_workflow_state(request, 'ongoing')
Example #20
0
 def test_ongoing_wo_proposal(self):
     register_workflows(self.config)
     self.config.include('arche.testing.catalog')
     ai = self._agenda_item_with_proposals_fixture()
     ai['poll'] = poll = self._cut()
     #ai = find_interface(poll, IAgendaItem)
     security.unrestricted_wf_transition_to(ai, 'upcoming')
     security.unrestricted_wf_transition_to(ai, 'ongoing')
     # remove all proposals on poll
     #poll.set_field_value('proposals', set())
     security.unrestricted_wf_transition_to(poll, 'upcoming')
     request = testing.DummyRequest()
     self.assertRaises(HTTPForbidden, poll.set_workflow_state, request, 'ongoing')
Example #21
0
 def test_adjust_proposal_states_bad_state(self):
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config = testing.setUp(registry = self.config.registry, request = request)
     agenda_item = self._agenda_item_with_proposals_fixture()
     prop1 = agenda_item['prop1']
     prop2 = agenda_item['prop2']
     agenda_item['poll'] = poll = self._cut()
     poll.proposal_uids = (prop1.uid, prop2.uid,)
     adjust_states = {prop1.uid: 'john',
                      prop2.uid: 'doe',}
     poll.adjust_proposal_states(adjust_states)
     self.assertEqual(prop1.get_workflow_state(), 'published')
     self.assertEqual(prop2.get_workflow_state(), 'published')
    def test_with_user_outside_of_meeting_context(self):
        from voteit.core.models.user import User

        register_security_policies(self.config)
        register_workflows(self.config)
        root = _fixture(self.config)
        context = root['meeting']
        #New user
        root.users['new'] = User()
        obj = self._cut(context)
        node = None
        self.assertRaises(
            colander.Invalid, obj, node,
            "@new doesn't exist in this meeting so this shouldn't work")
Example #23
0
 def test_workflow_state_to_ongoing(self):
     """ When you try to set state to ongoing on poll and 
         agenda item is not ongoing an exception should be raised.
     """
     register_workflows(self.config)
     self.config.include('arche.testing.catalog')
     request = testing.DummyRequest()
     obj = self._agenda_item_with_proposals_fixture()
     obj.set_workflow_state(request, 'upcoming')
     self.assertRaises(Exception, obj.set_workflow_state, 'ongoing')
     ai = find_interface(obj, IAgendaItem)
     ai.set_workflow_state(request, 'upcoming')
     ai.set_workflow_state(request, 'ongoing')
     obj.set_workflow_state(request, 'ongoing')
Example #24
0
 def test_ongoing_wo_proposal(self):
     register_workflows(self.config)
     self.config.include('arche.testing.catalog')
     ai = self._agenda_item_with_proposals_fixture()
     ai['poll'] = poll = self._cut()
     #ai = find_interface(poll, IAgendaItem)
     security.unrestricted_wf_transition_to(ai, 'upcoming')
     security.unrestricted_wf_transition_to(ai, 'ongoing')
     # remove all proposals on poll
     #poll.set_field_value('proposals', set())
     security.unrestricted_wf_transition_to(poll, 'upcoming')
     request = testing.DummyRequest()
     self.assertRaises(HTTPForbidden, poll.set_workflow_state, request,
                       'ongoing')
Example #25
0
 def test_workflow_state_to_ongoing(self):
     """ When you try to set state to ongoing on poll and 
         agenda item is not ongoing an exception should be raised.
     """
     register_workflows(self.config)
     self.config.include('arche.testing.catalog')
     request = testing.DummyRequest()
     obj = self._agenda_item_with_proposals_fixture()
     obj.set_workflow_state(request, 'upcoming')
     self.assertRaises(Exception, obj.set_workflow_state, 'ongoing')
     ai = find_interface(obj, IAgendaItem)
     ai.set_workflow_state(request, 'upcoming')
     ai.set_workflow_state(request, 'ongoing')
     obj.set_workflow_state(request, 'ongoing')
Example #26
0
 def test_proposal_in_wrong_state(self):
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config.begin(request)
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.proposal import Proposal
     from voteit.core.models.poll import Poll
     self.root['ai'] = ai = AgendaItem()
     ai['prop'] = Proposal()
     ai['poll'] = Poll()
     ai['poll'].proposal_uids = (ai['prop'].uid, )
     self.config.include('voteit.core.subscribers.poll')
     #Set state to something that doesn't have a transition to 'voting'
     ai['prop'].set_workflow_state(request, 'approved')
     self.assertRaises(HTTPForbidden, ai['poll'].set_workflow_state, request, 'upcoming')
Example #27
0
 def test_change_states_proposals(self):
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.proposal import Proposal
     from voteit.core.models.poll import Poll
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config.begin(request)
     self.root['ai'] = ai = AgendaItem()
     ai['prop1'] = Proposal()
     ai['prop2'] = Proposal()
     ai['poll'] = Poll()
     ai['poll'].proposal_uids = (ai['prop1'].uid, ai['prop2'].uid)
     ai['poll'].set_workflow_state(request, 'upcoming')
     self.assertEqual(ai['prop1'].get_workflow_state(), 'voting')
     self.assertEqual(ai['prop2'].get_workflow_state(), 'voting')
Example #28
0
 def test_change_states_proposals(self):
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.proposal import Proposal
     from voteit.core.models.poll import Poll
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config.begin(request)
     self.root['ai'] = ai = AgendaItem()
     ai['prop1'] = Proposal()
     ai['prop2'] = Proposal()
     ai['poll'] = Poll()
     ai['poll'].proposal_uids = (ai['prop1'].uid, ai['prop2'].uid)
     ai['poll'].set_workflow_state(request, 'upcoming')
     self.assertEqual(ai['prop1'].get_workflow_state(), 'voting')
     self.assertEqual(ai['prop2'].get_workflow_state(), 'voting')
Example #29
0
 def test_proposal_in_wrong_state(self):
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config.begin(request)
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.proposal import Proposal
     from voteit.core.models.poll import Poll
     self.root['ai'] = ai = AgendaItem()
     ai['prop'] = Proposal()
     ai['poll'] = Poll()
     ai['poll'].proposal_uids = (ai['prop'].uid, )
     self.config.include('voteit.core.subscribers.poll')
     #Set state to something that doesn't have a transition to 'voting'
     ai['prop'].set_workflow_state(request, 'denied')
     self.assertRaises(HTTPForbidden, ai['poll'].set_workflow_state, request, 'upcoming')
Example #30
0
 def test_adjust_proposal_states(self):
     self.config.include('arche.testing.catalog')
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config = testing.setUp(registry = self.config.registry, request = request)
     agenda_item = self._agenda_item_with_proposals_fixture()
     prop1 = agenda_item['prop1']
     prop2 = agenda_item['prop2']
     prop1.set_workflow_state(request, 'voting')
     prop2.set_workflow_state(request, 'voting')
     agenda_item['poll'] = poll = self._cut()
     poll.proposal_uids = (prop1.uid, prop2.uid,)
     adjust_states = {prop1.uid: 'denied',
                      prop2.uid: 'approved',}
     poll.adjust_proposal_states(adjust_states)
     self.assertEqual(prop1.get_workflow_state(), 'denied')
     self.assertEqual(prop2.get_workflow_state(), 'approved')
Example #31
0
 def test_adjust_proposal_states_already_correct_state(self):
     register_workflows(self.config)
     request = testing.DummyRequest()
     self.config = testing.setUp(registry = self.config.registry, request = request)
     agenda_item = self._agenda_item_with_proposals_fixture()
     prop1 = agenda_item['prop1']
     prop2 = agenda_item['prop2']
     prop1.set_workflow_state(request, 'voting')
     prop2.set_workflow_state(request, 'voting')
     prop2.set_workflow_state(request, 'approved')
     agenda_item['poll'] = poll = self._cut()
     poll.proposal_uids = (prop1.uid, prop2.uid,)
     adjust_states = {prop1.uid: 'denied',
                      prop2.uid: 'approved',}
     poll.adjust_proposal_states(adjust_states)
     self.assertEqual(prop1.get_workflow_state(), 'denied')
     #No change here, but no exception raised either
     self.assertEqual(prop2.get_workflow_state(), 'approved')
Example #32
0
    def test_proposal_in_wrong_state(self):
        register_workflows(self.config)
        request = testing.DummyRequest()
        self.config = testing.setUp(registry=self.config.registry,
                                    request=request)

        from voteit.core.models.agenda_item import AgendaItem
        from voteit.core.models.proposal import Proposal
        from voteit.core.models.poll import Poll
        ai = AgendaItem()
        ai['prop'] = Proposal()
        ai['poll'] = Poll()
        ai['poll'].proposal_uids = (ai['prop'].uid, )

        #Set state to something that doesn't have a transition to 'voting'
        ai['prop'].set_workflow_state(request, 'approved')

        self.assertRaises(HTTPForbidden, ai['poll'].set_workflow_state,
                          request, 'upcoming')
Example #33
0
 def test_render_poll_state_info(self):
     from voteit.core.models.poll import Poll
     from voteit.core.views.api import APIView
     from voteit.core.testing_helpers import register_workflows
     register_workflows(self.config)
     self.config.registry.settings['default_timezone_name'] = "Europe/Stockholm"
     self.config.include('voteit.core.models.date_time_util')
     self.config.scan('voteit.core.views.components.main')
     #root = active_poll_fixture(self.config)
     #poll = root['meeting']['ai']['poll']
     poll = Poll()
     from voteit.core.models.date_time_util import utcnow
     poll.set_field_value('start_time', utcnow())
     poll.set_field_value('end_time', utcnow())
     request = testing.DummyRequest()
     #obj = self._cut(poll, request)
     api = APIView(poll, request)
     res = render_view_action(poll, request, 'main', 'poll_state_info', api = api)
     #obj.get_poll_state_info(poll)
     self.assertIn('The poll starts', res)
Example #34
0
    def test_close_poll(self):
        register_workflows(self.config)
        request = testing.DummyRequest()
        self.config = testing.setUp(registry = self.config.registry, request = request)
        agenda_item = self._agenda_item_with_proposals_fixture()
        prop1 = agenda_item['prop1']
        prop2 = agenda_item['prop2']
        agenda_item['poll'] = poll = self._cut()
        poll.proposal_uids = (prop1.uid, prop2.uid,)

        class _MockPollPlugin(PollPlugin):
            def handle_close(self):
                pass
            def change_states_of(self):
                return {prop1.uid: 'voting', prop2.uid:'voting'}

        self.config.registry.registerAdapter(_MockPollPlugin, (IPoll,), IPollPlugin, 'mock_poll_plugin')
        poll.set_field_value('poll_plugin', 'mock_poll_plugin')
        poll.close_poll()
        #Should have been adjusted if everything went according to plan
        self.assertEqual(prop2.get_workflow_state(), 'voting')
Example #35
0
 def setUp(self):
     self.config = testing.setUp()
     policy = ACLAuthorizationPolicy()
     self.pap = policy.principals_allowed_by_permission
     register_workflows(self.config)