示例#1
0
 def test_doNotAddInviteToNoCalendars(self):
     """
     When there are no calendars and no events at all, the inviter
     does nothing.
     """
     userNumber = 13
     client = StubClient(userNumber, self.mktemp())
     inviter = RealisticInviter(None, self.sim, client, userNumber)
     inviter._invite()
     self.assertEquals(client._events, {})
     self.assertEquals(client._calendars, {})
示例#2
0
    def test_enabled(self):
        userNumber = 13
        client = StubClient(userNumber, self.mktemp())

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

        inviter = RealisticInviter(None, self.sim, client, userNumber,
                                   **{"enabled": True})
        self.assertEqual(inviter.enabled, True)
示例#3
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 = RealisticInviter(None, self.sim, client, userNumber,
                                   **{"enabled": False})
        inviter._invite()

        self.assertEquals(client._events, {})
示例#4
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 = RealisticInviter(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)
示例#5
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 = RealisticInviter(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)
示例#6
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 = RealisticInviter(Clock(), self.sim, client, userNumber)
     inviter.setParameters(inviteeDistribution=Deterministic(1),
                           inviteeCountDistribution=Deterministic(2))
     inviter._invite()
     self.assertEquals(len(client._events), 0)