def test_plm_sent(self, tmpdir): calls = [] def callback(success, msg, done): calls.append((success, msg, done)) modem = H.main.MockModem(tmpdir) proto = H.main.MockProtocol() handler = IM.handler.ModemInfo(modem, callback) assert not handler._PLM_sent #Try a message prior to sent msg = Msg.OutModemInfo(addr=IM.Address('11.22.33'), dev_cat=0x44, sub_cat=0x55, firmware=0x66, is_ack=True) r = handler.msg_received(proto, msg) assert r == Msg.UNKNOWN # Signal Sent handler.sending_message(msg) assert handler._PLM_sent #Try a message prior to sent msg = Msg.OutModemInfo(addr=IM.Address('11.22.33'), dev_cat=0x44, sub_cat=0x55, firmware=0x66, is_ack=True) r = handler.msg_received(proto, msg) assert r == Msg.FINISHED
def test_load_config_step2_success_addr_diff(self, test_device, tmpdir, caplog): cfg = IM.config.load('config-example.yaml') cfg['storage'] = tmpdir test_device.addr = IM.Address('44.85.11') msg = Msg.OutModemInfo(addr=IM.Address('44.85.12'), dev_cat=None, sub_cat=None, firmware=None, is_ack=True) test_device.load_config_step2(True, 'message', msg, cfg) assert 'Modem address in config 44.85.11 does not match address' in caplog.text
def test_out(self): obj = Msg.OutModemInfo() assert obj.fixed_msg_size == 9 b = obj.to_bytes() rt = bytes([0x02, 0x60]) assert b == rt str(obj)
def test_load_config_step2_success_addr_same(self, test_device, tmpdir, caplog): cfg = IM.config.load('config-example.yaml') cfg['storage'] = tmpdir test_device.addr = IM.Address('44.85.11') msg = Msg.OutModemInfo(addr=test_device.addr, dev_cat=None, sub_cat=None, firmware=None, is_ack=True) test_device.load_config_step2(True, 'message', msg, cfg) for record in caplog.records: assert record.levelname != "ERROR"
def test_acks(self, tmpdir): calls = [] def callback(success, msg, done): calls.append((success, msg, done)) modem = H.main.MockModem(tmpdir) proto = H.main.MockProtocol() handler = IM.handler.ModemInfo(modem, callback) handler._PLM_sent = True handler._PLM_ACK = True #Try a good message msg = Msg.OutModemInfo(addr=IM.Address('11.22.33'), dev_cat=0x44, sub_cat=0x55, firmware=0x66, is_ack=True) r = handler.msg_received(proto, msg) assert r == Msg.FINISHED assert calls[0][0] #Try a NAK message msg = Msg.OutModemInfo(addr=IM.Address('11.22.33'), dev_cat=0x44, sub_cat=0x55, firmware=0x66, is_ack=False) r = handler.msg_received(proto, msg) assert r == Msg.FINISHED assert not calls[1][0] #Wrong Message msg = Msg.OutResetModem(is_ack=True) r = handler.msg_received(proto, msg) assert r == Msg.UNKNOWN