Пример #1
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)
Пример #2
0
 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
Пример #3
0
 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
Пример #4
0
 def test_utcnow(self):
     from voteit.core.models.date_time_util import utcnow
     obj = self._make_obj()
     now = utcnow()
     self.assertEquals(now.tzinfo, pytz.utc)
     now = obj.utcnow()
     self.assertEquals(now.tzinfo, pytz.utc)
Пример #5
0
    def test_start_time(self):
        obj = self._add_mock_meeting()

        now = utcnow()
        now_unix = timegm(now.timetuple())

        #Shouldn't return anything
        self.assertEqual(
            self.query("start_time == %s and path == '/meeting'" %
                       now_unix)[0], 0)
        qy = ("%s < start_time < %s and path == '/meeting'" %
              (now_unix - 1, now_unix + 1))
        self.assertEqual(self.query(qy)[0], 0)

        #So let's set it and return stuff
        obj.set_field_value('start_time', now)
        from voteit.core.models.catalog import reindex_indexes
        reindex_indexes(self.root.catalog)

        self.assertEqual(
            self.query("start_time == %s and path == '/meeting'" %
                       now_unix)[0], 1)
        qy = ("%s < start_time < %s and path == '/meeting'" %
              (now_unix - 1, now_unix + 1))
        self.assertEqual(self.query(qy)[0], 1)
Пример #6
0
 def __init__(self, context_uid, message, tags=(), userid=None, scripted=None):
     self.created = utcnow()
     self.context_uid = context_uid
     self.message = message
     self.tags = tuple(tags)
     self.userid = userid
     self.scripted = scripted
Пример #7
0
 def __init__(self, number, token, creator):
     self.number = number
     self.created = utcnow()
     self.claimed = None
     self.claimed_by = None
     self.token = token
     self.created_by = creator
Пример #8
0
 def send(self, request, message = u""):
     if self.closed: #Just as a precaution
         return
     meeting = find_interface(self, IMeeting)
     html = render_view_action(self, request, 'email', 'invite_ticket', message = message)
     subject = _(u"Invitation to ${meeting_title}", mapping = {'meeting_title': meeting.title})
     if send_email(subject = subject, recipients = self.email, html = html, request = request, send_immediately = True):
         self.sent_dates.append(utcnow())
Пример #9
0
 def close_poll(self):
     """ Close the poll. """
     self._calculate_ballots()
     poll_plugin = self.get_poll_plugin()
     poll_plugin.handle_close()
     uid_states = poll_plugin.change_states_of()
     if uid_states:
         self.adjust_proposal_states(uid_states)
     self.set_field_appstruct({'end_time': utcnow()})
Пример #10
0
 def test_get_time_created(self):
     self.config.registry.settings['default_timezone_name'] = "Europe/Stockholm"
     self.config.include('voteit.core.models.date_time_util')
     from voteit.core.models.date_time_util import utcnow
     context = testing.DummyResource()
     context.created = utcnow()
     request = testing.DummyRequest()
     obj = self._cut(context, request)
     self.assertEqual(obj.get_time_created(context), 'Just now')
Пример #11
0
 def close_poll(self):
     """ Close the poll. """
     self._calculate_ballots()
     poll_plugin = self.get_poll_plugin()
     poll_plugin.handle_close()
     uid_states = poll_plugin.change_states_of()
     if uid_states:
         self.adjust_proposal_states(uid_states)
     self.set_field_appstruct({'end_time': utcnow()})
Пример #12
0
 def test_get_time_created(self):
     self.config.registry.settings[
         'default_timezone_name'] = "Europe/Stockholm"
     self.config.include('voteit.core.models.date_time_util')
     from voteit.core.models.date_time_util import utcnow
     context = testing.DummyResource()
     context.created = utcnow()
     request = testing.DummyRequest()
     obj = self._cut(context, request)
     self.assertEqual(obj.get_time_created(context), 'Just now')
Пример #13
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)
Пример #14
0
 def __init__(self,
              context_uid,
              message,
              tags=(),
              userid=None,
              scripted=None):
     self.created = utcnow()
     self.context_uid = context_uid
     self.message = message
     self.tags = tuple(tags)
     self.userid = userid
     self.scripted = scripted
Пример #15
0
    def test_end_time(self):
        obj = self._add_mock_meeting()

        now = utcnow()
        now_unix = timegm(now.timetuple())
        
        obj.set_field_value('end_time', now)
        from voteit.core.models.catalog import reindex_indexes
        reindex_indexes(self.root.catalog)
        
        self.assertEqual(self.query("end_time == %s and path == '/meeting'" % now_unix)[0], 1)
        qy = ("%s < end_time < %s and path == '/meeting'" % (now_unix-1, now_unix+1))
        self.assertEqual(self.query(qy)[0], 1)
Пример #16
0
 def mark_activity_for(self, userid, meeting_uid, dt = None, **kw):
     assert isinstance(meeting_uid, basestring)
     kw['dt'] = dt and dt or utcnow()
     kw['userid'] = userid
     kw['m_uid'] = meeting_uid
     try:
         us = self._storage[meeting_uid][userid]
     except KeyError:
         if meeting_uid not in self._storage:
             self._storage[meeting_uid] = OOBTree()
         us = self._storage[meeting_uid][userid] = OOBTree()
     for (k, v) in kw.items():
         us[k] = v
     return kw.keys()
Пример #17
0
 def claim(self, request):
     #Is the ticket open?
     if self.get_workflow_state() != 'open':
         raise Forbidden("Access already granted with this ticket")
     #Find required resources and do some basic validation
     meeting = find_interface(self, IMeeting)
     assert meeting
     userid = authenticated_userid(request)
     if userid is None:
         raise Forbidden("You can't claim a ticket unless you're authenticated.")
     meeting.add_groups(userid, self.roles)
     self.claimed_by = userid
     self.set_workflow_state(request, 'closed')
     self.closed = utcnow()
Пример #18
0
 def __init__(self, email, roles, message = u"", sent_by = None):
     self.email = email.lower()
     for role in roles:
         if role not in SELECTABLE_ROLES:
             raise ValueError("InviteTicket got '%s' as a role, and that isn't selectable." % role)
     self.roles = roles
     assert isinstance(message, basestring)
     self.message = message
     self.created = utcnow()
     self.closed = None
     self.claimed_by = None
     self.sent_by = sent_by
     self.token = ''.join([choice(string.letters + string.digits) for x in range(30)])
     self.sent_dates = PersistentList()
     self.uid = unicode(uuid4())
     super(InviteTicket, self).__init__()
Пример #19
0
    def test_end_time(self):
        obj = self._add_mock_meeting()

        now = utcnow()
        now_unix = timegm(now.timetuple())

        obj.set_field_value('end_time', now)
        from voteit.core.models.catalog import reindex_indexes
        reindex_indexes(self.root.catalog)

        self.assertEqual(
            self.query("end_time == %s and path == '/meeting'" % now_unix)[0],
            1)
        qy = ("%s < end_time < %s and path == '/meeting'" %
              (now_unix - 1, now_unix + 1))
        self.assertEqual(self.query(qy)[0], 1)
Пример #20
0
def crontick():

    worker = ScriptWorker('crontick')

    unixnow = timegm(utcnow().timetuple())

    #Find methods to execute and run them
    methods = _find_methods(worker)

    for method in methods:
        try:
            method(worker, unixnow)
            transaction.commit()
            print "=== Transaction for %s committed" % method
        except Exception, e:
            worker.logger.exception(e)
            transaction.abort()
            print "=== Transaction for %s aborted" % method
Пример #21
0
def crontick():
    
    worker = ScriptWorker('crontick')
    
    unixnow = timegm(utcnow().timetuple())

    #Find methods to execute and run them
    methods = _find_methods(worker)
    
    for method in methods:
        try:
            method(worker, unixnow)
            transaction.commit()
            print "=== Transaction for %s committed" % method
        except Exception, e:
            worker.logger.exception(e)
            transaction.abort()
            print "=== Transaction for %s aborted" % method
Пример #22
0
    def test_start_time(self):
        obj = self._add_mock_meeting()

        now = utcnow()
        now_unix = timegm(now.timetuple())
        
        #Shouldn't return anything
        self.assertEqual(self.query("start_time == %s and path == '/meeting'" % now_unix)[0], 0)
        qy = ("%s < start_time < %s and path == '/meeting'" % (now_unix-1, now_unix+1))
        self.assertEqual(self.query(qy)[0], 0)
        
        #So let's set it and return stuff
        obj.set_field_value('start_time', now)
        from voteit.core.models.catalog import reindex_indexes
        reindex_indexes(self.root.catalog)
        
        self.assertEqual(self.query("start_time == %s and path == '/meeting'" % now_unix)[0], 1)
        qy = ("%s < start_time < %s and path == '/meeting'" % (now_unix-1, now_unix+1))
        self.assertEqual(self.query(qy)[0], 1)
Пример #23
0
 def claim(self, userid):
     if self.claimed or self.claimed_by:
         raise TicketAlreadyClaimedError(u"Ticket already claimed")
     self.claimed = utcnow()
     self.claimed_by = userid
Пример #24
0
 def add_mention(self, userid):
     self.mentioned[userid] = utcnow()
Пример #25
0
 def start_check(self):
     self.open = True
     self.present_userids.clear()
     self.start_time = utcnow()
     self.end_time = None
Пример #26
0
 def end_check(self):
     self.open = False
     self.end_time = utcnow()
Пример #27
0
 def new_register(self, userids):
     reg = OOBTree()
     reg.update({'userids': frozenset(userids), 'time': utcnow()})
     self.registers[self.get_next_key()] = reg
Пример #28
0
 def test_validate_expired(self):
     obj = self._make_obj()
     obj.token = 'dummy'
     obj.expires = utcnow() - timedelta(days=1)
     self.assertRaises(TokenValidationError, obj.validate, 'dummy')
Пример #29
0
 def validate(self, value):
     if value != self.token:
         raise TokenValidationError("Token doesn't match.")
     if utcnow() > self.expires:
         raise TokenValidationError("Token expired.")
Пример #30
0
 def __init__(self):
     self.token = ''.join([choice(string.letters + string.digits) for x in range(30)])
     self.created = utcnow()
     self.expires = self.created + timedelta(days=3)
Пример #31
0
 def add_mention(self, userid):
     self.mentioned[userid] = utcnow()
Пример #32
0
 def __init__(self, context_uid, message, tags=()):
     self.created = utcnow()
     self.context_uid = context_uid
     self.message = message
     self.tags = tuple(tags)
Пример #33
0
 def test_validate_expired(self):
     obj = self._make_obj()
     obj.token = 'dummy'
     obj.expires = utcnow() - timedelta(days=1)
     self.assertRaises(TokenValidationError, obj.validate, 'dummy')