def test_acks(self):
        calls = []

        def callback(success, msg, done):
            calls.append(msg)

        proto = MockProtocol()
        db = Mockdb()
        handler = IM.handler.ModemDbGet(db, callback)
        handler._PLM_sent = True
        handler._PLM_ACK = True

        get_first = Msg.OutAllLinkGetFirst(is_ack=True)
        get_next = Msg.OutAllLinkGetNext(is_ack=True)
        get_nak = Msg.OutAllLinkGetNext(is_ack=False)

        r = handler.msg_received(proto, get_first)
        assert r == Msg.CONTINUE

        r = handler.msg_received(proto, get_next)
        assert r == Msg.CONTINUE

        r = handler.msg_received(proto, get_nak)
        assert r == Msg.FINISHED
        assert calls == ['Database download complete']

        r = handler.msg_received(proto, "dummy")
        assert r == Msg.UNKNOWN
Exemple #2
0
    def test_acks(self):
        calls = []

        def callback(msg):
            calls.append(msg)

        proto = MockProtocol()
        handler = IM.handler.ModemGetDb(callback)

        get_first = Msg.OutAllLinkGetFirst(is_ack=True)
        get_next = Msg.OutAllLinkGetNext(is_ack=True)
        get_nak = Msg.OutAllLinkGetNext(is_ack=False)

        r = handler.msg_received(proto, get_first)
        assert r == Msg.CONTINUE

        r = handler.msg_received(proto, get_next)
        assert r == Msg.CONTINUE

        r = handler.msg_received(proto, get_nak)
        assert r == Msg.FINISHED
        assert calls == [None]

        r = handler.msg_received(proto, "dummy")
        assert r == Msg.UNKNOWN
    def test_out(self):
        obj = Msg.OutAllLinkGetFirst()
        assert obj.fixed_msg_size == 3

        b = obj.to_bytes()
        rt = bytes([0x02, 0x69])
        assert b == rt

        str(obj)
    def test_plm_ack_sent(self, caplog):
        calls = []

        def callback(success, msg, done):
            calls.append(msg)

        proto = MockProtocol()
        db = Mockdb()
        handler = IM.handler.ModemDbGet(db, callback)
        msg = Msg.OutAllLinkGetFirst(is_ack=True)

        # test not sent
        r = handler.msg_received(proto, msg)
        assert r == Msg.UNKNOWN

        # Signal Sent
        handler.sending_message(msg)
        assert handler._PLM_sent
        assert not handler._PLM_ACK

        # test receive ack
        r = handler.msg_received(proto, msg)
        assert r == Msg.CONTINUE