

def test_stringReceived():
    proto = MessageProtocol()

    class C(object):

        def __init__(self, name, val):
            setattr(self, name, val)
    node = C('message_received', MagicMock())
    factory = C('node', node)
    setattr(proto, 'factory', factory)
    msg = {
        'type': 'message',
        'message': 'hello',
    }
    proto.stringReceived(json.dumps(msg))
    assert (1 == proto.factory.node.message_received.call_count)
    assert (msg == proto.factory.node.message_received.call_args[0][0])

dataset/ETHPy150Open hpk42/p4p/tests/test_protocol.py test_stringReceived/original