1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import pytest
from ssdpy.cli import server as server_cli
def test_invalid_arguments():
with pytest.raises(SystemExit):
server_cli.parse_args(("TestServer", "--invalid-argument"))
def test_version():
with pytest.raises(SystemExit):
server_cli.parse_args(("TestServer", "--version"))
def test_verbose():
args = server_cli.parse_args(("TestServer", "-v"))
assert args.verbose is True
args = server_cli.parse_args(("TestServer", "--verbose"))
assert args.verbose is True
def test_ssdpserver_init(mocker):
mocker.patch.object(server_cli, "SSDPServer")
server_cli.main(("TestServer",))
server_cli.SSDPServer.assert_called_once_with(
"TestServer",
address=None,
al=None,
device_type="ssdp:rootdevice",
iface=None,
location=None,
max_age=None,
port=1900,
proto="ipv4",
extra_fields=None,
)
def test_ssdpserver_init_with_ipv6(mocker):
mocker.patch.object(server_cli, "SSDPServer")
server_cli.main(("TestServer", "-6"))
server_cli.SSDPServer.assert_called_once_with(
"TestServer",
address=None,
al=None,
device_type="ssdp:rootdevice",
iface=None,
location=None,
max_age=None,
port=1900,
proto="ipv6",
extra_fields=None,
)
mocker.patch.object(server_cli, "SSDPServer")
server_cli.main(("TestServer", "--ipv6"))
server_cli.SSDPServer.assert_called_once_with(
"TestServer",
address=None,
al=None,
device_type="ssdp:rootdevice",
iface=None,
location=None,
max_age=None,
port=1900,
proto="ipv6",
extra_fields=None,
)
def test_ssdpserver_init_with_args(mocker):
mocker.patch.object(server_cli, "SSDPServer")
server_cli.main(
(
"TestServer",
"-i",
"lo",
"-a",
"test-address",
"-l",
"test-location",
"-p",
"0",
"-6",
"-t",
"test-device",
"--max-age",
"0",
"-e",
"test-field",
"foo"
)
)
server_cli.SSDPServer.assert_called_once_with(
"TestServer",
address="test-address",
al="test-location",
device_type="test-device",
iface=b"lo",
location="test-location",
max_age=0,
port=0,
proto="ipv6",
extra_fields={"test-field": "foo"},
)
|