예제 #1
0
async def test_handleNodeListReport(gateway: ZIPGateway):
    async def ipOfNode(_):
        return ipaddress.IPv6Address("::1")

    listener = MagicMock()
    gateway.ipOfNode = ipOfNode
    gateway.addListener(listener)
    gateway._nodes = {
        1: {
            "ip": ipaddress.IPv6Address("::1")
        },
        2: {
            "ip": ipaddress.IPv6Address("::1")
        },
    }
    # pylint: disable=line-too-long
    zipPkt = b"#\x02@\x10\x00\x00\x00R\x02\x02\x00\x01!\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    future = gateway.onUnsolicitedMessage(zipPkt, ("::1", ))
    await asyncio.gather(future)
    assert gateway._nodes == {
        1: {
            "ip": ipaddress.IPv6Address("::1")
        },
        6: {
            "ip": ipaddress.IPv6Address("::1")
        },
    }
    listener.nodeListUpdated.assert_called_once()
예제 #2
0
def test_onUnsolicitedMessage(gateway: ZIPGateway):
    ip = ipaddress.IPv6Address("::ffff:c0a8:ee")
    gateway._nodes = {7: {"ip": ip}}
    pkt = b"#\x02\x80\xc0\xf9\x00\x00\x05\x84\x02\x00\x00%\x03\x00"
    assert gateway.onUnsolicitedMessage(pkt, (ip, 4123)) is True

    # Extract the flags from the call
    call = gateway.listener.messageReceived.mock_calls[1]
    args = call[1]
    flags = args[4]
    gateway.listener.messageReceived.assert_called_once_with(
        gateway, 7, 0, SwitchBinary.Report(value=0), flags)
    gateway._unsolicitedConnection.sendTo.assert_called_once_with(
        b"#\x02@\x00\xf9\x00\x00", (ip, 4123))
예제 #3
0
def test_onUnsolicitedMessage_unknownNode(gateway: ZIPGateway):
    ip = ipaddress.IPv6Address("::ffff:c0a8:ee")
    gateway._nodes = {7: {"ip": ipaddress.IPv6Address("::ffff:c0a8:ef")}}
    pkt = b"#\x02\x00\xc0\xf9\x00\x00\x05\x84\x02\x00\x00%\x03\x00"
    assert gateway.onUnsolicitedMessage(pkt, (ip, )) is False
    gateway.listener.messageReceived.assert_not_called()