Beispiel #1
0
def test_await_json_bad_message(upstream):
    """
    The Wormhole.await_json method should not break if the upstream resolves
    into a message that does not conform to the wormhole spec.
    """
    upstream.get_message = lambda: succeed('some string')

    wormhole = Wormhole()
    with pytest.raises(SuspiciousOperation):
        yield wormhole.await_json()
Beispiel #2
0
def test_await_json_works(upstream):
    """
    The Wormhole.await_json method should resolve into a dict parsed from the
    upstream's return value.
    """
    upstream.get_message = lambda: succeed(dict_to_bytes({'answer': 42}))

    wormhole = Wormhole()
    res = yield wormhole.await_json()
    assert res == {'answer': 42}
Beispiel #3
0
def test_await_json_timeout(upstream):
    """
    The Wormhole.await_json method should be able to handle timeouts.
    """
    def get_message():
        deferred = Deferred()
        reactor.callLater(2, deferred.callback, dict_to_bytes({}))
        return deferred
    upstream.get_message = get_message

    wormhole = Wormhole()
    with pytest.raises(Timeout):
        yield wormhole.await_json(timeout=0)