Esempio n. 1
0
    def test_cursor_eq(self):
        event_id_1 = uuid.uuid4()
        event_occurred_1 = datetime.datetime.utcnow()

        cursor_1 = ByTimeRangeCursor(event_occurred_1, event_id_1)
        cursor_2 = ByTimeRangeCursor(event_occurred_1, event_id_1)
        cursor_3 = ByTimeRangeCursor(event_occurred_1, uuid.uuid4())
        cursor_4 = ByTimeRangeCursor(datetime.datetime.utcnow(), event_id_1)

        self.assertTrue(cursor_1 == cursor_2)
        self.assertFalse(cursor_3 == cursor_4)
        self.assertFalse(cursor_3 == cursor_2)
        self.assertFalse(cursor_4 == cursor_1)
Esempio n. 2
0
    def test_get_events_by_timerange_cursor(self):
        event_dicts, events = self._add_events()

        es = store.get_events_by_timerange()

        self.assertEqual(es.count, len(events))

        from_store = list(es)

        cursor = ByTimeRangeCursor(
            from_store[2].occurred,
            from_store[2].id
        )

        omitted = [e.id for e in from_store[:2]]

        es = store.get_events_by_timerange()

        count = 0

        for p in list(es.pages(cursor=cursor)):
            count += p.count

            for e in p:
                self.assertTrue(
                    (e.occurred, e.id) < (cursor.occurred, cursor.id)
                )
                self.assertTrue(e.id not in omitted)

        self.assertEqual(es.count - 3, count)
Esempio n. 3
0
    def test_get_all_with_feeds_and_next(self):
        feeds = ['foo', 'bar']

        self._page.next = ByTimeRangeCursor(
            datetime.datetime.utcnow(),
            str(uuid.uuid4())
        )

        expected_next = (
            "/events?" +
            "limit=10&embed_related=full&cursor=%s&feeds=%s" % (
                eventlog.service.core.cursor.serialize(self._page.next),
                ','.join(feeds)
            )
        )

        rv = self.app.get('/events?feeds=foo,bar')

        self.verify_response(rv, pagination={"next": expected_next})

        store.get_events_by_timerange.assert_called_with(
            after=None,
            before=None,
            feeds=feeds,
            pagesize=10,
            embed_related=True,
            timezone=None
        )
Esempio n. 4
0
    def test_get_all_with_cursor(self):

        datestr = '2014-01-01 12:01:01.00'
        dt = datetime.datetime.strptime(datestr, DATETIME_FMT)

        cursor = ByTimeRangeCursor(dt, str(uuid.uuid4()))

        rv = self.app.get(
            '/events?cursor=%s' % (
                eventlog.service.core.cursor.serialize(cursor)
            )
        )

        self.verify_response(rv, pagination={})

        store.get_events_by_timerange.assert_called_with(
            after=None,
            before=None,
            feeds=self._all_feeds_names,
            pagesize=10,
            embed_related=True,
            timezone=None
        )

        self._event_set.page.assert_called_with(cursor=cursor)
Esempio n. 5
0
    def test_get_all_with_on_and_after(self):
        self._page.next = ByTimeRangeCursor(
            datetime.datetime.utcnow(),
            str(uuid.uuid4())
        )

        datestr = '2014-01-01 12:01:01.000000'

        dt = datetime.datetime.strptime(datestr, DATETIME_FMT)

        expected_next = (
            "/events?limit=10&embed_related=full&cursor=%s&after=%s" % (
                eventlog.service.core.cursor.serialize(self._page.next),
                datestr
            )
        )

        rv = self.app.get('/events?after=' + datestr)

        self.verify_response(
            rv,
            pagination={"next": expected_next}
        )

        store.get_events_by_timerange.assert_called_with(
            before=None,
            after=dt,
            embed_related=True,
            feeds=self._all_feeds_names,
            pagesize=10,
            timezone=None
        )

        self._event_set.page.assert_called_with(cursor=None)
Esempio n. 6
0
    def test_get_all_with_next(self):
        self._page.next = ByTimeRangeCursor(
            datetime.datetime.utcnow(),
            str(uuid.uuid4())
        )

        expected_next = (
            "/events?limit=10&embed_related=full&cursor=%s" % (
                eventlog.service.core.cursor.serialize(self._page.next)
            )
        )

        rv = self.app.get('/events')

        self.verify_response(
            rv,
            pagination={"next": expected_next}
        )

        store.get_events_by_timerange.assert_called_with(
            after=None,
            before=None,
            feeds=self._all_feeds_names,
            pagesize=10,
            embed_related=True,
            timezone=None
        )

        self._event_set.page.assert_called_with(cursor=None)
Esempio n. 7
0
def parse(value, timezone):

    values = value.split(',')

    if len(values) == 1:
        return BySearchCursor(int(values[0]))
    elif len(values) == 2:
        return ByTimeRangeCursor(datetime_format(values[0]),
                                 str(uuid.UUID(values[1])),
                                 timezone=timezone)
    else:
        raise ValueError("unrecognized cursor format")