"""Discovery parsing, with no network: the two shapes cameras actually send."""
from behavision.discover import parse_probe_match, guess_make, local_networks
HIK = (''
''
'onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/name/HIKVISION%20DS-2CD2043G2 '
'onvif://www.onvif.org/hardware/DS-2CD2043G2-I onvif://www.onvif.org/location/city/hangzhou'
'http://192.168.1.122/onvif/device_service'
'')
BARE = (''
'http://10.0.0.9:8080/onvif/device_service http://[fe80::1]/onvif'
'')
def test_hikvision_probe_match_is_named_and_recognised():
f = parse_probe_match(HIK, "192.168.1.122")
assert f.host == "192.168.1.122"
assert f.onvif and not f.rtsp
assert "HIKVISION DS-2CD2043G2" in f.name and "DS-2CD2043G2-I" in f.name
assert f.make == "hikvision"
def test_a_nameless_match_still_yields_its_address():
f = parse_probe_match(BARE, "10.0.0.9")
assert f.host == "10.0.0.9" and f.name == "" and f.make == ""
assert f.onvif_url.startswith("http://10.0.0.9:8080")
def test_garbage_is_not_a_camera():
assert parse_probe_match("not soap", "1.2.3.4") is None
def test_make_guesses_the_common_indian_retail_brands():
assert guess_make("CP PLUS CP-UNC-TA21L3") == "cpplus"
assert guess_make("Dahua IPC-HDW1230") == "dahua"
assert guess_make("TP-LINK Tapo C200") == "tplink"
assert guess_make("Something Else") == ""
def test_local_networks_are_slash_24_and_never_loopback():
for n in local_networks():
assert n.prefixlen == 24
assert not n.network_address.is_loopback