diff --git a/meshtastic/node.py b/meshtastic/node.py index 1e6e893..837c06a 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -203,6 +203,7 @@ class Node: channelSet = apponly_pb2.ChannelSet() channelSet.ParseFromString(decodedURL) + if len(channelSet.settings) == 0: our_exit("Warning: There were no settings.") @@ -213,6 +214,7 @@ class Node: ch.index = i ch.settings.CopyFrom(chs) self.channels[ch.index] = ch + logging.debug(f'Channel i:{i} ch:{ch}') self.writeChannel(ch.index) i = i + 1 @@ -246,6 +248,7 @@ class Node: is ignored for other nodes)""" p = admin_pb2.AdminMessage() p.exit_simulator = True + logging.debug('in exitSimulator()') return self._sendAdmin(p) diff --git a/meshtastic/tests/test_node.py b/meshtastic/tests/test_node.py index 8d07f32..528bead 100644 --- a/meshtastic/tests/test_node.py +++ b/meshtastic/tests/test_node.py @@ -81,3 +81,61 @@ def test_setOwner_no_short_name_and_long_name_has_words(caplog): assert re.search(r'p.set_owner.short_name:ABC:', caplog.text, re.MULTILINE) assert re.search(r'p.set_owner.is_licensed:True', caplog.text, re.MULTILINE) assert re.search(r'p.set_owner.team:0', caplog.text, re.MULTILINE) + + +@pytest.mark.unit +def test_exitSimulator(caplog): + """Test exitSimulator""" + anode = Node('foo', 'bar', noProto=True) + with caplog.at_level(logging.DEBUG): + anode.exitSimulator() + assert re.search(r'in exitSimulator', caplog.text, re.MULTILINE) + + +@pytest.mark.unit +def test_reboot(caplog): + """Test reboot""" + anode = Node('foo', 'bar', noProto=True) + with caplog.at_level(logging.DEBUG): + anode.reboot() + assert re.search(r'Telling node to reboot', caplog.text, re.MULTILINE) + + +@pytest.mark.unit +def test_setURL_empty_url(): + """Test reboot""" + anode = Node('foo', 'bar', noProto=True) + with pytest.raises(SystemExit) as pytest_wrapped_e: + anode.setURL('') + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == 1 + + +@pytest.mark.unit +def test_setURL_valid_URL(caplog): + """Test setURL""" + iface = MagicMock(autospec=SerialInterface) + url = "https://www.meshtastic.org/d/#CgUYAyIBAQ" + with caplog.at_level(logging.DEBUG): + anode = Node(iface, 'bar', noProto=True) + anode.radioConfig = 'baz' + channels = ['zoo'] + anode.channels = channels + anode.setURL(url) + assert re.search(r'Channel i:0', caplog.text, re.MULTILINE) + assert re.search(r'modem_config: Bw125Cr48Sf4096', caplog.text, re.MULTILINE) + assert re.search(r'psk: "\\001"', caplog.text, re.MULTILINE) + assert re.search(r'role: PRIMARY', caplog.text, re.MULTILINE) + + +@pytest.mark.unit +def test_setURL_valid_URL_but_no_settings(caplog): + """Test setURL""" + iface = MagicMock(autospec=SerialInterface) + url = "https://www.meshtastic.org/d/#" + with pytest.raises(SystemExit) as pytest_wrapped_e: + anode = Node(iface, 'bar', noProto=True) + anode.radioConfig = 'baz' + anode.setURL(url) + assert pytest_wrapped_e.type == SystemExit + assert pytest_wrapped_e.value.code == 1