Beispiel #1
0
def test_serialization_is_idempotent(fieldmap_class, nested_parties_group):
    kwargs = {}
    fields = [(35, "a"), (2, "b"), *nested_parties_group.values(), (3, "c")]

    if fieldmap_class.__name__ == FieldDict.__name__:
        kwargs["group_templates"] = {
            539: {
                "*": [524, 525, 538, 804]
            },
            804: {
                "*": [545, 805]
            },
        }

    fm = fieldmap_class(*fields, **kwargs)

    encoded = encoders.to_json(fm)
    decoded = decoders.from_json(encoded)

    assert fm == decoded

    encoded = encoders.to_json(decoded)
    decoded = decoders.from_json(encoded)

    assert fm == decoded
Beispiel #2
0
    def test_default_nested_fielddict_raises_exception_on_duplicate_tags_without_template_defined(
            self, nested_parties_group, encoded_dict_sample):
        with pytest.raises(DuplicateTags):
            broken_encoding = {**json.loads(encoded_dict_sample)}
            broken_encoding.pop("group_templates")
            broken_encoding = json.dumps(broken_encoding)

            decoders.from_json(broken_encoding)
Beispiel #3
0
    async def _send_channel_reader(self):
        try:
            with await self.redis_pool as conn:
                await conn.subscribe(self.SEND_CHANNEL)

                send_channel = conn.channels[self.SEND_CHANNEL]

                while await send_channel.wait_message():
                    message = await send_channel.get()
                    message = decoders.from_json(utils.decode(message))
                    asyncio.create_task(
                        self.send(message))  # Pass message on to pipeline

        except aioredis.ChannelClosedError:
            # Shutting down...
            logger.info(f"{self.name}: Unsubscribed from {send_channel.name}.")
Beispiel #4
0
    def test_get_send(self, api_app):

        msg = admin.TestRequestMessage("TEST123")
        encoded_msg = encoders.to_json(msg)

        response = api_app.flask_app.post("/send",
                                          data={"message": encoded_msg})

        assert response.status_code == 200

        result = json.loads(response.data)
        assert result["success"] is True
        assert result["message"] == "Successfully added message to pipeline!"
        assert result["data"]["message"] == encoded_msg

        assert (decoders.from_json(result["data"]["message"]) == msg
                )  # Test idempotency while we're at it.
Beispiel #5
0
    def post(self):
        """
        Endpoint for sending a FIX message.

        'message' should be a FIXMessage that was previously JSON-encoded with encoders.to_json(message).

        """
        args = self.parser.parse_args()
        message = decoders.from_json(args["message"])

        asyncio.create_task(self.app.send(message))

        return JsonResultResponse(
            True,
            "Successfully added message to pipeline!",
            {"message": args["message"]},
        )
Beispiel #6
0
    def test_default_nested_fielddict_decodes_as_expected(
            self, nested_parties_group, encoded_dict_sample):
        fm = FieldDict(
            (35, "a"),
            (2, "b"),
            *nested_parties_group.values(),
            (3, "c"),
            group_templates={
                539: {
                    "*": [524, 525, 538, 804]
                },
                804: {
                    "*": [545, 805]
                }
            },
        )

        assert decoders.from_json(encoded_dict_sample) == fm
Beispiel #7
0
    def test_default_nested_fieldlist_encodes_as_expected(
            self, nested_parties_group, encoded_list_sample):
        fm = FieldList((35, "a"), (2, "b"), *nested_parties_group.values(),
                       (3, "c"))

        assert decoders.from_json(encoded_list_sample) == fm