'Test automatic determination of interval start and end'

def testAutomaticInterval(self):

    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    is_now = self.is_now
    s3db = current.s3db
    query = (FS('event_type') == 'STARTEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2011, 1, 3, 0, 0, 0))
    assertTrue(is_now(ef.end))
    query = (FS('event_type') == 'NOSTART')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2012, 2, 12, 0, 0, 0))
    assertTrue(is_now(ef.end))
    query = (FS('event_type') == 'NOEND')
    resource = s3db.resource('tp_test_events', filter=query)
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2012, 7, 21, 0, 0, 0))
    assertTrue(is_now(ef.end))
    resource = s3db.resource('tp_test_events')
    ts = S3TimeSeries(resource, event_start='event_start', event_end='event_end')
    ef = ts.event_frame
    assertEqual(ef.start, tp_datetime(2011, 1, 3, 0, 0, 0))
    assertTrue(is_now(ef.end))
