예제 #1
0
 def test_repeat_event_list_no_repeat(self):
     event = Event(
         id='TEST EVENT',
         title='REPEATING EVENT',
         date=datetime.date(2017, 1, 4),
         time=datetime.time(10, 0, 0, tzinfo=pytz.UTC),
     )
     repeats = event.repeat_between(
         datetime.datetime(2017, 1, 4, 10, 0, 0, tzinfo=pytz.UTC),
         datetime.datetime(2017, 1, 8, 10, 0, 0, tzinfo=pytz.UTC))
     self.assertEqual([], repeats)
예제 #2
0
 def test_format_event_real_html(self):
     component = Component()
     component.add('summary', 'Встреча ML-клуба')
     component.add('location',
                   'ул. Таубе, 5, Омск, Омская обл., Россия, 644037')
     component.add(
         'description',
         '10 февраля в 11:00 пройдет 5-я встреча&nbsp;<a href="https://vk.com/mlomsk">ML клуба</a>&nbsp;в офисе&nbsp;<a href="https://vk.com/7bits">7bits</a>, Таубе 5. Регистрация на встречу:&nbsp;<a href="https://vk.com/away.php?to=http%3A%2F%2Fmlomsk.1der.link%2Fmeetup%2Fsignup&amp;post=-141957789_74&amp;cc_key=" target="_blank">mlomsk.1der.link/meetup/signup</a>.<br><br>В этот раз у нас будет 2 доклада:'
     )
     timezone = pytz.timezone('Asia/Omsk')
     component.add(
         'dtstart', datetime.datetime(2018,
                                      2,
                                      10,
                                      11,
                                      0,
                                      0,
                                      tzinfo=timezone))
     event = Event.from_vevent(component, timezone)
     user_config = UserConfig.new(Config('calbot.cfg.sample'), 'TEST')
     user_config.language = 'ru_RU.UTF-8'
     result = format_event(user_config, event)
     self.assertEqual(
         'Встреча ML-клуба\nСуббота, 10 февраля 2018, 11:00 Asia/Omsk\nул. Таубе, 5, Омск, Омская обл., Россия, 644037\n10 февраля в 11:00 пройдет 5-я встреча ML клуба (https://vk.com/mlomsk) в офисе 7bits (https://vk.com/7bits), Таубе 5. Регистрация на встречу: mlomsk.1der.link/meetup/signup.\n\nВ этот раз у нас будет 2 доклада:',
         result)
예제 #3
0
 def test_repeat_fullday_event_list(self):
     event = Event(
         id='TEST EVENT',
         title='REPEATING EVENT',
         date=datetime.date(2017, 1, 4),
         repeat_rule='FREQ=DAILY',
     )
     repeats = event.repeat_between(
         datetime.datetime(2017, 1, 4, 9, 0, 0, tzinfo=pytz.UTC),
         datetime.datetime(2017, 1, 6, 10, 0, 0, tzinfo=pytz.UTC))
     self.assertEqual(2, len(repeats))
     repeat = repeats[0]
     self.assertEqual('TEST EVENT_2017-01-05T00:00:00', repeat.id)
     self.assertEqual(datetime.date(2017, 1, 5), repeat.date)
     repeat = repeats[1]
     self.assertEqual('TEST EVENT_2017-01-06T00:00:00', repeat.id)
     self.assertEqual(datetime.date(2017, 1, 6), repeat.date)
예제 #4
0
 def test_format_date_only_event(self):
     timezone = pytz.UTC
     component = _get_component()
     component.add('dtstart', datetime.date(2016, 6, 23))
     event = Event.from_vevent(component, timezone, datetime.time(10, 0))
     user_config = UserConfig.new(Config('calbot.cfg.sample'), 'TEST')
     result = format_event(user_config, event)
     self.assertEqual(
         'summary\nThursday, 23 June 2016\nlocation\ndescription', result)
예제 #5
0
 def test_format_event_blanks(self):
     component = Component()
     component.add('dtstart',
                   datetime.datetime(2018, 2, 3, 13, 3, 4, tzinfo=pytz.UTC))
     event = Event.from_vevent(component, pytz.UTC)
     user_config = UserConfig.new(Config('calbot.cfg.sample'), 'TEST')
     user_config.language = 'ru_RU.UTF-8'
     result = format_event(user_config, event)
     self.assertEqual(
         'None\nСуббота, 03 февраля 2018, 13:03 UTC\nNone\nNone', result)
예제 #6
0
 def test_date_only_event(self):
     timezone = pytz.UTC
     component = _get_component()
     component.add('dtstart', datetime.date.today())
     event = Event.from_vevent(component, timezone, datetime.time(10, 0))
     self.assertTrue(isinstance(event.date, datetime.date))
     self.assertIsNone(event.time)
     self.assertEqual(10, event.notify_datetime.hour)
     self.assertEqual(0, event.notify_datetime.minute)
     self.assertEqual(pytz.UTC, event.notify_datetime.tzinfo)
예제 #7
0
 def test_format_event(self):
     component = _get_component()
     component.add(
         'dtstart',
         datetime.datetime(2016, 6, 23, 19, 50, 35, tzinfo=pytz.UTC))
     event = Event.from_vevent(component, pytz.UTC)
     user_config = UserConfig.new(Config('calbot.cfg.sample'), 'TEST')
     result = format_event(user_config, event)
     self.assertEqual(
         'summary\nThursday, 23 June 2016, 19:50 UTC\nlocation\ndescription',
         result)
예제 #8
0
    def test_filter_notified_events(self):
        timezone = pytz.UTC
        component_now = _get_component()
        component_now.add(
            'dtstart',
            datetime.datetime.now(tz=timezone) + datetime.timedelta(minutes=5))
        component_future24 = _get_component()
        component_future24.add(
            'dtstart',
            datetime.datetime.now(tz=timezone) +
            datetime.timedelta(hours=24, minutes=-5))
        component_future48 = _get_component()
        component_future48.add(
            'dtstart',
            datetime.datetime.now(tz=timezone) +
            datetime.timedelta(hours=48, minutes=-5))

        class TestCalendarConfig:
            def __init__(self):
                self.advance = [24, 48]

            def event(self, id):
                return TestEventConfig()

        class TestEventConfig:
            def __init__(self):
                self.id = 1
                self.last_notified = 48

        events = [
            Event.from_vevent(component_now, timezone),
            Event.from_vevent(component_future24, timezone),
            Event.from_vevent(component_future48, timezone)
        ]
        config = TestCalendarConfig()
        result = list(filter_notified_events(events, config))
        self.assertEqual(2, len(result))
        self.assertEqual(component_now.decoded('dtstart'),
                         result[0].notify_datetime)
        self.assertEqual(component_future24.decoded('dtstart'),
                         result[1].notify_datetime)
예제 #9
0
 def test_format_event_ru(self):
     component = _get_component()
     component.add(
         'dtstart',
         datetime.datetime(2016, 6, 23, 19, 50, 35, tzinfo=pytz.UTC))
     event = Event.from_vevent(component, pytz.UTC)
     user_config = UserConfig.new(Config('calbot.cfg.sample'), 'TEST')
     user_config.language = 'ru_RU.UTF-8'
     result = format_event(user_config, event)
     self.assertEqual(
         'summary\nЧетверг, 23 июня 2016, 19:50 UTC\nlocation\ndescription',
         result)
예제 #10
0
    def test_filter_future_events(self):
        timezone = pytz.UTC
        now = datetime.datetime.now(tz=timezone)

        component_past = _get_component()
        component_past.add('dtstart', now - datetime.timedelta(hours=1))
        component_now = _get_component()
        component_now.add('dtstart', now + datetime.timedelta(minutes=10))
        component_future = _get_component()
        component_future.add('dtstart', now + datetime.timedelta(hours=2))
        events = [
            Event.from_vevent(component_past, timezone),
            Event.from_vevent(component_now, timezone),
            Event.from_vevent(component_future, timezone)
        ]

        result = list(
            filter_future_events(events, now,
                                 now + datetime.timedelta(hours=1)))

        self.assertEqual(1, len(result))
        self.assertEqual(component_now.decoded('dtstart'),
                         result[0].notify_datetime)
예제 #11
0
 def test_sort_events(self):
     timezone = pytz.UTC
     component_past = _get_component()
     component_past.add(
         'dtstart',
         datetime.datetime.now(tz=timezone) - datetime.timedelta(hours=1))
     component_now = _get_component()
     component_now.add(
         'dtstart',
         datetime.datetime.now(tz=timezone) +
         datetime.timedelta(minutes=10))
     component_future = _get_component()
     component_future.add(
         'dtstart',
         datetime.datetime.now(tz=timezone) + datetime.timedelta(hours=2))
     events = [
         Event.from_vevent(component_future, timezone),
         Event.from_vevent(component_now, timezone),
         Event.from_vevent(component_past, timezone)
     ]
     result = list(sort_events(events))
     self.assertEqual(events[2], result[0])
     self.assertEqual(events[1], result[1])
     self.assertEqual(events[0], result[2])
예제 #12
0
 def test_format_event_html(self):
     component = Component()
     component.add('summary', '<b>summary</b>')
     component.add('location', '<i>location</i>')
     component.add(
         'description',
         '<b>description</b><br><br>&nbsp;<a href="link.html">link</a>')
     component.add('dtstart',
                   datetime.datetime(2018, 2, 3, 13, 3, 4, tzinfo=pytz.UTC))
     event = Event.from_vevent(component, pytz.UTC)
     user_config = UserConfig.new(Config('calbot.cfg.sample'), 'TEST')
     user_config.language = 'ru_RU.UTF-8'
     result = format_event(user_config, event)
     self.assertEqual(
         'summary\nСуббота, 03 февраля 2018, 13:03 UTC\nlocation\ndescription\n\n link (link.html)',
         result)