twistedcaldav.ical.Component.fromString

Here are the examples of the python api twistedcaldav.ical.Component.fromString taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: ccs-calendarserver
Source File: test_export.py
View license
    @inlineCallbacks
    def test_emptyCalendar(self):
        """
        Exporting an empty calendar results in an empty calendar.
        """
        io = StringIO()
        value = yield exportToFile([], io)
        # it doesn't return anything, it writes to the file.
        self.assertEquals(value, None)
        # but it should write a valid component to the file.
        self.assertEquals(Component.fromString(io.getvalue()),
                          Component.newCalendar())

Example 2

Project: ccs-calendarserver
Source File: test_export.py
View license
    @inlineCallbacks
    def test_emptyCalendar(self):
        """
        Exporting an empty calendar results in an empty calendar.
        """
        io = StringIO()
        value = yield exportToFile([], io)
        # it doesn't return anything, it writes to the file.
        self.assertEquals(value, None)
        # but it should write a valid component to the file.
        self.assertEquals(Component.fromString(io.getvalue()),
                          Component.newCalendar())

Example 3

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def _simpleAccount(self, userNumber, eventText):
        client = StubClient(userNumber, self.mktemp())
        vevent = Component.fromString(eventText)
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', u'/cal/', None)
        event = Event(client.serializeLocation(), calendar.url + u'1234.ics', None, vevent)
        calendar.events = {u'1234.ics': event}
        client._events.update({event.url: event})
        client._calendars.update({calendar.url: calendar})

        return vevent, event, calendar, client

Example 4

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def test_ignoreAccepted(self):
        """
        If the client is an attendee on an event but the PARTSTAT is
        not NEEDS-ACTION, the event is ignored.
        """
        vevent = Component.fromString(ACCEPTED_EVENT)
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        userNumber = int(attendees[1].parameterValue('CN').split(None, 1)[1])
        calendarURL = '/some/calendar/'
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', calendarURL, None)
        client = StubClient(userNumber, self.mktemp())
        client._calendars[calendarURL] = calendar
        event = Event(client.serializeLocation(), calendarURL + u'1234.ics', None, vevent)
        client._events[event.url] = event
        accepter = Accepter(None, self.sim, client, userNumber)
        accepter.eventChanged(event.url)

Example 5

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def _simpleAccount(self, userNumber, eventText):
        client = StubClient(userNumber, self.mktemp())
        vevent = Component.fromString(eventText)
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', u'/cal/', None)
        event = Event(client.serializeLocation(), calendar.url + u'1234.ics', None, vevent)
        calendar.events = {u'1234.ics': event}
        client._events.update({event.url: event})
        client._calendars.update({calendar.url: calendar})

        return vevent, event, calendar, client

Example 6

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def test_ignoreAccepted(self):
        """
        If the client is an attendee on an event but the PARTSTAT is
        not NEEDS-ACTION, the event is ignored.
        """
        vevent = Component.fromString(ACCEPTED_EVENT)
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        userNumber = int(attendees[1].parameterValue('CN').split(None, 1)[1])
        calendarURL = '/some/calendar/'
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', calendarURL, None)
        client = StubClient(userNumber, self.mktemp())
        client._calendars[calendarURL] = calendar
        event = Event(client.serializeLocation(), calendarURL + u'1234.ics', None, vevent)
        client._events[event.url] = event
        accepter = Accepter(None, self.sim, client, userNumber)
        accepter.eventChanged(event.url)

Example 7

View license
    def test_empty(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData()
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), data)

Example 8

View license
    def test_public_default(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        for item in (data, Component.fromString(data),):
            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, True).filter(item)), data)
            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, False).filter(item)), data)

Example 9

View license
    def test_public_none(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        for item in (data, Component.fromString(data),):
            self.assertEqual(str(PrivateEventFilter(None, True).filter(item)), data)
            self.assertEqual(str(PrivateEventFilter(None, False).filter(item)), data)

Example 10

View license
    def test_empty(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData()
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), data)

Example 11

View license
    def test_public_default(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        for item in (data, Component.fromString(data),):
            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, True).filter(item)), data)
            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, False).filter(item)), data)

Example 12

View license
    def test_public_none(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        for item in (data, Component.fromString(data),):
            self.assertEqual(str(PrivateEventFilter(None, True).filter(item)), data)
            self.assertEqual(str(PrivateEventFilter(None, False).filter(item)), data)

Example 13

View license
    @inlineCallbacks
    def populate(self):
        """
        Put the contents of the Holidays directory into the store.
        """
        record = yield self.directory.recordWithShortName(RecordType.user, u"wsanchez")
        yield self.transactionUnderTest().calendarHomeWithUID(record.uid, create=True)
        calendar = yield self.calendarUnderTest(name="calendar", home=record.uid)
        for f in os.listdir(self.holidays_dir):
            if f.endswith(".ics"):
                with open(os.path.join(self.holidays_dir, f)) as fin:
                    component = Component.fromString(fin.read())
                yield calendar._createCalendarObjectWithNameInternal(f, component, internal_state=ComponentUpdateState.RAW)
        yield self.commit()

Example 14

View license
    @inlineCallbacks
    def populate(self):
        """
        Put the contents of the Holidays directory into the store.
        """
        record = yield self.directory.recordWithShortName(RecordType.user, u"wsanchez")
        yield self.transactionUnderTest().calendarHomeWithUID(record.uid, create=True)
        calendar = yield self.calendarUnderTest(name="calendar", home=record.uid)
        for f in os.listdir(self.holidays_dir):
            if f.endswith(".ics"):
                with open(os.path.join(self.holidays_dir, f)) as fin:
                    component = Component.fromString(fin.read())
                yield calendar._createCalendarObjectWithNameInternal(f, component, internal_state=ComponentUpdateState.RAW)
        yield self.commit()

Example 15

View license
    @inlineCallbacks
    def _setCalendarData(self, data, user, name=None):
        if name is None:
            items = (yield self._listCalendarObjects(user))
            name = items[0]

        calendar_resource = (yield self.calendarObjectUnderTest(name=name, home=user))
        yield calendar_resource.setComponent(Component.fromString(data))
        yield self.commit()

Example 16

Project: ccs-calendarserver
Source File: inbound.py
View license
    @inlineCallbacks
    def doWork(self):
        calendar = Component.fromString(self.icalendarText)
        try:
            yield injectMessage(self.transaction, self.organizer, self.attendee, calendar)
        except:
            log.error("Unable to process reply")

Example 17

Project: ccs-calendarserver
Source File: outbound.py
View license
    @inlineCallbacks
    def doWork(self):
        """
        Send an outbound IMIP message
        """
        mailSender = self.getMailSender()
        if mailSender is not None:
            calendar = Component.fromString(self.icalendarText)
            yield mailSender.outbound(
                self.transaction,
                self.fromAddr, self.toAddr, calendar)

Example 18

Project: ccs-calendarserver
Source File: test_outbound.py
View license
    def generateSampleEmail(self, caltext=initialInviteText):
        """
        Invoke L{MailHandler.generateEmail} and parse the result.
        """
        calendar = Component.fromString(caltext)
        msgID, msgTxt = self.sender.generateEmail(
            inviteState='new',
            calendar=calendar,
            orgEmail=u"[email protected]",
            orgCN=u"User Z\xe9ro One",
            attendees=[(u"Us\xe9r One", "[email protected]"),
                       (u"User 2", "[email protected]")],
            fromAddress="[email protected]",
            replyToAddress="[email protected]",
            toAddress="[email protected]",
        )
        message = email.message_from_string(msgTxt)
        return msgID, message

Example 19

Project: ccs-calendarserver
Source File: test_outbound.py
View license
    def test_generateEmail_noOrganizerCN(self):
        """
        L{MailHandler.generateEmail} generates a MIME-formatted email when
        the organizer property has no CN parameter.
        """
        calendar = Component.fromString(initialInviteText)
        _ignore_msgID, msgTxt = self.sender.generateEmail(
            inviteState='new',
            calendar=calendar,
            orgEmail=u"[email protected]",
            orgCN=None,
            attendees=[(u"Us\xe9r One", "[email protected]"),
                       (u"User 2", "[email protected]")],
            fromAddress="[email protected]",
            replyToAddress="[email protected]",
            toAddress="[email protected]",
        )
        message = email.message_from_string(msgTxt)
        self.assertTrue(message is not None)

Example 20

Project: ccs-calendarserver
Source File: test_outbound.py
View license
    def test_generateEmail_noAttendeeCN(self):
        """
        L{MailHandler.generateEmail} generates a MIME-formatted email when
        the attendee property has no CN parameter.
        """
        calendar = Component.fromString(initialInviteText)
        _ignore_msgID, msgTxt = self.sender.generateEmail(
            inviteState='new',
            calendar=calendar,
            orgEmail=u"[email protected]",
            orgCN=u"User Z\xe9ro One",
            attendees=[(None, "[email protected]"),
                       (None, "[email protected]")],
            fromAddress="[email protected]",
            replyToAddress="[email protected]",
            toAddress="[email protected]",
        )
        message = email.message_from_string(msgTxt)
        self.assertTrue(message is not None)

Example 21

View license
    @inlineCallbacks
    def _setCalendarData(self, data, user, name=None):
        if name is None:
            items = (yield self._listCalendarObjects(user))
            name = items[0]

        calendar_resource = (yield self.calendarObjectUnderTest(name=name, home=user))
        yield calendar_resource.setComponent(Component.fromString(data))
        yield self.commit()

Example 22

Project: ccs-calendarserver
Source File: test_delivery.py
View license
        def __init__(self, txn, organizer, caldata=None):
            self.txn = txn
            self.organizer = CalendarUser(organizer)
            self.calendar = Component.fromString(caldata) if caldata else None
            self.isiTIPRequest = True
            self.isfreebusy = False

Example 23

Project: ccs-calendarserver
Source File: inbound.py
View license
    @inlineCallbacks
    def doWork(self):
        calendar = Component.fromString(self.icalendarText)
        try:
            yield injectMessage(self.transaction, self.organizer, self.attendee, calendar)
        except:
            log.error("Unable to process reply")

Example 24

Project: ccs-calendarserver
Source File: outbound.py
View license
    @inlineCallbacks
    def doWork(self):
        """
        Send an outbound IMIP message
        """
        mailSender = self.getMailSender()
        if mailSender is not None:
            calendar = Component.fromString(self.icalendarText)
            yield mailSender.outbound(
                self.transaction,
                self.fromAddr, self.toAddr, calendar)

Example 25

Project: ccs-calendarserver
Source File: test_outbound.py
View license
    def generateSampleEmail(self, caltext=initialInviteText):
        """
        Invoke L{MailHandler.generateEmail} and parse the result.
        """
        calendar = Component.fromString(caltext)
        msgID, msgTxt = self.sender.generateEmail(
            inviteState='new',
            calendar=calendar,
            orgEmail=u"[email protected]",
            orgCN=u"User Z\xe9ro One",
            attendees=[(u"Us\xe9r One", "[email protected]"),
                       (u"User 2", "[email protected]")],
            fromAddress="[email protected]",
            replyToAddress="[email protected]",
            toAddress="[email protected]",
        )
        message = email.message_from_string(msgTxt)
        return msgID, message

Example 26

Project: ccs-calendarserver
Source File: test_outbound.py
View license
    def test_generateEmail_noOrganizerCN(self):
        """
        L{MailHandler.generateEmail} generates a MIME-formatted email when
        the organizer property has no CN parameter.
        """
        calendar = Component.fromString(initialInviteText)
        _ignore_msgID, msgTxt = self.sender.generateEmail(
            inviteState='new',
            calendar=calendar,
            orgEmail=u"[email protected]",
            orgCN=None,
            attendees=[(u"Us\xe9r One", "[email protected]"),
                       (u"User 2", "[email protected]")],
            fromAddress="[email protected]",
            replyToAddress="[email protected]",
            toAddress="[email protected]",
        )
        message = email.message_from_string(msgTxt)
        self.assertTrue(message is not None)

Example 27

Project: ccs-calendarserver
Source File: test_outbound.py
View license
    def test_generateEmail_noAttendeeCN(self):
        """
        L{MailHandler.generateEmail} generates a MIME-formatted email when
        the attendee property has no CN parameter.
        """
        calendar = Component.fromString(initialInviteText)
        _ignore_msgID, msgTxt = self.sender.generateEmail(
            inviteState='new',
            calendar=calendar,
            orgEmail=u"[email protected]",
            orgCN=u"User Z\xe9ro One",
            attendees=[(None, "[email protected]"),
                       (None, "[email protected]")],
            fromAddress="[email protected]",
            replyToAddress="[email protected]",
            toAddress="[email protected]",
        )
        message = email.message_from_string(msgTxt)
        self.assertTrue(message is not None)

Example 28

View license
    def iCalendar(self):
        with self.fp.open() as f:
            text = f.read()
        try:
            component = Component.fromString(text)
            # Fix any bogus data we can
            component.validCalendarData()
            component.validCalendarForCalDAV(methodAllowed=False)
        except InvalidICalendarDataError, e:
            raise InternalDataStoreError(
                "File corruption detected (%s) in file: %s"
                % (e, self._path.path)
            )
        return component

Example 29

Project: ccs-calendarserver
Source File: util.py
View license
    def assertEqualCalendarData(self, cal1, cal2):
        if isinstance(cal1, str):
            cal1 = Component.fromString(cal1)
        if isinstance(cal2, str):
            cal2 = Component.fromString(cal2)
        ncal1 = normalize_iCalStr(cal1)
        ncal2 = normalize_iCalStr(cal2)
        self.assertEqual(ncal1, ncal2, msg=diff_iCalStrs(ncal1, ncal2))

Example 30

Project: ccs-calendarserver
Source File: test_delivery.py
View license
        def __init__(self, txn, organizer, caldata=None):
            self.txn = txn
            self.organizer = CalendarUser(organizer)
            self.calendar = Component.fromString(caldata) if caldata else None
            self.isiTIPRequest = True
            self.isfreebusy = False

Example 31

View license
    @inlineCallbacks
    def test_objectresource_loadallobjects(self):
        """
        Test that a remote home child L{objectResources} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")
        objects = yield calendar.objectResources()
        self.assertEqual(len(objects), 1)
        self.assertEqual(objects[0].name(), "1.ics")
        yield self.commitTransaction(1)

Example 32

View license
    @inlineCallbacks
    def test_objectresource_listobjects(self):
        """
        Test that a remote home child L{listObjectResources} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")
        names = yield calendar.listObjectResources()
        self.assertEqual(set(names), set(("1.ics", "2.ics",)))
        yield self.commitTransaction(1)

Example 33

View license
    @inlineCallbacks
    def test_objectresource_countobjects(self):
        """
        Test that a remote home child L{countObjectResources} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")
        count = yield calendar.countObjectResources()
        self.assertEqual(count, 2)
        yield self.commitTransaction(1)

Example 34

View license
    def iCalendar(self):
        with self.fp.open() as f:
            text = f.read()
        try:
            component = Component.fromString(text)
            # Fix any bogus data we can
            component.validCalendarData()
            component.validCalendarForCalDAV(methodAllowed=False)
        except InvalidICalendarDataError, e:
            raise InternalDataStoreError(
                "File corruption detected (%s) in file: %s"
                % (e, self._path.path)
            )
        return component

Example 35

Project: ccs-calendarserver
Source File: util.py
View license
    def assertEqualCalendarData(self, cal1, cal2):
        if isinstance(cal1, str):
            cal1 = Component.fromString(cal1)
        if isinstance(cal2, str):
            cal2 = Component.fromString(cal2)
        ncal1 = normalize_iCalStr(cal1)
        ncal2 = normalize_iCalStr(cal2)
        self.assertEqual(ncal1, ncal2, msg=diff_iCalStrs(ncal1, ncal2))

Example 36

View license
    @inlineCallbacks
    def test_objectresource_loadallobjects(self):
        """
        Test that a remote home child L{objectResources} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")
        objects = yield calendar.objectResources()
        self.assertEqual(len(objects), 1)
        self.assertEqual(objects[0].name(), "1.ics")
        yield self.commitTransaction(1)

Example 37

View license
    @inlineCallbacks
    def test_objectresource_listobjects(self):
        """
        Test that a remote home child L{listObjectResources} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")
        names = yield calendar.listObjectResources()
        self.assertEqual(set(names), set(("1.ics", "2.ics",)))
        yield self.commitTransaction(1)

Example 38

View license
    @inlineCallbacks
    def test_objectresource_countobjects(self):
        """
        Test that a remote home child L{countObjectResources} works.
        """

        home01 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name="user01", create=True)
        self.assertTrue(home01 is not None)
        calendar01 = yield home01.childWithName("calendar")
        yield calendar01.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
        yield calendar01.createCalendarObjectWithName("2.ics", Component.fromString(self.caldata2))
        yield self.commitTransaction(0)

        home = yield self._remoteHome(self.theTransactionUnderTest(1), "user01")
        self.assertTrue(home is not None)
        calendar = yield home.childWithName("calendar")
        count = yield calendar.countObjectResources()
        self.assertEqual(count, 2)
        yield self.commitTransaction(1)

Example 39

Project: ccs-calendarserver
Source File: test_export.py
View license
    @inlineCallbacks
    def test_onlyOneVTIMEZONE(self):
        """
        C{VTIMEZONE} subcomponents with matching TZIDs in multiple event
        calendar objects should only be rendered in the resulting output once.

        (Note that the code to suppor this is actually in PyCalendar, not the
        export tool itself.)
        """
        yield populateCalendarsFrom(
            {
                "user01": {
                    "calendar1": {
                        "1.ics": (one, {}),  # EST
                        "2.ics": (another, {}),  # EST
                        "3.ics": (third, {})  # PST
                    }
                }
            }, self.store
        )

        io = StringIO()
        yield exportToFile(
            [(yield self.txn().calendarHomeWithUID("user01"))
                .calendarWithName("calendar1")], io
        )
        result = Component.fromString(io.getvalue())

        def filtered(name):
            for c in result.subcomponents():
                if c.name() == name:
                    yield c

        timezones = list(filtered("VTIMEZONE"))
        events = list(filtered("VEVENT"))

        # Sanity check to make sure we picked up all three events:
        self.assertEquals(len(events), 3)

        self.assertEquals(len(timezones), 2)
        self.assertEquals(set([tz.propertyValue("TZID") for tz in timezones]),

                          # Use an intentionally wrong TZID in order to make
                          # sure we don't depend on caching effects elsewhere.
                          set(["America/New_Yrok", "US/Pacific"]))

Example 40

Project: ccs-calendarserver
Source File: test_export.py
View license
    @inlineCallbacks
    def test_full(self):
        """
        Running C{calendarserver_export} on the command line exports an ics
        file. (Almost-full integration test, starting from the main point, using
        as few test fakes as possible.)

        Note: currently the only test for directory interaction.
        """
        yield populateCalendarsFrom(
            {
                "user02": {
                    # TODO: more direct test for skipping inbox
                    "inbox": {
                        "inbox-item.ics": (valentines, {})
                    },
                    "calendar1": {
                        "peruser.ics": (dataForTwoUsers, {}),  # EST
                    }
                }
            }, self.store
        )

        output = FilePath(self.mktemp())
        main(['calendarserver_export', '--output',
              output.path, '--user', 'user02'], reactor=self)

        yield self.waitToStop

        self.assertEquals(
            Component.fromString(resultForUser2),
            Component.fromString(output.getContent())
        )

Example 41

Project: ccs-calendarserver
Source File: test_export.py
View license
    @inlineCallbacks
    def test_onlyOneVTIMEZONE(self):
        """
        C{VTIMEZONE} subcomponents with matching TZIDs in multiple event
        calendar objects should only be rendered in the resulting output once.

        (Note that the code to suppor this is actually in PyCalendar, not the
        export tool itself.)
        """
        yield populateCalendarsFrom(
            {
                "user01": {
                    "calendar1": {
                        "1.ics": (one, {}),  # EST
                        "2.ics": (another, {}),  # EST
                        "3.ics": (third, {})  # PST
                    }
                }
            }, self.store
        )

        io = StringIO()
        yield exportToFile(
            [(yield self.txn().calendarHomeWithUID("user01"))
                .calendarWithName("calendar1")], io
        )
        result = Component.fromString(io.getvalue())

        def filtered(name):
            for c in result.subcomponents():
                if c.name() == name:
                    yield c

        timezones = list(filtered("VTIMEZONE"))
        events = list(filtered("VEVENT"))

        # Sanity check to make sure we picked up all three events:
        self.assertEquals(len(events), 3)

        self.assertEquals(len(timezones), 2)
        self.assertEquals(set([tz.propertyValue("TZID") for tz in timezones]),

                          # Use an intentionally wrong TZID in order to make
                          # sure we don't depend on caching effects elsewhere.
                          set(["America/New_Yrok", "US/Pacific"]))

Example 42

Project: ccs-calendarserver
Source File: test_export.py
View license
    @inlineCallbacks
    def test_full(self):
        """
        Running C{calendarserver_export} on the command line exports an ics
        file. (Almost-full integration test, starting from the main point, using
        as few test fakes as possible.)

        Note: currently the only test for directory interaction.
        """
        yield populateCalendarsFrom(
            {
                "user02": {
                    # TODO: more direct test for skipping inbox
                    "inbox": {
                        "inbox-item.ics": (valentines, {})
                    },
                    "calendar1": {
                        "peruser.ics": (dataForTwoUsers, {}),  # EST
                    }
                }
            }, self.store
        )

        output = FilePath(self.mktemp())
        main(['calendarserver_export', '--output',
              output.path, '--user', 'user02'], reactor=self)

        yield self.waitToStop

        self.assertEquals(
            Component.fromString(resultForUser2),
            Component.fromString(output.getContent())
        )

Example 43

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def test_acceptInvitation(self):
        """
        If the client is an attendee on an event and the PARTSTAT is
        NEEDS-ACTION, a response is generated which accepts the
        invitation and the corresponding event in the
        I{schedule-inbox} is deleted.
        """
        clock = Clock()
        randomDelay = 7
        vevent = Component.fromString(INVITED_EVENT)
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        userNumber = int(attendees[1].parameterValue('CN').split(None, 1)[1])
        client = StubClient(userNumber, self.mktemp())

        calendarURL = '/some/calendar/'
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', calendarURL, None)
        client._calendars[calendarURL] = calendar

        inboxURL = '/some/inbox/'
        inbox = Calendar(
            caldavxml.schedule_inbox, set(), u'the inbox', inboxURL, None)
        client._calendars[inboxURL] = inbox

        event = Event(client.serializeLocation(), calendarURL + u'1234.ics', None, vevent)
        client._setEvent(event.url, event)

        inboxEvent = Event(client.serializeLocation(), inboxURL + u'4321.ics', None, vevent)
        client._setEvent(inboxEvent.url, inboxEvent)

        accepter = Accepter(clock, self.sim, client, userNumber)
        accepter.setParameters(acceptDelayDistribution=Deterministic(randomDelay))
        accepter.eventChanged(event.url)
        clock.advance(randomDelay)

        vevent = client._events[event.url].component
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 2)
        self.assertEquals(
            attendees[1].parameterValue('CN'), 'User %02d' % (userNumber,))
        self.assertEquals(
            attendees[1].parameterValue('PARTSTAT'), 'ACCEPTED')
        self.assertFalse(attendees[1].hasParameter('RSVP'))

        self.assertNotIn(inboxEvent.url, client._events)
        self.assertNotIn('4321.ics', inbox.events)

Example 44

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def test_reacceptInvitation(self):
        """
        If a client accepts an invitation on an event and then is
        later re-invited to the same event, the invitation is again
        accepted.
        """
        clock = Clock()
        randomDelay = 7
        vevent = Component.fromString(INVITED_EVENT)
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        userNumber = int(attendees[1].parameterValue('CN').split(None, 1)[1])
        calendarURL = '/some/calendar/'
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', calendarURL, None)
        client = StubClient(userNumber, self.mktemp())
        client._calendars[calendarURL] = calendar
        event = Event(client.serializeLocation(), calendarURL + u'1234.ics', None, vevent)
        client._events[event.url] = event
        accepter = Accepter(clock, self.sim, client, userNumber)
        accepter.setParameters(acceptDelayDistribution=Deterministic(randomDelay))
        accepter.eventChanged(event.url)
        clock.advance(randomDelay)

        # Now re-set the event so it has to be accepted again
        event.component = Component.fromString(INVITED_EVENT)

        # And now re-deliver it
        accepter.eventChanged(event.url)
        clock.advance(randomDelay)

        # And ensure that it was accepted again
        vevent = client._events[event.url].component
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 2)
        self.assertEquals(
            attendees[1].parameterValue('CN'), 'User %02d' % (userNumber,))
        self.assertEquals(
            attendees[1].parameterValue('PARTSTAT'), 'ACCEPTED')
        self.assertFalse(attendees[1].hasParameter('RSVP'))

Example 45

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def test_acceptInvitation(self):
        """
        If the client is an attendee on an event and the PARTSTAT is
        NEEDS-ACTION, a response is generated which accepts the
        invitation and the corresponding event in the
        I{schedule-inbox} is deleted.
        """
        clock = Clock()
        randomDelay = 7
        vevent = Component.fromString(INVITED_EVENT)
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        userNumber = int(attendees[1].parameterValue('CN').split(None, 1)[1])
        client = StubClient(userNumber, self.mktemp())

        calendarURL = '/some/calendar/'
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', calendarURL, None)
        client._calendars[calendarURL] = calendar

        inboxURL = '/some/inbox/'
        inbox = Calendar(
            caldavxml.schedule_inbox, set(), u'the inbox', inboxURL, None)
        client._calendars[inboxURL] = inbox

        event = Event(client.serializeLocation(), calendarURL + u'1234.ics', None, vevent)
        client._setEvent(event.url, event)

        inboxEvent = Event(client.serializeLocation(), inboxURL + u'4321.ics', None, vevent)
        client._setEvent(inboxEvent.url, inboxEvent)

        accepter = Accepter(clock, self.sim, client, userNumber)
        accepter.setParameters(acceptDelayDistribution=Deterministic(randomDelay))
        accepter.eventChanged(event.url)
        clock.advance(randomDelay)

        vevent = client._events[event.url].component
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 2)
        self.assertEquals(
            attendees[1].parameterValue('CN'), 'User %02d' % (userNumber,))
        self.assertEquals(
            attendees[1].parameterValue('PARTSTAT'), 'ACCEPTED')
        self.assertFalse(attendees[1].hasParameter('RSVP'))

        self.assertNotIn(inboxEvent.url, client._events)
        self.assertNotIn('4321.ics', inbox.events)

Example 46

Project: ccs-calendarserver
Source File: test_profiles.py
View license
    def test_reacceptInvitation(self):
        """
        If a client accepts an invitation on an event and then is
        later re-invited to the same event, the invitation is again
        accepted.
        """
        clock = Clock()
        randomDelay = 7
        vevent = Component.fromString(INVITED_EVENT)
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        userNumber = int(attendees[1].parameterValue('CN').split(None, 1)[1])
        calendarURL = '/some/calendar/'
        calendar = Calendar(
            caldavxml.calendar, set(('VEVENT',)), u'calendar', calendarURL, None)
        client = StubClient(userNumber, self.mktemp())
        client._calendars[calendarURL] = calendar
        event = Event(client.serializeLocation(), calendarURL + u'1234.ics', None, vevent)
        client._events[event.url] = event
        accepter = Accepter(clock, self.sim, client, userNumber)
        accepter.setParameters(acceptDelayDistribution=Deterministic(randomDelay))
        accepter.eventChanged(event.url)
        clock.advance(randomDelay)

        # Now re-set the event so it has to be accepted again
        event.component = Component.fromString(INVITED_EVENT)

        # And now re-deliver it
        accepter.eventChanged(event.url)
        clock.advance(randomDelay)

        # And ensure that it was accepted again
        vevent = client._events[event.url].component
        attendees = tuple(vevent.mainComponent().properties('ATTENDEE'))
        self.assertEquals(len(attendees), 2)
        self.assertEquals(
            attendees[1].parameterValue('CN'), 'User %02d' % (userNumber,))
        self.assertEquals(
            attendees[1].parameterValue('PARTSTAT'), 'ACCEPTED')
        self.assertFalse(attendees[1].hasParameter('RSVP'))

Example 47

View license
    def test_vcalendar_no_effect(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        no_effect = CalendarData(
            CalendarComponent(
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)

        no_effect = CalendarData(
            CalendarComponent(
                AllComponents(),
                AllProperties(),
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)

Example 48

View license
    def test_vcalendar_no_props(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
X-WR-CALNAME:Help
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        result = """BEGIN:VCALENDAR
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData(
            CalendarComponent(
                AllComponents(),
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), result)

Example 49

View license
    def test_vcalendar_no_comp(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
X-WR-CALNAME:Help
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        result = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
X-WR-CALNAME:Help
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData(
            CalendarComponent(
                AllProperties(),
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), result)

Example 50

View license
    def test_vevent_other_component(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        result = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
END:VCALENDAR
""".replace("\n", "\r\n")

        other_component = CalendarData(
            CalendarComponent(
                CalendarComponent(
                    name="VTODO"
                ),
                AllProperties(),
                name="VCALENDAR"
            )
        )
        for item in (data, Component.fromString(data),):
            self.assertEqual(str(CalendarDataFilter(other_component).filter(item)), result)