コード例 #1
0
    def test_measurement_id_returns_proper_data(self, query_patch):
        handler = create_measurement_handler(DEFAULT_ENTITY_ID,
                                             DEFAULT_AGGREGATION_LENGTH,
                                             DEFAULT_AGGREGATION_TYPE,
                                             {'measurement_id': 17})

        self.assertEqual(handler.evaluate(1, 10), [(100000, 0.5),
                                                   (100001, None)])
        self.assertEqual(query_patch.call_count, 1)
コード例 #2
0
    def test_create_measurement_handler_returns_proper_handler_types(
            self, query_patch):
        handler = create_measurement_handler(DEFAULT_ENTITY_ID,
                                             DEFAULT_AGGREGATION_LENGTH,
                                             DEFAULT_AGGREGATION_TYPE,
                                             {'measurement_id': 17})
        self.assertTrue(isinstance(handler, MeasurementIdType))

        handler = create_measurement_handler(DEFAULT_ENTITY_ID,
                                             DEFAULT_AGGREGATION_LENGTH,
                                             DEFAULT_AGGREGATION_TYPE, {
                                                 'unary_operator': 'minus',
                                                 'arg': {
                                                     'measurement_id': 17
                                                 }
                                             })
        self.assertTrue(isinstance(handler, UnaryMeasurementType))
        self.assertTrue(isinstance(handler._child, MeasurementIdType))

        handler = create_measurement_handler(
            DEFAULT_ENTITY_ID, DEFAULT_AGGREGATION_LENGTH,
            DEFAULT_AGGREGATION_TYPE, {
                'binary_operator': 'add',
                'arg1': {
                    'measurement_id': 17
                },
                'arg2': {
                    'unary_operator': 'minus',
                    'arg': {
                        'measurement_id': 12
                    }
                }
            })
        self.assertTrue(isinstance(handler, BinaryMeasurementType))
        self.assertTrue(isinstance(handler._child1, MeasurementIdType))
        self.assertTrue(isinstance(handler._child2, UnaryMeasurementType))
        self.assertEqual(handler._operator(3, 5), 8)
コード例 #3
0
 def __init__(self, request_id: int, payload: dict):
     super().__init__(request_id, payload)
     session = Session()
     self._entity = get_one(session,
                            Entity,
                            id=self._raw_payload.node_id,
                            exception_cls=ValueError)
     self._requested_data = [
         create_measurement_handler(self._raw_payload.node_id,
                                    self._raw_payload.aggregation_length,
                                    self._raw_payload.aggregation_type,
                                    data)
         for data in self._raw_payload.requested_data
     ]
     self._run_assertions()
コード例 #4
0
    def test_binary_measurement_type_add_returns_proper_data(
            self, query_patch):
        handler = create_measurement_handler(
            DEFAULT_ENTITY_ID, DEFAULT_AGGREGATION_LENGTH,
            DEFAULT_AGGREGATION_TYPE, {
                'binary_operator': 'add',
                'arg1': {
                    'measurement_id': 17
                },
                'arg2': {
                    'measurement_id': 12
                }
            })

        self.assertEqual(handler.evaluate(1, 10), [(100000, 1),
                                                   (100001, None)])
        self.assertEqual(query_patch.call_count, 2)