Esempio n. 1
0
    def test_twoSimpleEvents(self):
        """
        Exporting a calendar with two events in it will result in a VCALENDAR
        component with both VEVENTs in it.
        """
        yield populateCalendarsFrom(
            {
                "user01": {
                    "calendar1": {
                        "valentines-day.ics": (valentines, {}),
                        "new-years-day.ics": (newYears, {})
                    }
                }
            }, self.store)

        expected = Component.newCalendar()
        a = Component.fromString(valentines)
        b = Component.fromString(newYears)
        for comp in a, b:
            for sub in comp.subcomponents():
                expected.addComponent(sub)

        io = StringIO()
        yield exportToFile([(yield self.txn().calendarHomeWithUID("user01")
                             ).calendarWithName("calendar1")], io)
        self.assertEquals(Component.fromString(io.getvalue()), expected)
Esempio n. 2
0
    def test_twoSimpleEvents(self):
        """
        Exporting a calendar with two events in it will result in a VCALENDAR
        component with both VEVENTs in it.
        """
        yield populateCalendarsFrom(
            {
                "home1": {
                    "calendar1": {
                        "valentines-day.ics": (valentines, {}),
                        "new-years-day.ics": (newYears, {})
                    }
                }
            }, self.store
        )

        expected = Component.newCalendar()
        a = Component.fromString(valentines)
        b = Component.fromString(newYears)
        for comp in a, b:
            for sub in comp.subcomponents():
                expected.addComponent(sub)

        io = StringIO()
        yield exportToFile(
            [(yield self.txn().calendarHomeWithUID("home1"))
              .calendarWithName("calendar1")], io
        )
        self.assertEquals(Component.fromString(io.getvalue()),
                          expected)
Esempio n. 3
0
    def test_oneEventCalendar(self):
        """
        Exporting an calendar with one event in it will result in just that
        event.
        """
        yield populateCalendarsFrom(
            {
                "home1": {
                    "calendar1": {
                        "valentines-day.ics": (valentines, {})
                    }
                }
            }, self.store
        )

        expected = Component.newCalendar()
        [theComponent] = Component.fromString(valentines).subcomponents()
        expected.addComponent(theComponent)

        io = StringIO()
        yield exportToFile(
            [(yield self.txn().calendarHomeWithUID("home1"))
              .calendarWithName("calendar1")], io
        )
        self.assertEquals(Component.fromString(io.getvalue()),
                          expected)
Esempio n. 4
0
    def test_oneEventCalendar(self):
        """
        Exporting an calendar with one event in it will result in just that
        event.
        """
        yield populateCalendarsFrom(
            {
                "user01": {
                    "calendar1": {
                        "valentines-day.ics": (valentines, {})
                    }
                }
            }, self.store
        )

        expected = Component.newCalendar()
        [theComponent] = Component.fromString(valentines).subcomponents()
        expected.addComponent(theComponent)

        io = StringIO()
        yield exportToFile(
            [(yield self.txn().calendarHomeWithUID("user01"))
                .calendarWithName("calendar1")], io
        )
        self.assertEquals(Component.fromString(io.getvalue()),
                          expected)
Esempio n. 5
0
 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())
Esempio n. 6
0
 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())
Esempio n. 7
0
 def test_mailto(self):
     """
     Verify the conversion of non-mailto: CUAs to mailto: CUAs
     """
     yield populateCalendarsFrom(
         {"user01": {
             "calendar1": {
                 "peruser.ics": (dataWithUIDs, {}),
             }
         }}, self.store)
     io = StringIO()
     yield exportToFile([(yield self.txn().calendarHomeWithUID("user01")
                          ).calendarWithName("calendar1")],
                        io,
                        convertToMailto=True)
     self.assertEquals(Component.fromString(resultWithMailtos),
                       Component.fromString(io.getvalue()))
Esempio n. 8
0
    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(
            {
                "home1": {
                    "calendar1": {
                        "1.ics": (one, {}), # EST
                        "2.ics": (another, {}), # EST
                        "3.ics": (third, {}) # PST
                    }
                }
            }, self.store
        )

        io = StringIO()
        yield exportToFile(
            [(yield self.txn().calendarHomeWithUID("home1"))
              .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"]))
Esempio n. 9
0
    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"]))
Esempio n. 10
0
 def test_perUserFiltering(self):
     """
     L{exportToFile} performs per-user component filtering based on the owner
     of that calendar.
     """
     yield populateCalendarsFrom(
         {
             "user02": {
                 "calendar1": {
                     "peruser.ics": (dataForTwoUsers, {}),  # EST
                 }
             }
         },
         self.store)
     io = StringIO()
     yield exportToFile([(yield self.txn().calendarHomeWithUID("user02")
                          ).calendarWithName("calendar1")], io)
     self.assertEquals(Component.fromString(resultForUser2),
                       Component.fromString(io.getvalue()))
Esempio n. 11
0
 def test_perUserFiltering(self):
     """
     L{exportToFile} performs per-user component filtering based on the owner
     of that calendar.
     """
     yield populateCalendarsFrom(
         {
             "user02": {
                 "calendar1": {
                     "peruser.ics": (dataForTwoUsers, {}), # EST
                 }
             }
         }, self.store
     )
     io = StringIO()
     yield exportToFile(
         [(yield self.txn().calendarHomeWithUID("user02"))
           .calendarWithName("calendar1")], io
     )
     self.assertEquals(
         Component.fromString(resultForUser2),
         Component.fromString(io.getvalue())
     )