"""Why a camera "will not connect", when the real answer is that the computer asking is in the wrong building. Asked directly by the owner, about his own cameras, from his phone's connection: *"when i connect from my mobile internet the cameras wont connect, why is that"*. The answer was `cannot reach 192.168.1.121:554 - Operation timed out`, which reads as a broken camera and sends somebody to re-type an address and a password that were always correct. """ import pytest from behavision import capture @pytest.fixture def on(monkeypatch): def _set(ip): monkeypatch.setattr(capture, "_local_ipv4", lambda: ip) return _set def test_a_different_network_says_so_and_says_what_to_do(on): on("10.11.12.13") # a phone's tethered network hint = capture._wrong_network_hint("192.168.1.121") assert "not the camera's network" in hint # The action, not just the diagnosis: no setting on this screen fixes it. assert "computer in the shop" in hint def test_the_same_network_sends_you_to_the_camera_instead(on): on("192.168.1.120") hint = capture._wrong_network_hint("192.168.1.121") assert "on that network" in hint assert "powered on" in hint # Two states that need opposite actions must not share a sentence. assert "not the camera's network" not in hint @pytest.mark.parametrize("host", [ "8.8.8.8", # plainly routable "203.0.113.9", # TEST-NET-3: `is_private` calls this private, and it is # not a LAN address - which is why the check spells out # the RFC1918 blocks instead of asking is_private "100.64.0.5", # carrier-grade NAT, what a mobile network hands out ]) def test_an_address_that_is_not_a_lan_address_gets_no_hint(on, host): """A routable address unreachable from here is an ordinary network fault, and inventing a story about private networks would be wrong.""" on("192.168.1.120") assert capture._wrong_network_hint(host) == "" def test_a_name_gets_no_hint(on): """Nothing can be concluded about `camera.local` from the string, and a guess here is a confident wrong answer in the place people look first.""" on("192.168.1.120") assert capture._wrong_network_hint("camera.local") == "" def test_loopback_gets_no_hint(on): on("192.168.1.120") assert capture._wrong_network_hint("127.0.0.1") == "" def test_with_no_network_at_all_it_still_names_the_cause(on): """A machine with no route cannot say which network it is on, and must not pretend: the private-address fact is still true and still the reason.""" on("") hint = capture._wrong_network_hint("192.168.1.121") assert "private address" in hint assert "this computer is on" not in hint def test_the_hint_reaches_the_message_a_person_reads(): """The whole point is the sentence on the screen, not a helper nobody calls. Port 1 on a private address refuses or times out immediately.""" ok, msg = capture._tcp_reachable("rtsp://192.168.1.121:1/ch0", 1.0) assert not ok assert "192.168.1.121" in msg # Whichever branch the OS takes, the explanation travels with it. assert "network" in msg