예제 #1
0
def test_build_response():
    message_factory = MessageFactory()
    message = CallResponseMessage(
        flags=FlagsType.none,
        code=StatusCode.ok,
        headers={},
        id=12,
    )

    req = message_factory.build_response(message)
    assert req.code == message.code
    assert req.flags == message.flags
    assert req.headers == message.headers
    assert req.id == message.id
예제 #2
0
def test_build_raw_response_message():
    message_factory = MessageFactory()
    resp = Response(
        flags=FlagsType.none,
        code=StatusCode.ok,
        headers={},
        id=1111,
    )
    resp.state = StreamState.init
    message = message_factory.build_raw_response_message(resp, None, True)
    assert message.code == resp.code
    assert message.flags == resp.flags
    assert message.id == resp.id
    assert message.headers == resp.headers
예제 #3
0
def test_message_fragment(arg2, arg3, connection):
    msg = CallRequestMessage(args=["", arg2, arg3])
    origin_msg = CallRequestMessage(args=["", arg2, arg3])
    message_factory = MessageFactory(connection)
    fragments = message_factory.fragment(msg)
    recv_msg = None
    for fragment in fragments:
        output = message_factory.build(fragment)
        if output:
            recv_msg = output
    header = yield recv_msg.get_header()
    body = yield recv_msg.get_body()
    assert header == origin_msg.args[1]
    assert body == origin_msg.args[2]
예제 #4
0
def test_message_fragment(arg2, arg3, connection):
    msg = CallRequestMessage(args=["", arg2, arg3])
    origin_msg = CallRequestMessage(args=["", arg2, arg3])
    message_factory = MessageFactory(connection)
    fragments = message_factory.fragment(msg)
    recv_msg = None
    for fragment in fragments:
        output = message_factory.build(fragment)
        if output:
            recv_msg = output
    header = yield recv_msg.get_header()
    body = yield recv_msg.get_body()
    assert header == origin_msg.args[1]
    assert body == origin_msg.args[2]
예제 #5
0
def test_build_raw_request_message():
    message_factory = MessageFactory()
    req = Request(
        ttl=32,
        service="test",
        headers={},
        id=1111,
    )
    req.state = StreamState.init
    message = message_factory.build_raw_request_message(req, None, True)
    assert message.ttl / 1000.0 == req.ttl
    assert message.flags == req.flags
    assert message.id == req.id
    assert message.service == req.service
    assert message.headers == req.headers
예제 #6
0
def test_build_request():
    message_factory = MessageFactory()
    message = CallRequestMessage(
        flags=FlagsType.none,
        ttl=100,
        service="test",
        headers={},
        id=12,
    )

    req = message_factory.build_request(message)
    assert req.ttl == message.ttl / 1000.0
    assert req.flags == message.flags
    assert req.headers == message.headers
    assert req.id == message.id
    assert req.service == message.service