Ejemplo n.º 1
0
 def test_wrapping(self):
     """
     Should support input file with a long text field covering multiple lines
     """
     test_journal = get_test_file("journal.ics")
     vobj = base.readOne(test_journal)
     vjournal = base.readOne(vobj.serialize())
     self.assertTrue('Joe, Lisa, and Bob' in vjournal.description.value)
     self.assertTrue('Tuesday.\n2.' in vjournal.description.value)
Ejemplo n.º 2
0
 def test_wrapping(self):
     """
     Should support input file with a long text field covering multiple lines
     """
     test_journal = get_test_file("journal.ics")
     vobj = base.readOne(test_journal)
     vjournal = base.readOne(vobj.serialize())
     self.assertTrue('Joe, Lisa, and Bob' in vjournal.description.value)
     self.assertTrue('Tuesday.\n2.' in vjournal.description.value)
Ejemplo n.º 3
0
 def test_vtodo(self):
     """
     Test VTodo
     """
     vtodo = get_test_file("vtodo.ics")
     obj = base.readOne(vtodo)
     obj.vtodo.add('completed')
     obj.vtodo.completed.value = datetime.datetime(2015, 5, 5, 13, 30)
     self.assertEqual(obj.vtodo.completed.serialize()[0:23],
                      'COMPLETED:20150505T1330')
     obj = base.readOne(obj.serialize())
     self.assertEqual(obj.vtodo.completed.value,
                      datetime.datetime(2015, 5, 5, 13, 30))
Ejemplo n.º 4
0
 def test_vtodo(self):
     """
     Test VTodo
     """
     vtodo = get_test_file("vtodo.ics")
     obj = base.readOne(vtodo)
     obj.vtodo.add('completed')
     obj.vtodo.completed.value = datetime.datetime(2015,5,5,13,30)
     self.assertEqual(obj.vtodo.completed.serialize()[0:23],
                      'COMPLETED:20150505T1330')
     obj = base.readOne(obj.serialize())
     self.assertEqual(obj.vtodo.completed.value,
                      datetime.datetime(2015,5,5,13,30))
Ejemplo n.º 5
0
 def setUpClass(cls):
     """
     Method for setting up class fixture before running tests in the class.
     Fetches test file.
     """
     cls.test_file = get_test_file("vcard_with_groups.ics")
     cls.card = base.readOne(cls.test_file)
Ejemplo n.º 6
0
    def test_importing(self):
        """
        Test importing ics
        """
        cal = get_test_file("standard_test.ics")
        c = base.readOne(cal, validate=True)
        self.assertEqual(
            str(c.vevent.valarm.trigger),
            "<TRIGGER{}-1 day, 0:00:00>"
        )

        self.assertEqual(
            str(c.vevent.dtstart.value),
            "2002-10-28 14:00:00-08:00"
        )
        self.assertTrue(
            isinstance(c.vevent.dtstart.value, datetime.datetime)
        )
        self.assertEqual(
            str(c.vevent.dtend.value),
            "2002-10-28 15:00:00-08:00"
        )
        self.assertTrue(
            isinstance(c.vevent.dtend.value, datetime.datetime)
        )
        self.assertEqual(
            c.vevent.dtstamp.value,
            datetime.datetime(2002, 10, 28, 1, 17, 6, tzinfo=tzutc())
        )

        vevent = c.vevent.transformFromNative()
        self.assertEqual(
            str(vevent.rrule),
            "<RRULE{}FREQ=Weekly;COUNT=10>"
        )
Ejemplo n.º 7
0
def main():
    options, args = get_options()
    if PyICU is None:
        print("Failure. change_tz requires PyICU, exiting")
    elif options.list:
        for tz_string in PyICU.TimeZone.createEnumeration():
            print(tz_string)
    elif args:
        utc_only = options.utc
        if utc_only:
            which = "only UTC"
        else:
            which = "all"
        print("Converting {0!s} events".format(which))
        ics_file = args[0]
        if len(args) > 1:
            timezone = PyICU.ICUtzinfo.getInstance(args[1])
        else:
            timezone = PyICU.ICUtzinfo.default
        print("... Reading {0!s}".format(ics_file))
        cal = base.readOne(open(ics_file))
        change_tz(cal, timezone, PyICU.ICUtzinfo.default, utc_only)

        out_name = ics_file + '.converted'
        print("... Writing {0!s}".format(out_name))

        with open(out_name, 'wb') as out:
            cal.serialize(out)

        print("Done")
Ejemplo n.º 8
0
def main():
    options, args = get_options()
    if PyICU is None:
        print("Failure. change_tz requires PyICU, exiting")
    elif options.list:
        for tz_string in PyICU.TimeZone.createEnumeration():
            print(tz_string)
    elif args:
        utc_only = options.utc
        if utc_only:
            which = "only UTC"
        else:
            which = "all"
        print("Converting {0!s} events".format(which))
        ics_file = args[0]
        if len(args) > 1:
            timezone = PyICU.ICUtzinfo.getInstance(args[1])
        else:
            timezone = PyICU.ICUtzinfo.default
        print("... Reading {0!s}".format(ics_file))
        cal = base.readOne(open(ics_file))
        change_tz(cal, timezone, PyICU.ICUtzinfo.default, utc_only)

        out_name = ics_file + '.converted'
        print("... Writing {0!s}".format(out_name))

        with open(out_name, 'wb') as out:
            cal.serialize(out)

        print("Done")
Ejemplo n.º 9
0
 def setUpClass(cls):
     """
     Method for setting up class fixture before running tests in the class.
     Fetches test file.
     """
     cls.test_file = get_test_file("vcard_with_groups.ics")
     cls.card = base.readOne(cls.test_file)
Ejemplo n.º 10
0
    def test_unicode(self):
        """
        Test unicode characters
        """
        test_cal = get_test_file("utf8_test.ics")
        vevent = base.readOne(test_cal).vevent
        vevent2 = base.readOne(vevent.serialize())
        self.assertEqual(str(vevent), str(vevent2))

        self.assertEqual(vevent.summary.value, 'The title こんにちはキティ')

        if sys.version_info[0] < 3:
            test_cal = test_cal.decode('utf-8')
            vevent = base.readOne(test_cal).vevent
            vevent2 = base.readOne(vevent.serialize())
            self.assertEqual(str(vevent), str(vevent2))
            self.assertEqual(vevent.summary.value, u'The title こんにちはキティ')
Ejemplo n.º 11
0
 def test_recurrence_without_tz(self):
     """
     Test recurring vevent missing any time zone definitions.
     """
     test_file = get_test_file("recurrence-without-tz.ics")
     cal = base.readOne(test_file)
     dates = list(cal.vevent.getrruleset())
     self.assertEqual(dates[0], datetime.datetime(2013, 1, 17, 0, 0))
     self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
     self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))
Ejemplo n.º 12
0
    def test_bad_line(self):
        """
        Test bad line in ics file
        """
        cal = get_test_file("badline.ics")
        self.assertRaises(ParseError, base.readOne, cal)

        newcal = base.readOne(cal, ignoreUnreadable=True)
        self.assertEqual(str(newcal.vevent.x_bad_underscore),
                         '<X-BAD-UNDERSCORE{}TRUE>')
Ejemplo n.º 13
0
 def test_recurrence_without_tz(self):
     """
     Test recurring vevent missing any time zone definitions.
     """
     test_file = get_test_file("recurrence-without-tz.ics")
     cal = base.readOne(test_file)
     dates = list(cal.vevent.getrruleset())
     self.assertEqual(dates[0], datetime.datetime(2013, 1, 17, 0, 0))
     self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
     self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))
Ejemplo n.º 14
0
 def test_recurrence_offset_naive(self):
     """
     Ensure recurring vevent missing some time zone definitions is
     parsing. See isseu #75.
     """
     test_file = get_test_file("recurrence-offset-naive.ics")
     cal = base.readOne(test_file)
     dates = list(cal.vevent.getrruleset())
     self.assertEqual(dates[0], datetime.datetime(2013, 1, 17, 0, 0))
     self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
     self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))
Ejemplo n.º 15
0
    def test_vcard_3_parsing(self):
        """
        VCARD 3.0 parse test
        """
        test_file = get_test_file("simple_3_0_test.ics")
        card = base.readOne(test_file)
        # value not rendering correctly?
        #self.assertEqual(
        #    card.adr.value,
        #    "<Address: Haight Street 512;\nEscape, Test\nNovosibirsk,  80214\nGnuland>"
        #)
        self.assertEqual(card.org.value, [
            "University of Novosibirsk",
            "Department of Octopus Parthenogenesis"
        ])

        for _ in range(3):
            new_card = base.readOne(card.serialize())
            self.assertEqual(new_card.org.value, card.org.value)
            card = new_card
Ejemplo n.º 16
0
 def test_readOne(self):
     """
     Test reading first component of ics
     """
     cal = get_test_file("silly_test.ics")
     silly = base.readOne(cal)
     self.assertEqual(
         str(silly),
         "<SILLYPROFILE| [<MORESTUFF{}this line is not folded, but in practice probably ought to be, as it is exceptionally long, and moreover demonstratively stupid>, <SILLYNAME{}name>, <STUFF{}foldedline>]>"
     )
     self.assertEqual(str(silly.stuff), "<STUFF{}foldedline>")
Ejemplo n.º 17
0
    def test_vcard_3_parsing(self):
        """
        VCARD 3.0 parse test
        """
        test_file = get_test_file("simple_3_0_test.ics")
        card = base.readOne(test_file)
        # value not rendering correctly?
        #self.assertEqual(
        #    card.adr.value,
        #    "<Address: Haight Street 512;\nEscape, Test\nNovosibirsk,  80214\nGnuland>"
        #)
        self.assertEqual(
            card.org.value,
            ["University of Novosibirsk", "Department of Octopus Parthenogenesis"]
        )

        for _ in range(3):
            new_card = base.readOne(card.serialize())
            self.assertEqual(new_card.org.value, card.org.value)
            card = new_card
Ejemplo n.º 18
0
 def test_recurrence_offset_naive(self):
     """
     Ensure recurring vevent missing some time zone definitions is
     parsing. See isseu #75.
     """
     test_file = get_test_file("recurrence-offset-naive.ics")
     cal = base.readOne(test_file)
     dates = list(cal.vevent.getrruleset())
     self.assertEqual(dates[0], datetime.datetime(2013, 1, 17, 0, 0))
     self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
     self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))
Ejemplo n.º 19
0
    def test_bad_line(self):
        """
        Test bad line in ics file
        """
        cal = get_test_file("badline.ics")
        self.assertRaises(ParseError, base.readOne, cal)

        newcal = base.readOne(cal, ignoreUnreadable=True)
        self.assertEqual(
            str(newcal.vevent.x_bad_underscore),
            '<X-BAD-UNDERSCORE{}TRUE>'
        )
Ejemplo n.º 20
0
 def test_recurrence(self):
     """
     Ensure date valued UNTILs in rrules are in a reasonable timezone,
     and include that day (12/28 in this test)
     """
     test_file = get_test_file("recurrence.ics")
     cal = base.readOne(test_file)
     dates = list(cal.vevent.getrruleset())
     self.assertEqual(dates[0],
                      datetime.datetime(2006, 1, 26, 23, 0, tzinfo=tzutc()))
     self.assertEqual(dates[1],
                      datetime.datetime(2006, 2, 23, 23, 0, tzinfo=tzutc()))
     self.assertEqual(
         dates[-1], datetime.datetime(2006, 12, 28, 23, 0, tzinfo=tzutc()))
Ejemplo n.º 21
0
 def test_readOne(self):
     """
     Test reading first component of ics
     """
     cal = get_test_file("silly_test.ics")
     silly = base.readOne(cal)
     self.assertEqual(
         str(silly),
         "<SILLYPROFILE| [<MORESTUFF{}this line is not folded, but in practice probably ought to be, as it is exceptionally long, and moreover demonstratively stupid>, <SILLYNAME{}name>, <STUFF{}foldedline>]>"
     )
     self.assertEqual(
         str(silly.stuff),
         "<STUFF{}foldedline>"
     )
Ejemplo n.º 22
0
    def test_unicode(self):
        """
        Test unicode characters
        """
        test_cal = get_test_file("utf8_test.ics")
        vevent = base.readOne(test_cal).vevent
        vevent2 = base.readOne(vevent.serialize())
        self.assertEqual(str(vevent), str(vevent2))

        self.assertEqual(
            vevent.summary.value,
            'The title こんにちはキティ'
        )

        if sys.version_info[0] < 3:
            test_cal = test_cal.decode('utf-8')
            vevent = base.readOne(test_cal).vevent
            vevent2 = base.readOne(vevent.serialize())
            self.assertEqual(str(vevent), str(vevent2))
            self.assertEqual(
                vevent.summary.value,
                u'The title こんにちはキティ'
            )
Ejemplo n.º 23
0
 def test_recurrence(self):
     """
     Ensure date valued UNTILs in rrules are in a reasonable timezone,
     and include that day (12/28 in this test)
     """
     test_file = get_test_file("recurrence.ics")
     cal = base.readOne(test_file)
     dates = list(cal.vevent.getrruleset())
     self.assertEqual(
         dates[0],
         datetime.datetime(2006, 1, 26, 23, 0, tzinfo=tzutc())
     )
     self.assertEqual(
         dates[1],
         datetime.datetime(2006, 2, 23, 23, 0, tzinfo=tzutc())
     )
     self.assertEqual(
         dates[-1],
         datetime.datetime(2006, 12, 28, 23, 0, tzinfo=tzutc())
     )
Ejemplo n.º 24
0
    def test_importing(self):
        """
        Test importing ics
        """
        cal = get_test_file("standard_test.ics")
        c = base.readOne(cal, validate=True)
        self.assertEqual(str(c.vevent.valarm.trigger),
                         "<TRIGGER{}-1 day, 0:00:00>")

        self.assertEqual(str(c.vevent.dtstart.value),
                         "2002-10-28 14:00:00-08:00")
        self.assertTrue(isinstance(c.vevent.dtstart.value, datetime.datetime))
        self.assertEqual(str(c.vevent.dtend.value),
                         "2002-10-28 15:00:00-08:00")
        self.assertTrue(isinstance(c.vevent.dtend.value, datetime.datetime))
        self.assertEqual(
            c.vevent.dtstamp.value,
            datetime.datetime(2002, 10, 28, 1, 17, 6, tzinfo=tzutc()))

        vevent = c.vevent.transformFromNative()
        self.assertEqual(str(vevent.rrule), "<RRULE{}FREQ=Weekly;COUNT=10>")