add main unit test for --seturl

This commit is contained in:
Mike Kinney committed 2021-12-12 17:05:38 -08:00
1 parent 59e14d3741
commit d2a9b87968
2 files changed
+22 -1

No files matched your search

+1 -1
View File
@@ -732,7 +732,7 @@ def initParser():
"--setlon", help="Set device longitude (allows use without GPS)")
parser.add_argument(
"--pos-fields", help="Specify position message fields. Use '0' for list of valid values. "\
"--pos-fields", help="Specify fields to send when sending a position. Use no argument for a list of valid values. "\
"Can pass multiple values as a space separated list like "\
"this: '--pos-fields POS_ALTITUDE POS_ALT_MSL'",
nargs="*", action="store")
+21
View File
@@ -604,3 +604,24 @@ def test_main_set_team_invalid(capsys):
assert err == ''
mo.assert_called()
mm.Value.assert_called()
@pytest.mark.unit
def test_main_seturl(capsys):
"""Test --seturl (url used below is what is generated after a factory_reset)"""
sys.argv = ['', '--seturl', 'https://www.meshtastic.org/d/#CgUYAyIBAQ']
args = sys.argv
parser = None
parser = argparse.ArgumentParser()
our_globals = Globals.getInstance()
our_globals.set_parser(parser)
our_globals.set_args(args)
iface = MagicMock(autospec=SerialInterface)
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
main()
out, err = capsys.readouterr()
print('out:', out)
print('err:', err)
assert re.search(r'Connected to radio', out, re.MULTILINE)
assert err == ''
mo.assert_called()