def _make_poll(self): from voteit.core.models.poll import Poll poll = Poll() poll.set_field_value('proposals', set(self._make_proposal().uid)) return poll
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',))
def _make_poll(self): from voteit.core.models.poll import Poll from voteit.core.models.proposal import Proposal self.config.include('voteit.core.plugins.majority_poll') poll = Poll() poll.set_field_value('poll_plugin', u'majority_poll') proposal = Proposal() poll.set_field_value('proposals', set(proposal.uid)) return poll
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.config.include("voteit.core.testing_helpers.register_testing_poll") self.root['m'] = m = Meeting() m['ai'] = ai = self._cut() ai['prop'] = prop = Proposal() ai['poll'] = Poll(proposals=[prop.uid]) ai['poll'].poll_plugin_name = "testing" return ai
def _make_obj(self): """ Poll object need to be in the context of an Agenda Item to work properly """ root = bootstrap_and_fixture(self.config) self.config.include('voteit.core.models.poll') from voteit.core.models.poll import Poll from voteit.core.models.proposal import Proposal from voteit.core.models.agenda_item import AgendaItem root['ai'] = ai = AgendaItem() poll = Poll() ai['prop'] = proposal = Proposal() poll.set_field_value('proposals', set(proposal.uid)) ai['poll'] = poll return poll
def _fixture(self): root = bootstrap_voteit(echo=False) from voteit.core.models.meeting import Meeting from voteit.core.models.poll import Poll root['m'] = m = Meeting() m['p1'] = Poll(title='Hello from one') m['p2'] = Poll(title='Hello from two') m['p3'] = Poll(title='Hello from three') request = testing.DummyRequest() request.root = root request.meeting = m request.is_moderator = False attach_request_method(request, resolve_docids, 'resolve_docids') return m, request
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')
def _make_obj(self): """ Poll object need to be in the context of an Agenda Item to work properly """ from voteit.core.models.poll import Poll poll = Poll() from voteit.core.models.proposal import Proposal proposal = Proposal() poll.set_field_value('proposals', set(proposal.uid)) from voteit.core.models.agenda_item import AgendaItem ai = AgendaItem() ai['poll'] = poll return poll
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')
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')
def test_pr_included(self): self.config.include('voteit.schulze') poll = Poll() self.failUnless( self.config.registry.queryAdapter(poll, IPollPlugin, name='schulze_pr'))
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
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
def _make_obj(self): from voteit.core.plugins.majority_poll import MajorityPollPlugin from voteit.core.models.poll import Poll from voteit.core.models.agenda_item import AgendaItem self.config.include('arche.testing.catalog') self.root = bootstrap_and_fixture(self.config) self.root['ai'] = ai = AgendaItem() ai['poll'] = self.poll = Poll() return MajorityPollPlugin( ai['poll'] )
def _make_obj(self): from voteit.core.plugins.majority_poll import MajorityPollPlugin from voteit.core.models.poll import Poll from voteit.core.models.agenda_item import AgendaItem ai = AgendaItem() ai['poll'] = self.poll = Poll() return MajorityPollPlugin(ai['poll'])
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
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')
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)
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)
def _fixture(self): """ Normal context for this view is an agenda item. """ from voteit.core.models.user import User from voteit.core.models.agenda_item import AgendaItem from voteit.core.models.meeting import Meeting from voteit.core.models.poll import Poll self.config.include('voteit.core.plugins.majority_poll') root = bootstrap_and_fixture(self.config) root.users['dummy'] = User() root['m'] = meeting = Meeting() meeting['ai'] = ai = AgendaItem() ai['poll'] = Poll(start_time=utcnow(), end_time=utcnow()) ai['poll'].set_field_value('poll_plugin', 'majority_poll') return ai
def _make_poll(self): from voteit.core.models.poll import Poll from voteit.core.models.proposal import Proposal self.config.include( 'voteit.core.testing_helpers.register_testing_poll') poll = Poll() poll.set_field_value('poll_plugin', "testing") proposal = Proposal() poll.set_field_value('proposals', set(proposal.uid)) return poll
def setUp(self): self.request = testing.DummyRequest() self.config = testing.setUp(request=self.request) self.config.testing_securitypolicy(userid='admin') self.config.include('arche.testing') self.config.include('arche.models.catalog') #Enable workflows self.config.include('voteit.core.testing_helpers.register_workflows') #Register poll plugin self.config.include('voteit.core.plugins.majority_poll') #Add root from voteit.core.models.site import SiteRoot self.root = root = SiteRoot() #Add users from voteit.core.models.users import Users root['users'] = users = Users() from voteit.core.models.user import User users['admin'] = User() #Add meeting from voteit.core.models.meeting import Meeting root['m'] = self.meeting = m = Meeting() #Add agenda item - needed for lookups from voteit.core.models.agenda_item import AgendaItem m['ai'] = ai = AgendaItem() #Add a poll from voteit.core.models.poll import Poll ai['poll'] = Poll() #Wrap in correct context self.poll = ai['poll'] #Select plugin to use from voteit.core.plugins.majority_poll import MajorityPollPlugin self.poll.set_field_value('poll_plugin', MajorityPollPlugin.name) #Add proposals from voteit.core.models.proposal import Proposal p1 = Proposal(text = 'p1', creators = ['admin'], aid = 'one') p1.uid = 'p1uid' #To make it simpler to test against ai['p1'] = p1 p2 = Proposal(text = 'p2', creators = ['admin'], aid = 'two') p2.uid = 'p2uid' #To make it simpler to test against ai['p2'] = p2 #Select proposals for this poll self.poll.proposal_uids = (p1.uid, p2.uid, ) self.ai = ai
def _fixture(self): #register as adapter self.config.registry.registerAdapter(self._cut, name=self._cut.name) self.config.include('arche.testing.catalog') root = bootstrap_and_fixture(self.config) #Add agenda item - needed for lookups root['ai'] = ai = AgendaItem() #Add a poll ai['poll'] = Poll() #Wrap in correct context poll = ai['poll'] #Add proposals ai['p1'] = p1 = Proposal(text='p1', uid='p1uid') ai['p2'] = p2 = Proposal(text='p2', uid='p2uid') #Select proposals for this poll poll.proposal_uids = ( p1.uid, p2.uid, ) poll.set_field_value('poll_plugin', 'dutt_poll') return ai
def test_verify_obj_implementation(self): obj = self._cut(Poll()) self.failUnless(verifyObject(IPollPlugin, obj))
def test_verify_object(self): self.failUnless(verifyObject(IPollPlugin, self._cut(Poll())))
def test_poll_plugin(self): poll = Poll() self.failUnless( self.config.registry.queryAdapter(poll, IPollPlugin, name=u'dutt_poll'))
def test_get_settings_schema(self): obj = self._cut(Poll()) schema = obj.get_settings_schema() self.assertIsInstance(schema, colander.SchemaNode) self.assertNotIn('winners', schema)