Example #1
0
def test_calendar__Calendar__get_events_for_month__3(sample_events):
    """It respects the given time zone for a western time zone."""
    assert ([u'end Jan 2013', u'start Feb 2013'] == [
        x.alternative_title
        for x in sample_events.calendar.get_events_for_month(
            Month(2, 2013), 'Etc/GMT-1')
    ])
Example #2
0
def Date(date):
    """Adapter between Date and Month.

    >>> from datetime import date
    >>> from zope.interface.verify import verifyObject
    >>> from gocept.month import IMonth

    >>> today = date.today()
    >>> verifyObject(IMonth, Date(today))
    True
    >>> Date(today).month == today.month
    True
    >>> Date(today).year == today.year
    True
    >>> Date(date(2005,12,6))
    Month 12/2005
    >>> str(Date(date(2005,12,6)))
    '12/2005'
    >>> str(Date(date(2005,12,6)) + 1)
    '01/2006'
    >>> Date(today) > Month(today.month, today.year-1)
    True
    >>> Date(today) == Month(today.month, today.year)
    True
    """
    return Month(date.month, date.year)
Example #3
0
def test_calendar__Calendar__get_events_for_month__8(address_book,
                                                     EventFactory, DateTime):
    """A whole day event does not change the month via timezone."""
    EventFactory(address_book,
                 alternative_title=u'whole day',
                 datetime=DateTime(2015, 4, 30, 23),
                 whole_day_event=True)
    EventFactory(address_book,
                 alternative_title=u'day',
                 datetime=DateTime(2015, 4, 30, 23))
    assert ([u'whole day', u'day'] == [
        x.alternative_title
        for x in address_book.calendar.get_events_for_month(
            Month(4, 2015), 'Etc/GMT+8')
    ])
    assert ([u'whole day'] == [
        x.alternative_title
        for x in address_book.calendar.get_events_for_month(
            Month(4, 2015), 'Etc/GMT-7')
    ])
Example #4
0
def test_calendar__Calendar__get_events_for_month__7(sample_events,
                                                     address_book,
                                                     EventFactory, DateTime):
    """It does not return deleted events."""
    event = EventFactory(address_book,
                         alternative_title=u'deleted start of March 2013',
                         datetime=DateTime(2013, 3, 1, 5))
    event.deleted = True
    assert ([u'start Mar 2013'] == [
        x.alternative_title
        for x in address_book.calendar.get_events_for_month(
            Month(3, 2013), 'Etc/GMT')
    ])
Example #5
0
def test_calendar__Calendar__get_events_for_month__9(address_book,
                                                     EventFactory,
                                                     CategoryFactory,
                                                     DateTime):
    """Deleted events are depressed in favour of not deleted ones.

    This behaviour requires the events to have the same category and the same
    time. It is needed to be able to delete a recurring event and add a new one
    later at the same place for the same category.
    """
    category = CategoryFactory(address_book, u'my cat')
    date = DateTime(2017, 5, 14, 13, 50, tzinfo=pytz.timezone('Europe/Berlin'))
    e1 = EventFactory(address_book, category=category, datetime=date)
    e1.deleted = True
    EventFactory(address_book, category=category, datetime=date)
    assert ([False] == [
        x.deleted for x in address_book.calendar.get_events_for_month(
            Month(5, 2017), 'Europe/Berlin')
    ])
Example #6
0
def test_calendar__Calendar__get_events_for_month__5(address_book,
                                                     CategoryFactory,
                                                     RecurringEventFactory,
                                                     EventFactory, DateTime):
    """A customized recurred event hides the original recurred event."""
    recurring_event = RecurringEventFactory(
        address_book,
        alternative_title=u'each week',
        datetime=DateTime(2013, 3, 14, 23, 0),
        period=u'weekly',
        category=CategoryFactory(address_book, u'night lunch'))
    event_data = get_event_data_from_recurring_event(
        recurring_event, DateTime(2013, 3, 21, 23, 0))
    event_data['alternative_title'] = u'this week'
    EventFactory(address_book, **event_data)
    assert ([(u'each week', '2013-03-14'), (u'this week', '2013-03-21'),
             (u'each week', '2013-03-28')
             ] == [(x.alternative_title, x.datetime.date().isoformat())
                   for x in address_book.calendar.get_events_for_month(
                       Month(3, 2013), 'Etc/GMT+1')])
Example #7
0
def test_calendar__Calendar__get_events_for_month__6(address_book,
                                                     CategoryFactory,
                                                     RecurringEventFactory,
                                                     DateTime):
    """The recurring event with the higher prio in the category is rendered."""
    category = CategoryFactory(address_book, u'night lunch')
    RecurringEventFactory(address_book,
                          alternative_title=u'monthly lunch',
                          datetime=DateTime(2013, 3, 10, 12),
                          period=u'nth weekday of month',
                          category=category)
    RecurringEventFactory(address_book,
                          alternative_title=u'weekly lunch',
                          datetime=DateTime(2013, 3, 3, 12),
                          period=u'weekly',
                          category=category)
    assert ([(u'weekly lunch', '2013-03-03'), (u'monthly lunch', '2013-03-10'),
             (u'weekly lunch', '2013-03-17'), (u'weekly lunch', '2013-03-24'),
             (u'weekly lunch', '2013-03-31')
             ] == [(x.alternative_title, x.datetime.date().isoformat())
                   for x in address_book.calendar.get_events_for_month(
                       Month(3, 2013), 'Etc/GMT+1')])
Example #8
0
def test_calendar__Calendar__get_events_for_month__4(sample_events,
                                                     address_book,
                                                     RecurringEventFactory,
                                                     CategoryFactory,
                                                     DateTime):
    """It returns the recurring events in the given month."""
    RecurringEventFactory(address_book,
                          alternative_title=u'each week',
                          datetime=DateTime(2013, 2, 14, 23, 0),
                          period=u'weekly',
                          category=CategoryFactory(address_book,
                                                   u'night lunch'))
    RecurringEventFactory(address_book,
                          alternative_title=u'each week in future',
                          datetime=DateTime(2013, 3, 1, 0),
                          period=u'weekly',
                          category=CategoryFactory(address_book, u'midnight'))
    assert ([(u'end Jan 2013', '2013-01-31T23:59:00+00:00'),
             (u'start Feb 2013', '2013-02-01T00:00:00+00:00'),
             (u'each week', '2013-02-15T00:00:00+01:00'),
             (u'each week', '2013-02-22T00:00:00+01:00')
             ] == [(x.alternative_title, x.datetime.isoformat())
                   for x in address_book.calendar.get_events_for_month(
                       Month(2, 2013), 'Etc/GMT-1')])
Example #9
0
 def _toFieldValue(self, input):
     try:
         return Month.fromString(input)
     except ValueError as error:
         raise MonthConversionError(error)
Example #10
0
 def fromUnicode(self, str):
     return Month.fromString(str)
Example #11
0
def test_calendar__Calendar__get_events_for_month__1(sample_events):
    """It returns only events in the given month."""
    assert ([u'start Feb 2013', u'end Feb 2013'] == [
        x.alternative_title
        for x in sample_events.calendar.get_events_for_month(Month(2, 2013))
    ])
Example #12
0
def test_monthly__recurrences_of_weekday_in_month__6(DateTime):
    """There are 5 recurrences of Sunday in 6/2014."""
    assert (5 == recurrences_of_weekday_in_month(
        DateTime(2014, 8, 17), Month(6, 2014)))
Example #13
0
def test_monthly__recurrences_of_weekday_in_month__5(DateTime):
    """There are 5 recurrences of Thursday in 7/2014."""
    assert (5 == recurrences_of_weekday_in_month(
        DateTime(2014, 8, 21), Month(7, 2014)))
Example #14
0
def test_monthly__recurrences_of_weekday_in_month__3(DateTime):
    """There are 4 recurrences of Sunday in 7/2014."""
    assert (4 == recurrences_of_weekday_in_month(
        DateTime(2014, 8, 17), Month(7, 2014)))
Example #15
0
def test_monthly__recurrences_of_weekday_in_month__2(DateTime):
    """There are 4 recurrences of Thursday in 6/2014."""
    assert (4 == recurrences_of_weekday_in_month(
        DateTime(2014, 8, 21), Month(6, 2014)))
Example #16
0
def BuiltinStr(date):
    return Month.fromString(date)