def test_populate_meeting(self):
     obj = self._make_obj()
     self._fill_obj(obj)
     from voteit.core.models.meeting import Meeting
     meeting = Meeting()
     obj.populate_meeting(meeting)
     self.assertEqual(len(meeting), 3)
     self.assertEqual(meeting.values()[0].get_field_value('title'), 'A1')
예제 #2
0
 def test_populate_meeting(self):
     obj = self._make_obj()
     self._fill_obj(obj)
     from voteit.core.models.meeting import Meeting
     meeting = Meeting()
     obj.populate_meeting(meeting)
     self.assertEqual(len(meeting), 3)
     self.assertEqual(meeting.values()[0].get_field_value('title'), 'A1')
 def test_get_content_specific_content_type(self):
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.agenda_item import AgendaItem
     meeting = Meeting()
     meeting['ai1'] = AgendaItem()
     meeting['ai2'] = AgendaItem()
     meeting['b1'] = self._cut()
     res = meeting.get_content(content_type = 'AgendaItem')
     self.assertEqual(len(res), 2)
예제 #4
0
 def test_unrestricted_wf_transition_to(self):
     from voteit.core.models.meeting import Meeting
     root = self._fixture()
     request = testing.DummyRequest()
     obj = Meeting()
     #Regular wf method doesn't work
     self.assertRaises(WorkflowError, obj.set_workflow_state, request, 'ongoing')
     #But unrestricted does
     security.unrestricted_wf_transition_to(obj, 'ongoing')
     self.assertEqual(obj.get_workflow_state(), 'ongoing')
예제 #5
0
 def _fixture(self, **kw):
     self.config.include('voteit.debate')
     meeting = Meeting()
     meeting.set_field_appstruct(kw)
     meeting['ai'] = ai = AgendaItem()
     ai.uid = 'uid'
     request = testing.DummyRequest()
     lists = request.registry.getAdapter(meeting, ISpeakerLists)
     lists.add_contextual_list(ai)
     return lists
예제 #6
0
 def test_unrestricted_wf_transition_to(self):
     from voteit.core.models.meeting import Meeting
     root = self._fixture()
     request = testing.DummyRequest()
     obj = Meeting()
     #Regular wf method doesn't work
     self.assertRaises(WorkflowError, obj.set_workflow_state, request,
                       'ongoing')
     #But unrestricted does
     security.unrestricted_wf_transition_to(obj, 'ongoing')
     self.assertEqual(obj.get_workflow_state(), 'ongoing')
예제 #7
0
 def test_search_catalog(self):
     register_catalog(self.config)
     self.config.testing_securitypolicy('admin', permissive=True)
     root = bootstrap_and_fixture(self.config)
     from voteit.core.models.meeting import Meeting
     root['m'] = Meeting(title='Hello world')
     root['m2'] = Meeting(title='Goodbye')
     request = testing.DummyRequest()
     obj = self._cut(root, request)
     self.assertEqual(obj.search_catalog(title='Hello world')[0], 1)
     #Context search should remove the result if the context is another tree
     self.assertEqual(
         obj.search_catalog(context=root['m2'], title='Hello world')[0], 0)
예제 #8
0
 def _fixture(self):
     root = bootstrap_and_fixture(self.config)
     self.config.include('arche.portlets')
     self.config.include('voteit.irl')
     self.config.include('voteit.qr')
     request = testing.DummyRequest()
     request.root = root
     apply_request_extensions(request)
     self.config.begin(request)
     root['m'] = Meeting()
     root['users']['jane'] = User()
     root['m'].local_roles['jane'] = [ROLE_VIEWER]
     return root, request
예제 #9
0
    def test_get_content_states(self):
        """ To test content states we need to setup workflow and use real content types."""
        from voteit.core.models.meeting import Meeting
        from voteit.core.models.agenda_item import AgendaItem
        self.config.include('pyramid_zcml')
        self.config.load_zcml('voteit.core:configure.zcml')

        meeting = Meeting()
        meeting.title = 'Hello Meeting'
        ai1 = AgendaItem()
        ai1.title = 'Stuff to do'
        ai2 = AgendaItem()
        ai2.title = 'More important things'
        meeting['ai1'] = ai1
        meeting['ai2'] = ai2
        meeting['b1'] = self._cut()

        self.assertEqual(
            meeting.get_content(sort_on='title', states='private'), (ai2, ai1))
        self.assertEqual(
            meeting.get_content(sort_on='title',
                                states=('private', 'upcoming')), (ai2, ai1))
        request = testing.DummyRequest()
        ai1.set_workflow_state(request, 'upcoming')
        self.assertEqual(
            meeting.get_content(sort_on='title', states='private'), (ai2, ))
        self.assertEqual(
            meeting.get_content(sort_on='title',
                                states=('private', 'some_other')), (ai2, ))
        self.assertEqual(
            meeting.get_content(sort_on='title',
                                states=(
                                    'private',
                                    'upcoming',
                                )), (ai2, ai1))
예제 #10
0
 def _add_mock_meeting(self):
     from voteit.core.models.meeting import Meeting
     obj = Meeting(
         title='Testing catalog',
         description='To check that everything works as expected.',
         uid='simple_uid',
         creators=['demo_userid'])
     obj.add_groups('admin', (
         security.ROLE_ADMIN,
         security.ROLE_MODERATOR,
     ),
                    event=False)
     self.root['meeting'] = obj
     return obj
예제 #11
0
 def test_get_content_by_interface(self):
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.interfaces import IAgendaItem
     from voteit.core.models.interfaces import IBaseContent
     meeting = Meeting()
     meeting['ai1'] = AgendaItem()
     meeting['ai2'] = AgendaItem()
     meeting['b1'] = self._cut()
     res = meeting.get_content(iface = IAgendaItem)
     self.assertEqual(len(res), 2)
     #IAgendaItem subclasses IBaseContent
     res = meeting.get_content(iface = IBaseContent)
     self.assertEqual(len(res), 3)
예제 #12
0
    def test_unrestricted_wf_transition_to(self):
        self.config.include('pyramid_zcml')
        self.config.load_zcml('voteit.core:configure.zcml')  #Load workflows

        from voteit.core.models.meeting import Meeting
        request = testing.DummyRequest()
        obj = Meeting()

        #Regular wf method doesn't work
        self.assertRaises(WorkflowError, obj.set_workflow_state, request,
                          'ongoing')

        #But unrestricted does
        security.unrestricted_wf_transition_to(obj, 'ongoing')
        self.assertEqual(obj.get_workflow_state(), 'ongoing')
예제 #13
0
 def test_meeting_state(self):
     from voteit.core.models.meeting import Meeting
     root = bootstrap_and_fixture(self.config)
     meeting = root['m'] = Meeting()
     request = testing.DummyRequest()
     obj = self._cut(meeting, request)
     self.assertEqual(obj.meeting_state, u'upcoming')
예제 #14
0
 def _fixture(self):
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.user import User
     root = bootstrap_and_fixture(self.config)
     root['m'] = Meeting()
     root['users']['dummy'] = User(first_name = 'John', last_name = 'Doe')
     return root
예제 #15
0
 def test_meeting_good_group(self):
     from voteit.core.models.meeting import Meeting
     context = Meeting()
     self._reg_dummy_policy(context)
     request = testing.DummyRequest()
     obj = self._cut(context, request)
     self.assertIsNone(obj(None, ['role:Moderator', 'role:Discussion']))
예제 #16
0
 def _fixture(self):
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.meeting import Meeting
     root = bootstrap_and_fixture(self.config)
     root['m'] = meeting = Meeting()
     meeting['ai'] = ai = AgendaItem()
     return ai
예제 #17
0
 def test_update_contained_in_ai(self):
     self.config.include('arche.testing.setup_auth')
     self.config.include('arche.testing')
     self.config.include('voteit.core.models.meeting')
     self.config.include('voteit.core.models.discussion_post')
     from voteit.core.models.discussion_post import DiscussionPost
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.user import User
     root = self._fixture()
     root['users']['john'] = User()
     root['m'] = Meeting()
     root['m'].add_groups('john', [security.ROLE_VIEWER])
     root['m']['ai'] = ai = self._ai(title='New object')
     ai['dp'] = dp = DiscussionPost()
     #To make sure dp got catalogued
     self.assertEqual(root.catalog.search(uid=dp.uid)[0], 1)
     #The discussion post shouldn't be visible now, since the ai is private
     self.assertEqual(
         root.catalog.search(uid=dp.uid,
                             allowed_to_view=[security.ROLE_VIEWER])[0], 0)
     #When the ai is made upcoming, it should be visible
     security.unrestricted_wf_transition_to(ai, 'upcoming')
     self.assertEqual(
         root.catalog.search(uid=dp.uid,
                             allowed_to_view=[security.ROLE_VIEWER])[0], 1)
예제 #18
0
 def test_meeting_bad_group(self):
     from voteit.core.models.meeting import Meeting
     self.config.testing_securitypolicy(userid='dummy', permissive=True)
     context = Meeting()
     request = testing.DummyRequest()
     obj = self._cut(context, request)
     self.assertRaises(colander.Invalid, obj, None, ['role:Admin'])
예제 #19
0
def active_poll_fixture(config):
    """ This method sets up a site the way it will be when a poll is ready to start
        with admin as voter.
        You can use this if you want a fixture for your poll plugin tests
    """
    from voteit.core.models.poll import Poll
    from voteit.core.models.meeting import Meeting
    from voteit.core.models.agenda_item import AgendaItem
    from voteit.core.models.proposal import Proposal
    root = bootstrap_and_fixture(config)
    request = testing.DummyRequest()
    config = testing.setUp(request = request, registry = config.registry)
    config.include('pyramid_mailer.testing')
    config.include('voteit.core.subscribers.poll')
    root['users']['admin'].set_field_value('email', '*****@*****.**')
    meeting = root['meeting'] = Meeting()
    meeting.add_groups('admin', [ROLE_VOTER])
    meeting.set_workflow_state(request, 'ongoing')
    ai = meeting['ai'] = AgendaItem()
    ai['prop1'] = Proposal(text = u"Proposal 1")
    ai['prop2'] = Proposal(text = u"Proposal 2")
    ai.set_workflow_state(request, 'upcoming')
    ai.set_workflow_state(request, 'ongoing')
    ai['poll'] = Poll(title = 'A poll')
    poll = ai['poll']
    poll.set_field_value('proposals', set([ai['prop1'].uid, ai['prop2'].uid]))
    poll.set_workflow_state(request, 'upcoming')
    return root
예제 #20
0
파일: tests.py 프로젝트: VoteIT/voteit.stv
def _setup_poll_fixture(config):
    # type: (Configurator) -> Poll
    config.testing_securitypolicy('admin', permissive=True)
    # config.include('pyramid_chameleon')
    # Register plugin
    config.include('voteit.stv')
    config.include('arche.testing')
    config.include('arche.testing.workflow')
    config.include('arche.testing.catalog')
    config.include('voteit.core.models.catalog')
    root = bootstrap_and_fixture(config)
    root['m'] = Meeting()
    unrestricted_wf_transition_to(root['m'], 'ongoing')
    root['m']['ai'] = ai = AgendaItem()
    unrestricted_wf_transition_to(ai, 'upcoming')
    unrestricted_wf_transition_to(ai, 'ongoing')
    #Setup poll
    ai['poll'] = Poll()
    poll = ai['poll']
    #Add proposals
    p1 = Proposal(creators = ['dummy'], text = 'first proposal')
    p1.uid = 'p1uid' #To make it simpler to test against
    ai['p1'] = p1
    p2 = Proposal(creators = ['dummy'], text = 'second proposal')
    p2.uid = 'p2uid'
    ai['p2'] = p2
    p3 = Proposal(creators = ['dummy'], text = 'third proposal')
    p3.uid = 'p3uid'
    ai['p3'] = p3
    #Select proposals for this poll
    poll.proposal_uids = (p1.uid, p2.uid, p3.uid)
    #Set poll as ongoing
    unrestricted_wf_transition_to(poll, 'upcoming')
    return poll
예제 #21
0
 def _fixture(self):
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.user import User
     root = bootstrap_and_fixture(self.config)
     root['m'] = meeting = Meeting()
     root.users['dummy'] = User()
     return meeting
예제 #22
0
def _fixture(config):
    from voteit.core.models.meeting import Meeting
    config.include('arche.testing')
    config.include('voteit.core.schemas.contact')
    config.include('pyramid_mailer.testing')
    root = bootstrap_and_fixture(config)
    root['m'] = Meeting()
    return root
예제 #23
0
 def _fixture(self):
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.meeting import Meeting
     root = bootstrap_and_fixture(self.config)
     root['users']['admin'].email = '*****@*****.**'
     root['m'] = meeting = Meeting()
     meeting['ai'] = ai = AgendaItem()
     return ai
예제 #24
0
 def test_add_permission_meeting(self):
     root = self._fixture()
     from voteit.core.models.meeting import Meeting
     root['m'] = context = Meeting()
     request = testing.DummyRequest()
     obj = self._cut(context, request)
     response = obj.add_permission()
     self.assertIn('form', response)
예제 #25
0
 def test_group_form_meeting_cancel(self):
     root = self._fixture()
     from voteit.core.models.meeting import Meeting
     root['m'] = context = Meeting()
     request = testing.DummyRequest(post={'cancel': 'cancel'})
     obj = self._cut(context, request)
     response = obj.group_form()
     self.assertEqual(response.location, 'http://example.com/m/')
예제 #26
0
 def test_meeting_url(self):
     from voteit.core.models.meeting import Meeting
     root = bootstrap_and_fixture(self.config)
     meeting = root['m'] = Meeting()
     request = testing.DummyRequest()
     obj = self._cut(meeting, request)
     #example.com is from Pyramids testing env
     self.assertEqual(obj.meeting_url, 'http://example.com/m/')
예제 #27
0
def _fixture(config):
    from voteit.core.models.meeting import Meeting
    config.testing_securitypolicy(userid='dummy', permissive=True)
    config.include('voteit.core.testing_helpers.register_catalog')
    root = bootstrap_and_fixture(config)
    root['users']['admin'].about_me = u"The story of an administrator"
    root['m'] = Meeting()
    return root
예제 #28
0
 def _fixture(self):
     from voteit.core.models.meeting import Meeting
     self.config.include('arche.models.catalog')
     self.config.include('voteit.core.models.catalog')
     root = bootstrap_and_fixture(self.config)
     self.config.include('voteit.core.models.invite_ticket')
     root['m'] = Meeting()
     root['users']['admin'].email = '*****@*****.**'
     return root
예제 #29
0
 def _fixture(self):
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.proposal import Proposal
     from voteit.core.models.poll import Poll
     self.root['m'] = m = Meeting()
     m['ai'] = ai = self._cut()
     ai['prop'] = prop = Proposal()
     ai['poll'] = Poll(proposals=[prop.uid])
     return ai
예제 #30
0
 def _fixture(self):
     from arche.resources import Document
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.proposal import Proposal
     from voteit.core.models.meeting import Meeting
     root = bootstrap_and_fixture(self.config)
     root['m'] = m = Meeting()
     m['ai'] = ai = AgendaItem(title='ai')
     ai['p'] = Proposal(text='Some animlas are more equal than others')
     ai['p']['d'] = Document()
     ai['p2'] = Proposal(text='Me wont be there')
     unrestricted_wf_transition_to(ai['p2'], 'retracted')
     root['m2'] = Meeting()
     request = testing.DummyRequest()
     request.root = root
     apply_request_extensions(request)
     self.config.begin(request)
     return root, request
예제 #31
0
 def test_get_userinfo_url(self):
     from voteit.core.models.meeting import Meeting
     root = bootstrap_and_fixture(self.config)
     meeting = root['m'] = Meeting()
     request = testing.DummyRequest()
     obj = self._cut(meeting, request)
     #example.com is from Pyramids testing suite
     self.assertEqual(obj.get_userinfo_url('somebody'),
                      'http://example.com/m/_userinfo?userid=somebody')
 def _fixture(self):
     from voteit.core.models.meeting import Meeting
     from voteit.core.models.agenda_item import AgendaItem
     from voteit.core.models.user import User
     root = bootstrap_and_fixture(self.config)
     root.users['some_user'] = User()
     root['m'] = Meeting()
     root['m']['ai'] = AgendaItem()
     return root['m']['ai']
예제 #33
0
    def _fixture(self):
        from voteit.core.models.meeting import Meeting
        from voteit.core.models.invite_ticket import InviteTicket
        meeting = Meeting()

        ticket = InviteTicket('*****@*****.**', ['role:Moderator'],
                              'Welcome to the meeting!')
        meeting.invite_tickets['*****@*****.**'] = ticket
        return meeting
예제 #34
0
 def _fixture(self):
     root = bootstrap_and_fixture(self.config)
     tester = User(password = '******',
                   creators = ['tester'],
                   first_name = u'Tester',
                   email = "*****@*****.**",)
     root.users['tester'] = tester
     moderator = User(password = '******',
                      creators = ['moderator'],
                      first_name = u'Moderator',
                      email = "*****@*****.**",)
     root.users['moderator'] = moderator
 
     meeting = Meeting()
     meeting.add_groups('tester', [security.ROLE_DISCUSS, security.ROLE_PROPOSE, security.ROLE_VOTER])
     meeting.add_groups('moderator', [security.ROLE_MODERATOR])
     root['meeting'] = meeting
     return meeting
예제 #35
0
def includeme(config):
    from voteit.core.models.meeting import Meeting

    # Set properties on meeting
    Meeting.add_field('like_context_types', wrapper=frozenset)
    Meeting.add_field('like_workflow_states', wrapper=frozenset)
    Meeting.add_field('like_user_roles', wrapper=frozenset)
    Meeting.add_field('like_button_state', default=LIKE_SETTING_ACTIVE)
    Meeting.add_field('like_success_threshold', default=0)

    config.add_schema('Meeting', LikeSettingsSchema, 'like_settings')
    config.add_view_action(control_panel_category,
                           'control_panel', 'like',
                           panel_group='control_panel_like',
                           title=_("Like button"),
                           check_active=_check_active_for_meeting)
    config.add_view_action(control_panel_link,
                           'control_panel_like', 'settings',
                           title=_("Settings"), view_name='like_settings')
    config.scan(__name__)
    config.add_subscriber(like_resources, [IBaseView, IViewInitializedEvent])
    # Add catalog index
    indexes = {'like_userids': CatalogKeywordIndex(get_like_userids_indexer),}
    config.add_catalog_indexes(__name__, indexes)
    config.add_view(
        LikeSettingsForm,
        context = IMeeting,
        name="like_settings",
        permission=security.MODERATE_MEETING,
        renderer="arche:templates/form.pt",
    )
    # Setup storage
    for iface in (IProposal, IDiscussionPost):
        config.add_usertag('like', iface,
                           catalog_index = 'like_userids',
                           add_perm = PERM_VIEW,
                           view_perm = PERM_VIEW,
                           add_perm_callback = _check_add_perm)
        config.add_view(LikeUsersView,
                        context = iface,
                        name = '_like_users_popover',
                        permission = PERM_VIEW,
                        renderer = 'voteit.core.plugins:templates/like_users_popover.pt')
예제 #36
0
def _fixture(config):
    from voteit.core.models.user import User
    from voteit.core.models.meeting import Meeting
    config.include('pyramid_chameleon')
    root = bootstrap_and_fixture(config)
    tester = User(password = '******',
                  creators = ['tester'],
                  first_name = u'Tester',
                  email = "*****@*****.**",)
    root.users['tester'] = tester
    moderator = User(password = '******',
                     creators = ['moderator'],
                     first_name = u'Moderator',
                     email = "*****@*****.**",)
    root.users['moderator'] = moderator
    meeting = Meeting()
    meeting.add_groups('tester', [security.ROLE_DISCUSS, security.ROLE_PROPOSE, security.ROLE_VOTER])
    meeting.add_groups('moderator', [security.ROLE_MODERATOR])
    root['meeting'] = meeting
    return root
예제 #37
0
    def test_get_content_states(self):
        """ To test content states we need to setup workflow and use real content types."""
        from voteit.core.models.meeting import Meeting
        from voteit.core.models.agenda_item import AgendaItem
        self.config.include('pyramid_zcml')
        self.config.load_zcml('voteit.core:configure.zcml')

        meeting = Meeting()
        meeting.title = 'Hello Meeting'
        ai1 = AgendaItem()
        ai1.title = 'Stuff to do'
        ai2 = AgendaItem()
        ai2.title = 'More important things'
        meeting['ai1'] = ai1
        meeting['ai2'] = ai2
        meeting['b1'] = self._cut()
        
        self.assertEqual(meeting.get_content(sort_on = 'title', states='private'), (ai2, ai1))
        self.assertEqual(meeting.get_content(sort_on = 'title', states=('private', 'upcoming')), (ai2, ai1))
        request = testing.DummyRequest()
        ai1.set_workflow_state(request, 'upcoming')
        self.assertEqual(meeting.get_content(sort_on = 'title', states='private'), (ai2,))
        self.assertEqual(meeting.get_content(sort_on = 'title', states=('private', 'some_other')), (ai2,))
        self.assertEqual(meeting.get_content(sort_on = 'title', states=('private', 'upcoming',)), (ai2, ai1))
예제 #38
0
    def test_meeting_states(self):
        obj = Meeting()
        request = testing.DummyRequest()

        self.assertEqual(obj.get_workflow_state(), u"upcoming")

        obj.make_workflow_transition(request, "upcoming_to_ongoing")
        self.assertEqual(obj.get_workflow_state(), u"ongoing")

        obj.workflow.initialize(obj)
        obj.make_workflow_transition(request, "upcoming_to_closed")
        self.assertEqual(obj.get_workflow_state(), u"closed")

        obj.workflow.initialize(obj)
        obj.make_workflow_transition(request, "upcoming_to_ongoing")
        obj.make_workflow_transition(request, "ongoing_to_upcoming")
        self.assertEqual(obj.get_workflow_state(), u"upcoming")

        obj.workflow.initialize(obj)
        obj.make_workflow_transition(request, "upcoming_to_ongoing")
        obj.make_workflow_transition(request, "ongoing_to_closed")
        self.assertEqual(obj.get_workflow_state(), u"closed")

        obj.workflow.initialize(obj)
        obj.make_workflow_transition(request, "upcoming_to_closed")
        obj.make_workflow_transition(request, "closed_to_ongoing")
        self.assertEqual(obj.get_workflow_state(), u"ongoing")