Beispiel #1
0
    async def test_filter(self):
        events = await self.prepair_data()

        response = await self.client.post(
            '/get-events',
            data=events_log_pb2.GetEventsRequest(
                tags=[2], page=1, records_on_page=2).SerializeToString())

        data = await self.check_success(response,
                                        events_log_pb2.GetEventsResponse)

        self.assertEqual(
            list(data.events),
            [protobuf.from_event(events[0]),
             protobuf.from_event(events[2])])
        self.assertEqual(data.page, 1)
        self.assertEqual(data.total_records, 3)

        response = await self.client.post(
            '/get-events',
            data=events_log_pb2.GetEventsRequest(
                tags=[2], page=2, records_on_page=2).SerializeToString())

        data = await self.check_success(response,
                                        events_log_pb2.GetEventsResponse)

        self.assertEqual(list(data.events), [protobuf.from_event(events[4])])
        self.assertEqual(data.page, 2)
        self.assertEqual(data.total_records, 3)
Beispiel #2
0
    async def test_no_events(self):
        response = await self.client.post(
            '/get-events',
            data=events_log_pb2.GetEventsRequest(
                tags=[1, 13,
                      666], page=1, records_on_page=3).SerializeToString())

        data = await self.check_success(response,
                                        events_log_pb2.GetEventsResponse)

        self.assertEqual(list(data.events), [])
        self.assertEqual(data.page, 1)
        self.assertEqual(data.total_records, 0)
Beispiel #3
0
    async def test_pages__large_page(self):
        events = await self.prepair_data()

        response = await self.client.post(
            '/get-events',
            data=events_log_pb2.GetEventsRequest(
                tags=[], page=100, records_on_page=3).SerializeToString())

        data = await self.check_success(response,
                                        events_log_pb2.GetEventsResponse)

        self.assertEqual(list(data.events), [protobuf.from_event(events[6])])
        self.assertEqual(data.page, 3)
        self.assertEqual(data.total_records, 7)
Beispiel #4
0
    async def test_serialization(self):
        events = await self.prepair_data()

        response = await self.client.post(
            '/get-events',
            data=events_log_pb2.GetEventsRequest(
                tags=[], page=1, records_on_page=1).SerializeToString())

        data = await self.check_success(response,
                                        events_log_pb2.GetEventsResponse)

        event = data.events[0]

        self.assertEqual(event.id, events[0].id)
        self.assertEqual(s11n.from_json(event.data), {'turn': 0})
        self.assertEqual(set(event.tags), {1, 2})
        self.assertEqual(event.turn, 0)
        self.assertEqual(
            event.time,
            time.mktime(events[0].created_at.timetuple()) +
            events[0].created_at.microsecond / 1000000)