==================
DateRecurringIndex
==================

-------------
Overall tests
-------------

iCalendar Recurrence Mode
=========================

Initialize the catalog with DateRecurringIndex

    >>> from Products.DateRecurringIndex.index import DateRecurringIndex
    >>> from Products.DateRecurringIndex.tests import DummyExtras
    >>> dri = DateRecurringIndex('start',
    ...     extra=DummyExtras(recurrence_type='ical', recurdef='recurdef', 
    ...                       until='until'))


Index must have be the same name as dri's id
    >>> from Products.ZCatalog.Catalog import Catalog
    >>> self.app.catalog = Catalog()
    >>> self.app.catalog.addIndex('start', dri)
    >>> self.app.catalog.addColumn('id')

Let's define some dummy events and catalog them.

    >>> from datetime import datetime
    >>> import pytz
    >>> cet = pytz.timezone('CET')

    >>> from Products.DateRecurringIndex.tests import DummyEvent


Index the same event more than once and test if index size changes.
    >>> test_event = DummyEvent(id='test_event',
    ...     start=datetime(2001,01,01),
    ...     recurdef='RRULE:FREQ=DAILY;INTERVAL=1;COUNT=5')
    >>> self.app.catalog.catalogObject(test_event, 'test_event')
    1
    >>> dri.indexSize()
    5

    >>> test_event = DummyEvent(id='test_event',
    ...     start=datetime(2001,01,01),
    ...     recurdef='RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3')
    >>> self.app.catalog.catalogObject(test_event, 'test_event')
    1
    >>> dri.indexSize()
    3

    >>> test_event = DummyEvent(id='test_event',
    ...     start=datetime(2001,01,01),
    ...     recurdef='RRULE:FREQ=DAILY;INTERVAL=1;COUNT=8')
    >>> self.app.catalog.catalogObject(test_event, 'test_event')
    1
    >>> dri.indexSize()
    8

    >>> self.app.catalog.uncatalogObject('test_event')
    >>> dri.indexSize()
    0


Index for querying later on...
    >>> nonr = DummyEvent(id='nonr', start=datetime(2010,10,10,0,0,tzinfo=cet))
    >>> days = DummyEvent(id='days', start=datetime(2010,10,10,0,0,tzinfo=cet),
    ...     recurdef='RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5')
    >>> mins = DummyEvent(id='mins', start=datetime(2010,10,10,0,0,tzinfo=cet),
    ...     recurdef='RRULE:FREQ=MINUTELY;INTERVAL=10;COUNT=5')
    >>> dstc = DummyEvent(id='dstc', start=datetime(2010,10,20,0,0,tzinfo=cet),
    ...     recurdef='RRULE:FREQ=HOURLY;INTERVAL=1;COUNT=7')


    >>> self.app.catalog.catalogObject(nonr, 'nonr')
    1
    >>> self.app.catalog.catalogObject(days, 'days')
    1
    >>> self.app.catalog.catalogObject(mins, 'mins')
    1
    >>> self.app.catalog.catalogObject(dstc, 'dstc')
    1


These are the dates indexed:
    >>> from plone.event.recurrence import recurrence_sequence_ical

    >>> list(recurrence_sequence_ical(start=nonr.start))
    [datetime.datetime(2010, 10, 10, 0, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)]

    >>> list(recurrence_sequence_ical(start=days.start, recrule=days.recurdef))
    [datetime.datetime(2010, 10, 10, 0, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 0, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 30, 0, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 11, 9, 0, 0, tzinfo=<DstTzInfo 'CET' CET+1:00:00 STD>),
        datetime.datetime(2010, 11, 19, 0, 0, tzinfo=<DstTzInfo 'CET' CET+1:00:00 STD>)]

    >>> list(recurrence_sequence_ical(start=mins.start, recrule=mins.recurdef))
    [datetime.datetime(2010, 10, 10, 0, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 10, 0, 10, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 10, 0, 20, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 10, 0, 30, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 10, 0, 40, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)]

    >>> list(recurrence_sequence_ical(start=dstc.start, recrule=dstc.recurdef))
    [datetime.datetime(2010, 10, 20, 0, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 1, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 2, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 3, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 4, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 5, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
        datetime.datetime(2010, 10, 20, 6, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)]

Query min one specific date
---------------------------

    >>> cat = self.app.catalog
    >>> query = {
    ...     'recur_ical': {
    ...         'query': datetime(2010,10,10,0,0,tzinfo=cet),
    ...         'range': 'min',
    ...     },
    ... }
    >>> res = cat(**query)
    >>> sorted([it.id for it in res])
    ['days', 'dstc', 'mins', 'nonr']


Query max one specific date
---------------------------

    >>> cat = self.app.catalog
    >>> query = {
    ...     'start': {
    ...         'query': datetime(2010,10,10,0,0,tzinfo=cet),
    ...         'range': 'max',
    ...     },
    ... }
    >>> res = cat(**query)

    >>> sorted([it.id for it in res])
    ['days', 'mins', 'nonr']


Query timerange over days and dstc set
--------------------------------------

    >>> query = {
    ...     'start': {
    ...         'query': [datetime(2010,10,11,0,0,tzinfo=cet),
    ...                   datetime(2010,11,20,0,0,tzinfo=cet)],
    ...         'range': 'min:max',
    ...     },
    ... }
    >>> res = cat(**query)
    >>> sorted([brain.id for brain in res])
    ['days', 'dstc']


Query timerange over mins set
-----------------------------

    >>> query = {
    ...     'start': {
    ...         'query': [datetime(2010,10,10,0,10,tzinfo=cet),
    ...                   datetime(2010,10,10,0,40,tzinfo=cet)],
    ...         'range': 'min:max',
    ...     },
    ... }
    >>> res = cat(**query)
    >>> sorted([brain.id for brain in res])
    ['mins']
