Ejemplo n.º 1
0
    def test_eq(self):
        # TODO : better equality check
        c0, c1 = Calendar(), Calendar()
        e = Event()

        c0.events.add(e)
        c1.events.add(e)

        self.assertEqual(c0, c1)
Ejemplo n.º 2
0
    def test_creator(self):

        c0 = Calendar()
        c1 = Calendar()
        c0.creator = u'42'
        with self.assertRaises(ValueError):
            c1.creator = 42

        self.assertEqual(c0.creator, u'42')
Ejemplo n.º 3
0
    def test_eventlist_move(self):
        e = Event()
        c = Calendar()
        c.events.append(e)

        d = Calendar(events=c.events)

        self.assertIs(c.events, d.events)
        self.assertSequenceEqual([e], d.events)
        self.assertIs(e, d.events[0])
Ejemplo n.º 4
0
    def test_selfload(self):
        for fix in self.fixtures:
            c = Calendar(fix)
            d = Calendar(str(c))
            self.assertEqual(c, d)
            self.assertEqual(c.events, d.events)

            e = Calendar(str(d))
            # cannot compare str(c) and str(d) because times are encoded differently
            self.assertEqual(str(d), str(e))
Ejemplo n.º 5
0
    def test_neq_len(self):
        c0, c1 = Calendar(), Calendar()
        e = Event()

        c0.events.append(e)
        c0.events.append(e)

        c1.events.append(e)

        self.assertNotEqual(c0, c1)
Ejemplo n.º 6
0
    def test_neq_len(self):
        c0, c1 = Calendar(), Calendar()
        e1 = Event()
        e2 = Event()

        c0.events.add(e1)
        c0.events.add(e2)

        c1.events.add(e1)

        self.assertNotEqual(c0, c1)
Ejemplo n.º 7
0
    def test_version(self):

        c = Calendar(cal10)
        self.assertEqual(u'2.0', c.version)
        lines = str(c).splitlines()
        self.assertEqual(lines[:3], cal10.strip().splitlines()[:3])
        self.assertEqual("VERSION:2.0", lines[1])
        self.assertIn("PRODID", lines[2])

        c = Calendar(cal14)
        self.assertEqual(u'42', c.version)
def convert(args):
    file_ics: str = args.ics
    if not file_ics.startswith("http"):
        with open(file_ics, "r") as f:
            c = Calendar(f.read())
    else:
        c = Calendar(requests.get(file_ics).text)

    collector = []
    for e in c.events:
        title = e.name
        tpe = "---"

        # check for starting hashtag
        parts = title.split(" ")
        if parts[0].startswith("#"):
            tpe = parts[0][1:]
            title = " ".join(parts[1:])

        # // const
        # toreturn = {
        #            // title,
        # // "location": "",
        # // id: '' + id,
        # // calendarId: title.startsWith("Poster") ? '1': '2', // + (id % 2 + 1),
        # // category: 'time',
        # // dueDateClass: ''
        #                  //
        #                  //};

        link = e.location
        if args.strip_url_domain:
            link = re.sub(r"https?://(.*?)/", "./", link)

        json_event = {
            "title": title,
            "start": e.begin.for_json(),
            "end": e.end.for_json(),
            "location": link,
            "link": link,
            "category": "time",
            "calendarId": tpe,
        }
        collector.append(json_event)
        print(json_event)

    with (open(args.out, "w")) as f:
        json.dump(collector, f)

    # print(c.events)

    pass
Ejemplo n.º 9
0
    def test_eq(self):
        c0, c1 = Calendar(), Calendar()
        e = Event()

        c0.events.append(e)
        c1.events.append(e)

        self.assertEqual(c0, c1)

        t = Todo()

        c0.todos.append(t)
        c1.todos.append(t)
Ejemplo n.º 10
0
def convert(args):
    file_ics: str = args.ics
    if not file_ics.startswith("http"):
        with open(file_ics, "r") as f:
            c = Calendar(f.read())
    else:
        c = Calendar(requests.get(file_ics).text)

    collector = []
    for e in c.events:
        title = e.name
        tpe = "---"

        # check for starting hashtag
        parts = title.split(" ")
        if parts[0].startswith("#"):
            tpe = parts[0][1:]
            title = " ".join(parts[1:])

        # // const
        # toreturn = {
        #            // title,
        # // "location": "",
        # // id: '' + id,
        # // calendarId: title.startsWith("Poster") ? '1': '2', // + (id % 2 + 1),
        # // category: 'time',
        # // dueDateClass: ''
        #                  //
        #                  //};

        json_event = OrderedDict([
            ("title", title),
            ("start", e.begin.for_json()),
            ("end", e.end.for_json()),
            ("location", e.location),
            ("link", e.location),
            ("category", "time"),
            ("calendarId", tpe),
        ])
        collector.append(json_event)
        pprint.pprint(json_event)

    with (open(args.out, "w")) as f:
        json.dump(collector, f, indent=2, separators=(',', ': '))

    # print(c.events)

    pass
Ejemplo n.º 11
0
    def test_todos_setter(self):

        c = Calendar(cal1)
        t = Todo()
        c.todos = [t]

        self.assertEqual(c.todos, [t])
Ejemplo n.º 12
0
 def test_attendee_parse(self):
     with open(
             os.path.join(os.path.dirname(__file__),
                          "fixtures/groupscheduled.ics")) as f:
         c = Calendar(f.read())
         e = list(c.events)[0]
         assert len(e.attendees) == 1
Ejemplo n.º 13
0
    def test_events_setter(self):

        c = Calendar(cal1)
        e = Event()
        c.events = [e]

        self.assertEqual(c.events, [e])
Ejemplo n.º 14
0
 def test_alarm_without_repeat_extraction(self):
     c = Calendar(cal21)
     a = c.events[0].alarms[0]
     self.assertEqual(a.trigger, timedelta(hours=1))
     self.assertIsNone(a.repeat)
     self.assertIsNone(a.duration)
     self.assertEqual(a.description, 'Event reminder')
Ejemplo n.º 15
0
 def test_alarm_with_repeat_extraction(self):
     c = Calendar(cal22)
     a = c.events[0].alarms[0]
     self.assertEqual(a.trigger, timedelta(hours=1))
     self.assertEqual(a.repeat, 2)
     self.assertEqual(a.duration, timedelta(minutes=10))
     self.assertEqual(a.description, 'Event reminder')
Ejemplo n.º 16
0
 def test_empty_list_to_eventlist(self):
     c = Calendar()
     l = []
     c.events = l
     self.assertIsNot(c.events, l)
     self.assertIsInstance(c.events, EventList)
     self.assertSequenceEqual(sorted(c.events), sorted(l))
Ejemplo n.º 17
0
 def test_list_to_eventlist(self):
     c = Calendar()
     l = [Event(), Event(), Event(name='plop')]
     c.events = l
     self.assertIsNot(c.events, l)
     self.assertIsInstance(c.events, EventList)
     self.assertSequenceEqual(sorted(c.events), sorted(l))
Ejemplo n.º 18
0
 def test_unescape_summary(self):
     c = Calendar(cal15)
     e = c.events[0]
     self.assertEqual(
         e.name,
         "Hello, \n World; This is a backslash : \\ and another new \n line"
     )
Ejemplo n.º 19
0
    def test_output(self):
        c = Calendar(cal27)
        t = next(iter(c.todos))

        test_str = CRLF.join(("BEGIN:VTODO",
                              "SEQUENCE:0",
                              "DTSTAMP:20180218T154700Z",
                              "UID:Uid",
                              "COMPLETED:20180418T150000Z",
                              "CREATED:20180218T154800Z",
                              "DESCRIPTION:Lorem ipsum dolor sit amet.",
                              "DTSTART:20180218T164800Z",
                              "LOCATION:Earth",
                              "PERCENT-COMPLETE:0",
                              "PRIORITY:0",
                              "SUMMARY:Name",
                              "URL:https://www.example.com/cal.php/todo.ics",
                              "DURATION:PT10M",
                              "BEGIN:VALARM",
                              "TRIGGER:-PT1H",
                              "ACTION:DISPLAY",
                              "DESCRIPTION:Event reminder",
                              "END:VALARM",
                              "END:VTODO"))
        self.assertEqual(str(t), test_str)
Ejemplo n.º 20
0
 def test_iter(self):
     for fix in self.fixtures:
         c = Calendar(imports=fix)
         s = str(c)
         self.assertIsInstance(c, Iterable)
         i_with_no_lr = map(lambda x: x.rstrip('\n'), c)
         self.assertSequenceEqual(s.split('\n'), list(i_with_no_lr))
Ejemplo n.º 21
0
 def test_alarm_with_repeat_extraction(self):
     c = Calendar(cal22)
     a = next(iter(c.events)).alarms[0]
     self.assertEqual(a.trigger, timedelta(hours=1))
     self.assertEqual(a.repeat, 2)
     self.assertEqual(a.duration, timedelta(minutes=10))
     self.assertEqual(a.display_text, "Event reminder")
Ejemplo n.º 22
0
    def test_selfload(self):
        def filter(attr, value):
            return not attr.name.startswith(
                "_classmethod") and not attr.name == "_timezones"

        for fix in self.fixtures:
            c = Calendar(fix)
            d = Calendar(str(c))
            self.assertEqual(attr.asdict(c, filter=filter),
                             attr.asdict(d, filter=filter))
            self.assertEqual(c, d)
            self.assertEqual(c.events, d.events)
            self.assertEqual(c.todos, d.todos)

            e = Calendar(str(d))
            # cannot compare str(c) and str(d) because times are encoded differently
            self.assertEqual(str(d), str(e))
Ejemplo n.º 23
0
    def test_clone(self):
        c0 = Calendar()
        e = Event()
        c0.events.add(e)
        c1 = c0.clone()

        self.assertEqual(c0.events, c1.events)
        self.assertEqual(c0, c1)
Ejemplo n.º 24
0
 def test_init(self):
     c = Calendar(creator='tests')
     self.assertEqual(c.creator, 'tests')
     self.assertSequenceEqual(c.events, [])
     self.assertEqual(c.method, None)
     self.assertEqual(c.scale, None)
     self.assertEqual(c._unused, Container(name='VCALENDAR'))
     self.assertEqual(c._timezones, {})
Ejemplo n.º 25
0
    def test_on(self):

        l = EventList()

        c = Calendar(cal1)
        l.append(c.events[0])
        day = "2013-10-29"
        self.assertIn(c.events[0], l.on(day))
Ejemplo n.º 26
0
 def test_unescape_texts(self):
     c = Calendar(cal31)
     t = c.todos[0]
     self.assertEqual(
         t.name,
         "Hello, \n World; This is a backslash : \\ and another new \n line"
     )
     self.assertEqual(t.location, "In, every text field")
     self.assertEqual(t.description, "Yes, all of them;")
Ejemplo n.º 27
0
 def test_imports(self):
     c = Calendar(cal1)
     self.assertEqual(c.creator, '-//Apple Inc.//Mac OS X 10.9//EN')
     self.assertEqual(c.method, 'PUBLISH')
     e = c.events[0]
     self.assertFalse(e.all_day)
     self.assertEqual(arrow.get(2013, 10, 29, 9, 30), e.begin)
     self.assertEqual(arrow.get(2013, 10, 29, 10, 30), e.end)
     self.assertEqual(1, len(c.events))
Ejemplo n.º 28
0
    def test_alarm_without_repeat_datetime_trigger_extraction(self):
        c = Calendar(cal23)
        a = c.events[0].alarms[0]

        alarm_time = arrow.get('2016-01-01')
        self.assertEqual(a.trigger, arrow.get(alarm_time))
        self.assertIsNone(a.repeat)
        self.assertIsNone(a.duration)
        self.assertEqual(a.description, 'Event reminder')
Ejemplo n.º 29
0
 def test_alarm_without_repeat_extraction(self):
     c = Calendar(cal21)
     e = next(iter(c.events))
     assert isinstance(e.alarms, list)
     a = e.alarms[0]
     self.assertEqual(a.trigger, timedelta(hours=1))
     self.assertIsNone(a.repeat)
     self.assertIsNone(a.duration)
     self.assertEqual(a.display_text, "Event reminder")
Ejemplo n.º 30
0
    def test_alarm_without_repeat_datetime_trigger_extraction(self):
        c = Calendar(cal23)
        a = next(iter(c.events)).alarms[0]

        alarm_time = datetime(year=2016, month=1, day=1, hour=0, minute=0, second=0, tzinfo=tzutc)
        self.assertEqual(a.trigger, alarm_time)
        self.assertIsNone(a.repeat)
        self.assertIsNone(a.duration)
        self.assertEqual(a.display_text, "Event reminder")