diff --git a/tests/test_app_network.py b/tests/test_app_network.py index 6b02be7..4b75af2 100644 --- a/tests/test_app_network.py +++ b/tests/test_app_network.py @@ -55,9 +55,9 @@ class AppNetworkTest(unittest.TestCase): @patch("modules.app_network._phone_ssid", return_value="") @patch( "modules.app_network._nmcli", - return_value="Hotspot\n100 (connected)\n2 (portal)\n10.42.0.1/24", + return_value="home-wifi\n100 (connected)\n2 (portal)\n192.168.50.220/24", ) - def test_local_hotspot_does_not_claim_internet_or_large_uploads( + def test_no_internet_blocks_large_uploads( self, _nmcli, _ssid, @@ -65,7 +65,7 @@ class AppNetworkTest(unittest.TestCase): with patch("builtins.open", side_effect=FileNotFoundError): status = app_network.get_status() - self.assertEqual(status["mode"], "local_hotspot") + self.assertEqual(status["mode"], "wifi") self.assertFalse(status["internet_reachable"]) self.assertFalse(status["large_upload_allowed"]) diff --git a/tests/test_app_settings.py b/tests/test_app_settings.py index 50b2f91..6d4cab1 100644 --- a/tests/test_app_settings.py +++ b/tests/test_app_settings.py @@ -18,6 +18,7 @@ def valid_payload(): "ntfy_token": "secret-token", "clear_ntfy_url": False, "clear_ntfy_token": False, + "odometer_baseline": 0, "alert_thresholds": { "temperature_c": 75.5, "disk_percent": 88, @@ -66,6 +67,7 @@ class SettingsUpdateTest(unittest.TestCase): ) self.assertEqual(self.settings["alert_ntfy_token"], "secret-token") self.assertEqual(self.settings["alert_temperature_c"], "75.5") + self.assertEqual(self.settings["odometer_baseline"], "0.0") def test_invalid_payload_does_not_save_any_settings(self): payload = valid_payload() diff --git a/tests/test_app_trip.py b/tests/test_app_trip.py index 3ea2213..2db8bbc 100644 --- a/tests/test_app_trip.py +++ b/tests/test_app_trip.py @@ -1,10 +1,22 @@ import unittest from datetime import datetime, timedelta +from unittest.mock import patch from modules import app_trip class TripBuilderTest(unittest.TestCase): + def setUp(self): + # BUG-10 guard suppresses trips until the car ECU has been reached + # once. Trip-building tests simulate a connected car. + self._car_connected = patch( + "modules.app_obd.was_car_ever_connected", return_value=True + ) + self._car_connected.start() + + def tearDown(self): + self._car_connected.stop() + def rows_for_route(self, coordinates, speeds=None, start_id=1): started = datetime(2026, 1, 1, 8) speeds = speeds or [0] * len(coordinates) diff --git a/tests/test_trip_sql.py b/tests/test_trip_sql.py index 6fa64ec..edf95f8 100644 --- a/tests/test_trip_sql.py +++ b/tests/test_trip_sql.py @@ -2,6 +2,7 @@ import os import tempfile import unittest from datetime import datetime, timedelta +from unittest.mock import patch from modules import app_sql @@ -15,8 +16,15 @@ class TripSqlTest(unittest.TestCase): app_sql._last_trip_refresh = 0 app_sql.sql_path = self.path self.conn = app_sql.get_conn() + # refresh_trips() and build_trip_summaries() suppress trips until the + # car ECU has been reached once (BUG-10 guard). Simulate a connected car. + self._car_connected = patch( + "modules.app_obd.was_car_ever_connected", return_value=True + ) + self._car_connected.start() def tearDown(self): + self._car_connected.stop() if app_sql._conn is not None: app_sql._conn.close() app_sql._conn = None diff --git a/tests/test_yaris_uplink.py b/tests/test_yaris_uplink.py index d68d5bf..0d9ad98 100644 --- a/tests/test_yaris_uplink.py +++ b/tests/test_yaris_uplink.py @@ -70,7 +70,7 @@ class UplinkSelectionTest(unittest.TestCase): @patch("deploy.yaris_uplink.phone_is_visible", return_value=True) @patch("deploy.yaris_uplink.activate", return_value=True) @patch("deploy.yaris_uplink.connection_exists", return_value=True) - @patch("deploy.yaris_uplink.active_connection", return_value="Hotspot") + @patch("deploy.yaris_uplink.active_connection", return_value="Hotspot-local") def test_phone_is_preferred_over_home_from_local_hotspot( self, _active, @@ -135,25 +135,18 @@ class UplinkSelectionTest(unittest.TestCase): ) @patch("deploy.yaris_uplink.write_status") - @patch( - "deploy.yaris_uplink.activate", - side_effect=[False, True], - ) - def test_local_hotspot_is_restored_when_home_is_unavailable( + @patch("deploy.yaris_uplink.activate", return_value=False) + def test_home_unavailable_reports_no_connection( self, activate, write_status, ): self.assertTrue(yaris_uplink.restore_fallback()) - self.assertEqual( - activate.call_args_list, - [ - call("home-wifi"), - call("Hotspot"), - ], + activate.assert_called_once_with("home-wifi") + write_status.assert_called_once_with( + "no_connection", "No home WiFi or phone hotspot available." ) - write_status.assert_called_once_with("restored_local_hotspot") class UplinkWaitTest(unittest.TestCase): @@ -188,8 +181,10 @@ class UplinkWaitTest(unittest.TestCase): @patch("deploy.yaris_uplink.write_status") @patch("deploy.yaris_uplink.active_connection", return_value="home-wifi") @patch("deploy.yaris_uplink.connection_exists", return_value=True) - def test_wait_timeout_preserves_current_client_connection( + @patch("deploy.yaris_uplink._connect_home_or_idle", return_value=True) + def test_wait_timeout_restores_home_fallback( self, + _home, _exists, _active, write_status, @@ -201,14 +196,14 @@ class UplinkWaitTest(unittest.TestCase): write_status.assert_any_call("waiting_for_phone") write_status.assert_called_with( - "phone_wait_timed_out_current_connection_preserved", + "phone_wait_timed_out_fallback_restored", "Phone hotspot did not appear within two minutes.", ) class UplinkTransitionTest(unittest.TestCase): @patch("deploy.yaris_uplink.write_status") - @patch("deploy.yaris_uplink.active_connection", return_value="Hotspot") + @patch("deploy.yaris_uplink.active_connection", return_value="Hotspot-local") def test_records_networkmanager_fallback(self, _active, write_status): yaris_uplink.record_current_connection()