Example #1
0
    def test_cad_batch_engine_interactor(self):

        interactor = BatchEngineInteractor(DummyBatch(),
                                           EngineBuilderFactory.get_cad(),
                                           InputJsonMessageHandler())
        data = interactor.process()

        for i, item in enumerate(data):
            self.assertEqual(item.agg_value, i)
    def test_parse_message_and_validate_invalid(self):
        handler = InputJsonMessageHandler()
        with self.assertRaises(ValidationError) as ctx:
            handler.parse_message(self.INVALID_MESSAGE_1)

        self.assertEqual(ctx.exception.message,
                         "'value' is a required property")

        with self.assertRaises(ValidationError) as ctx:
            handler.parse_message(self.INVALID_MESSAGE_2)

        self.assertEqual(ctx.exception.message, "'ts' is a required property")

        with self.assertRaises(ValidationError) as ctx:
            handler.parse_message(self.INVALID_MESSAGE_3)

        self.assertEqual(ctx.exception.message,
                         "'application' is a required property")
Example #3
0
    async def get(self):

        input_data = {
            k: v[0].decode("utf-8")
            for k, v in self.request.arguments.items()
        }

        engines = EngineBuilderFactory.engines
        engine = input_data["engine"] if "engine" in input_data else "robust"
        file_input_value = input_data["file"] if "file" in input_data else ""

        engine_builder = EngineBuilderFactory.get(engine)
        for k in filter(lambda x: x.startswith("set"), input_data):
            try:
                engine_builder = engine_builder.set(k.replace("set_", ""),
                                                    input_data[k])
            except NotImplementedError as ex:
                self.logger.warning(str(ex))

        form = EngineBuilderForm(engine_builder).get_form()

        data = []
        if file_input_value:
            interactor = BatchEngineInteractor(
                FileObservable(file_input_value), engine_builder,
                InputJsonMessageHandler())

            data = [x.to_plain_dict() for x in interactor.process()]

        file_input = {
            "label": "Input file (JSON)",
            "name": "file",
            "type": "text",
            "value": file_input_value,
            "placeholder": "Local file to play with",
            "id": "input_file"
        }

        self.response(signal_name="Sandbox",
                      engine_key=engine,
                      engine_name=engine,
                      engines=engines,
                      form=form,
                      file_input=file_input,
                      data=json_encode(data))
 def test_extract_ts(self):
     handler = InputJsonMessageHandler()
     in_message = handler.parse_message(self.VALID_MESSAGE)
     self.assertEqual(handler.extract_ts(in_message), datetime(2018, 1, 1))
 def test_extract_value(self):
     handler = InputJsonMessageHandler()
     in_message = handler.parse_message(self.VALID_MESSAGE)
     self.assertEqual(handler.extract_value(in_message), 0.87)
 def test_parse_message_and_validate(self):
     handler = InputJsonMessageHandler()
     in_message = handler.parse_message(self.VALID_MESSAGE)
     self.assertEqual(handler.validate_message(in_message), True)
Example #7
0
 def get_json():
     return InputJsonMessageHandler()