示例#1
0
    def test_doNotAddExistingToEvent(self):
        """
        If the inviter randomly selects a user which is already an
        invitee on the event, a different user is added instead.
        """
        selfNumber = 1
        _ignore_vevent, event, _ignore_calendar, client = self._simpleAccount(
            selfNumber, INVITED_EVENT)

        invitee = tuple(event.component.mainComponent().properties('ATTENDEE'))[0]
        inviteeNumber = int(invitee.parameterValue('CN').split()[1])
        anotherNumber = inviteeNumber + 5
        values = [inviteeNumber - selfNumber, anotherNumber - selfNumber]

        inviter = Inviter(Clock(), self.sim, client, selfNumber)
        inviter.setParameters(inviteeDistribution=SequentialDistribution(values))
        inviter._invite()
        attendees = tuple(event.component.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 3)
        for paramname, paramvalue in {
            'CN': 'User %02d' % (anotherNumber,),
            'CUTYPE': 'INDIVIDUAL',
            'PARTSTAT': 'NEEDS-ACTION',
            'ROLE': 'REQ-PARTICIPANT',
            'RSVP': 'TRUE'
        }.items():
            self.assertTrue(attendees[2].hasParameter(paramname))
            self.assertEqual(attendees[2].parameterValue(paramname), paramvalue)
示例#2
0
    def test_doNotAddSelfToEvent(self):
        """
        If the inviter randomly selects its own user to be added to
        the attendee list, a different user is added instead.
        """
        selfNumber = 12
        _ignore_vevent, event, _ignore_calendar, client = self._simpleAccount(
            selfNumber, SIMPLE_EVENT)

        otherNumber = 20
        values = [selfNumber - selfNumber, otherNumber - selfNumber]

        inviter = Inviter(Clock(), self.sim, client, selfNumber)
        inviter.setParameters(inviteeDistribution=SequentialDistribution(values))
        inviter._invite()
        attendees = tuple(event.component.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 1)
        for paramname, paramvalue in {
            'CN': 'User %d' % (otherNumber,),
            'CUTYPE': 'INDIVIDUAL',
            'PARTSTAT': 'NEEDS-ACTION',
            'ROLE': 'REQ-PARTICIPANT',
            'RSVP': 'TRUE'
        }.items():
            self.assertTrue(attendees[0].hasParameter(paramname))
            self.assertEqual(attendees[0].parameterValue(paramname), paramvalue)
示例#3
0
 def test_doNotAddAttendeeToNoCalendars(self):
     """
     When there are no calendars and no events at all, the inviter
     does nothing.
     """
     userNumber = 13
     client = StubClient(userNumber, self.mktemp())
     inviter = Inviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertEquals(client._events, {})
     self.assertEquals(client._calendars, {})
示例#4
0
 def test_doNotAddAttendeeToNoCalendars(self):
     """
     When there are no calendars and no events at all, the inviter
     does nothing.
     """
     userNumber = 13
     client = StubClient(userNumber, self.mktemp())
     inviter = Inviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertEquals(client._events, {})
     self.assertEquals(client._calendars, {})
示例#5
0
    def test_enabled(self):
        userNumber = 13
        client = StubClient(userNumber, self.mktemp())

        inviter = Inviter(None, self.sim, client, userNumber,
                          **{"enabled": False})
        self.assertEqual(inviter.enabled, False)

        inviter = Inviter(None, self.sim, client, userNumber,
                          **{"enabled": True})
        self.assertEqual(inviter.enabled, True)
示例#6
0
 def test_doNotAddAttendeeToInbox(self):
     """
     When the only calendar with any events is a schedule inbox, no
     attempt is made to add attendees to an event on that calendar.
     """
     userNumber = 10
     vevent, _ignore_event, calendar, client = self._simpleAccount(
         userNumber, SIMPLE_EVENT)
     calendar.resourceType = caldavxml.schedule_inbox
     inviter = Inviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertFalse(vevent.mainComponent().hasProperty('ATTENDEE'))
示例#7
0
 def test_doNotAddAttendeeToInbox(self):
     """
     When the only calendar with any events is a schedule inbox, no
     attempt is made to add attendees to an event on that calendar.
     """
     userNumber = 10
     vevent, _ignore_event, calendar, client = self._simpleAccount(
         userNumber, SIMPLE_EVENT)
     calendar.resourceType = caldavxml.schedule_inbox
     inviter = Inviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertFalse(vevent.mainComponent().hasProperty('ATTENDEE'))
示例#8
0
 def test_doNotAddAttendeeToUninitializedEvent(self):
     """
     When there is an L{Event} on a calendar but the details of the
     event have not yet been retrieved, no attempt is made to add
     invitees to that event.
     """
     userNumber = 19
     _ignore_vevent, event, calendar, client = self._simpleAccount(
         userNumber, SIMPLE_EVENT)
     event.component = event.etag = event.scheduleTag = None
     inviter = Inviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertEquals(client._events, {event.url: event})
     self.assertEquals(client._calendars, {calendar.url: calendar})
示例#9
0
 def test_doNotAddAttendeeToUninitializedEvent(self):
     """
     When there is an L{Event} on a calendar but the details of the
     event have not yet been retrieved, no attempt is made to add
     invitees to that event.
     """
     userNumber = 19
     _ignore_vevent, event, calendar, client = self._simpleAccount(
         userNumber, SIMPLE_EVENT)
     event.component = event.etag = event.scheduleTag = None
     inviter = Inviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertEquals(client._events, {event.url: event})
     self.assertEquals(client._calendars, {calendar.url: calendar})
示例#10
0
 def test_everybodyInvitedAlready(self):
     """
     If the first so-many randomly selected users we come across
     are already attendees on the event, the invitation attempt is
     abandoned.
     """
     selfNumber = 1
     vevent, _ignore_event, _ignore_calendar, client = self._simpleAccount(
         selfNumber, INVITED_EVENT)
     inviter = Inviter(Clock(), self.sim, client, selfNumber)
     # Always return a user number which has already been invited.
     inviter.setParameters(inviteeDistribution=Deterministic(2 - selfNumber))
     inviter._invite()
     attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
     self.assertEquals(len(attendees), 2)
示例#11
0
    def test_doNotAddInviteToInbox(self):
        """
        When the only calendar with any events is a schedule inbox, no
        attempt is made to add attendees to that calendar.
        """
        calendar = Calendar(caldavxml.schedule_inbox, set(), u'inbox',
                            u'/sched/inbox', None)
        userNumber = 13
        client = StubClient(userNumber, self.mktemp())
        client._calendars.update({calendar.url: calendar})

        inviter = Inviter(None, self.sim, client, userNumber,
                          **{"enabled": False})
        inviter._invite()

        self.assertEquals(client._events, {})
示例#12
0
 def test_doNotInviteToSomeoneElsesEvent(self):
     """
     If there are events on our calendar which are being organized
     by someone else, the inviter does not attempt to invite new
     users to them.
     """
     selfNumber = 2
     vevent, _ignore_event, _ignore_calendar, client = self._simpleAccount(
         selfNumber, INVITED_EVENT)
     inviter = Inviter(None, self.sim, client, selfNumber)
     # Try to send an invitation, but with only one event on the
     # calendar, of which we are not the organizer.  It should be
     # unchanged afterwards.
     inviter._invite()
     attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
     self.assertEqual(len(attendees), 2)
     self.assertEqual(attendees[0].parameterValue('CN'), 'User 01')
     self.assertEqual(attendees[1].parameterValue('CN'), 'User 02')
示例#13
0
 def test_doNotInviteToSomeoneElsesEvent(self):
     """
     If there are events on our calendar which are being organized
     by someone else, the inviter does not attempt to invite new
     users to them.
     """
     selfNumber = 2
     vevent, _ignore_event, _ignore_calendar, client = self._simpleAccount(
         selfNumber, INVITED_EVENT)
     inviter = Inviter(None, self.sim, client, selfNumber)
     # Try to send an invitation, but with only one event on the
     # calendar, of which we are not the organizer.  It should be
     # unchanged afterwards.
     inviter._invite()
     attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
     self.assertEqual(len(attendees), 2)
     self.assertEqual(attendees[0].parameterValue('CN'), 'User 01')
     self.assertEqual(attendees[1].parameterValue('CN'), 'User 02')
示例#14
0
    def test_doNotAddExistingToEvent(self):
        """
        If the inviter randomly selects a user which is already an
        invitee on the event, a different user is added instead.
        """
        selfNumber = 1
        _ignore_vevent, event, _ignore_calendar, client = self._simpleAccount(
            selfNumber, INVITED_EVENT)

        invitee = tuple(
            event.component.mainComponent().properties('ATTENDEE'))[0]
        inviteeNumber = int(invitee.parameterValue('CN').split()[1])
        anotherNumber = inviteeNumber + 5
        values = [inviteeNumber - selfNumber, anotherNumber - selfNumber]

        inviter = Inviter(Clock(), self.sim, client, selfNumber)
        inviter.setParameters(
            inviteeDistribution=SequentialDistribution(values))
        inviter._invite()
        attendees = tuple(
            event.component.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 3)
        for paramname, paramvalue in {
                'CN': 'User %02d' % (anotherNumber, ),
                'CUTYPE': 'INDIVIDUAL',
                'PARTSTAT': 'NEEDS-ACTION',
                'ROLE': 'REQ-PARTICIPANT',
                'RSVP': 'TRUE'
        }.items():
            self.assertTrue(attendees[2].hasParameter(paramname))
            self.assertEqual(attendees[2].parameterValue(paramname),
                             paramvalue)
示例#15
0
    def test_doNotAddSelfToEvent(self):
        """
        If the inviter randomly selects its own user to be added to
        the attendee list, a different user is added instead.
        """
        selfNumber = 12
        _ignore_vevent, event, _ignore_calendar, client = self._simpleAccount(
            selfNumber, SIMPLE_EVENT)

        otherNumber = 20
        values = [selfNumber - selfNumber, otherNumber - selfNumber]

        inviter = Inviter(Clock(), self.sim, client, selfNumber)
        inviter.setParameters(
            inviteeDistribution=SequentialDistribution(values))
        inviter._invite()
        attendees = tuple(
            event.component.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 1)
        for paramname, paramvalue in {
                'CN': 'User %d' % (otherNumber, ),
                'CUTYPE': 'INDIVIDUAL',
                'PARTSTAT': 'NEEDS-ACTION',
                'ROLE': 'REQ-PARTICIPANT',
                'RSVP': 'TRUE'
        }.items():
            self.assertTrue(attendees[0].hasParameter(paramname))
            self.assertEqual(attendees[0].parameterValue(paramname),
                             paramvalue)
示例#16
0
    def test_doNotAddExistingToEvent(self):
        """
        If the inviter randomly selects a user which is already an
        invitee on the event, a different user is added instead.
        """
        calendar = Calendar(caldavxml.calendar, set(('VEVENT', )),
                            u'personal stuff', u'/cals/personal', None)
        selfNumber = 1
        client = StubClient(selfNumber, self.mktemp())
        client._calendars.update({calendar.url: calendar})

        inviteeNumber = 20
        anotherNumber = inviteeNumber + 5
        values = [
            inviteeNumber - selfNumber, inviteeNumber - selfNumber,
            anotherNumber - selfNumber
        ]

        inviter = Inviter(Clock(), self.sim, client, selfNumber)
        inviter.setParameters(
            inviteeDistribution=SequentialDistribution(values),
            inviteeCountDistribution=Deterministic(2))
        inviter._invite()
        self.assertEquals(len(client._events), 1)
        attendees = tuple(client._events.values()
                          [0].component.mainComponent().properties('ATTENDEE'))
        expected = set((
            "mailto:user%[email protected]" % (selfNumber, ),
            "mailto:user%[email protected]" % (inviteeNumber, ),
            "mailto:user%[email protected]" % (anotherNumber, ),
        ))
        for attendee in attendees:
            expected.remove(attendee.value())
        self.assertEqual(len(expected), 0)
示例#17
0
 def test_addInvite(self):
     """
     When there is a normal calendar, inviter adds an invite to it.
     """
     calendar = Calendar(caldavxml.calendar, set(('VEVENT', )),
                         u'personal stuff', u'/cals/personal', None)
     userNumber = 16
     serializePath = self.mktemp()
     os.mkdir(serializePath)
     client = StubClient(userNumber, self.mktemp())
     client._calendars.update({calendar.url: calendar})
     inviter = Inviter(Clock(), self.sim, client, userNumber)
     inviter.setParameters(inviteeDistribution=Deterministic(1),
                           inviteeCountDistribution=Deterministic(1))
     inviter._invite()
     self.assertEquals(len(client._events), 1)
     attendees = tuple(client._events.values()
                       [0].component.mainComponent().properties('ATTENDEE'))
     expected = set((
         "mailto:user%[email protected]" % (userNumber, ),
         "mailto:user%[email protected]" % (userNumber + 1, ),
     ))
     for attendee in attendees:
         expected.remove(attendee.value())
     self.assertEqual(len(expected), 0)
示例#18
0
 def test_addAttendeeToEvent(self):
     """
     When there is a normal calendar with an event, inviter adds an
     attendee to it.
     """
     userNumber = 16
     _ignore_vevent, event, _ignore_calendar, client = self._simpleAccount(
         userNumber, SIMPLE_EVENT)
     inviter = Inviter(Clock(), self.sim, client, userNumber)
     inviter.setParameters(inviteeDistribution=Deterministic(1))
     inviter._invite()
     attendees = tuple(event.component.mainComponent().properties('ATTENDEE'))
     self.assertEquals(len(attendees), 1)
     for paramname, paramvalue in {
         'CN': 'User %d' % (userNumber + 1,),
         'CUTYPE': 'INDIVIDUAL',
         'PARTSTAT': 'NEEDS-ACTION',
         'ROLE': 'REQ-PARTICIPANT',
         'RSVP': 'TRUE'
     }.items():
         self.assertTrue(attendees[0].hasParameter(paramname))
         self.assertEqual(attendees[0].parameterValue(paramname), paramvalue)
示例#19
0
 def test_everybodyInvitedAlready(self):
     """
     If the first so-many randomly selected users we come across
     are already attendees on the event, the invitation attempt is
     abandoned.
     """
     selfNumber = 1
     vevent, _ignore_event, _ignore_calendar, client = self._simpleAccount(
         selfNumber, INVITED_EVENT)
     inviter = Inviter(Clock(), self.sim, client, selfNumber)
     # Always return a user number which has already been invited.
     inviter.setParameters(inviteeDistribution=Deterministic(2 -
                                                             selfNumber))
     inviter._invite()
     attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
     self.assertEquals(len(attendees), 2)
示例#20
0
 def test_everybodyInvitedAlready(self):
     """
     If the first so-many randomly selected users we come across
     are already attendees on the event, the invitation attempt is
     abandoned.
     """
     calendar = Calendar(caldavxml.calendar, set(('VEVENT', )),
                         u'personal stuff', u'/cals/personal', None)
     userNumber = 1
     client = StubClient(userNumber, self.mktemp())
     client._calendars.update({calendar.url: calendar})
     inviter = Inviter(Clock(), self.sim, client, userNumber)
     inviter.setParameters(inviteeDistribution=Deterministic(1),
                           inviteeCountDistribution=Deterministic(2))
     inviter._invite()
     self.assertEquals(len(client._events), 0)
示例#21
0
 def test_addAttendeeToEvent(self):
     """
     When there is a normal calendar with an event, inviter adds an
     attendee to it.
     """
     userNumber = 16
     _ignore_vevent, event, _ignore_calendar, client = self._simpleAccount(
         userNumber, SIMPLE_EVENT)
     inviter = Inviter(Clock(), self.sim, client, userNumber)
     inviter.setParameters(inviteeDistribution=Deterministic(1))
     inviter._invite()
     attendees = tuple(
         event.component.mainComponent().properties('ATTENDEE'))
     self.assertEquals(len(attendees), 1)
     for paramname, paramvalue in {
             'CN': 'User %d' % (userNumber + 1, ),
             'CUTYPE': 'INDIVIDUAL',
             'PARTSTAT': 'NEEDS-ACTION',
             'ROLE': 'REQ-PARTICIPANT',
             'RSVP': 'TRUE'
     }.items():
         self.assertTrue(attendees[0].hasParameter(paramname))
         self.assertEqual(attendees[0].parameterValue(paramname),
                          paramvalue)