Пример #1
0
    async def test_last_impacts(self):
        all_impacts = await self.prepere_data()

        data = impacts_pb2.GetImpactsHistoryRequest(
            filter=impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
                'NONE'),
            limit=100).SerializeToString()

        request = await self.client.post('/get-impacts-history', data=data)
        answer = await self.check_success(
            request, impacts_pb2.GetImpactsHistoryResponse)

        self.assertEqual([
            protobuf.to_impact(impact, use_time=True)
            for impact in answer.impacts
        ], all_impacts)
Пример #2
0
    async def test_last_target_impacts__limit(self):
        all_impacts = await self.prepere_data()

        data = impacts_pb2.GetImpactsHistoryRequest(
            filter=impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
                'ONLY_TARGET'),
            target=impacts_pb2.Object(type=100, id=1000),
            limit=3).SerializeToString()

        request = await self.client.post('/get-impacts-history', data=data)
        answer = await self.check_success(
            request, impacts_pb2.GetImpactsHistoryResponse)

        self.assertEqual([
            protobuf.to_impact(impact, use_time=True)
            for impact in answer.impacts
        ], [all_impacts[0], all_impacts[1], all_impacts[4]])
Пример #3
0
    async def test_last_actor_impacts(self):
        all_impacts = await self.prepere_data()

        data = impacts_pb2.GetImpactsHistoryRequest(
            filter=impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
                'ONLY_ACTOR'),
            actor=impacts_pb2.Object(type=1, id=10),
            limit=100).SerializeToString()

        request = await self.client.post('/get-impacts-history', data=data)
        answer = await self.check_success(
            request, impacts_pb2.GetImpactsHistoryResponse)

        self.assertEqual([
            protobuf.to_impact(impact, use_time=True)
            for impact in answer.impacts
        ], [
            all_impacts[2], all_impacts[3], all_impacts[4], all_impacts[7],
            all_impacts[8], all_impacts[9]
        ])
Пример #4
0
    def cmd_get_last_power_impacts(self,
                                   limit,
                                   actor_type=None,
                                   actor_id=None,
                                   target_type=None,
                                   target_id=None):

        filter_type = impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
            'NONE')

        if actor_type is not None:
            if target_type is not None:
                filter_type = impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
                    'BOTH')
            else:
                filter_type = impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
                    'ONLY_ACTOR')
        elif target_type is not None:
            filter_type = impacts_pb2.GetImpactsHistoryRequest.FilterType.Value(
                'ONLY_TARGET')

        data = impacts_pb2.GetImpactsHistoryRequest(
            filter=filter_type,
            actor=impacts_pb2.Object(
                type=actor_type.value if actor_type else None, id=actor_id),
            target=impacts_pb2.Object(
                type=target_type.value if target_type else None, id=target_id),
            limit=limit)

        answer = tt_api.sync_request(
            url=self.entry_point + 'get-impacts-history',
            data=data,
            AnswerType=impacts_pb2.GetImpactsHistoryResponse)

        return [
            PowerImpact.from_tt_object(type=self.impact_type, tt_impact=impact)
            for impact in answer.impacts
        ]