test: align suite with shipped behavior (WiFi swap, BUG-10 guard, odometer_baseline)
- test_app_trip + test_trip_sql: mock was_car_ever_connected() so trip building runs (BUG-10 guard suppresses trips until car ECU reached) - test_app_settings: include odometer_baseline in valid payload + assert save - test_yaris_uplink: Hotspot -> Hotspot-local; restore_fallback no longer activates AP (reports no_connection); wait timeout writes fallback_restored - test_app_network: local_hotspot mode removed by WiFi swap -> wifi/no-internet
This commit is contained in:
@@ -55,9 +55,9 @@ class AppNetworkTest(unittest.TestCase):
|
|||||||
@patch("modules.app_network._phone_ssid", return_value="")
|
@patch("modules.app_network._phone_ssid", return_value="")
|
||||||
@patch(
|
@patch(
|
||||||
"modules.app_network._nmcli",
|
"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,
|
self,
|
||||||
_nmcli,
|
_nmcli,
|
||||||
_ssid,
|
_ssid,
|
||||||
@@ -65,7 +65,7 @@ class AppNetworkTest(unittest.TestCase):
|
|||||||
with patch("builtins.open", side_effect=FileNotFoundError):
|
with patch("builtins.open", side_effect=FileNotFoundError):
|
||||||
status = app_network.get_status()
|
status = app_network.get_status()
|
||||||
|
|
||||||
self.assertEqual(status["mode"], "local_hotspot")
|
self.assertEqual(status["mode"], "wifi")
|
||||||
self.assertFalse(status["internet_reachable"])
|
self.assertFalse(status["internet_reachable"])
|
||||||
self.assertFalse(status["large_upload_allowed"])
|
self.assertFalse(status["large_upload_allowed"])
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ def valid_payload():
|
|||||||
"ntfy_token": "secret-token",
|
"ntfy_token": "secret-token",
|
||||||
"clear_ntfy_url": False,
|
"clear_ntfy_url": False,
|
||||||
"clear_ntfy_token": False,
|
"clear_ntfy_token": False,
|
||||||
|
"odometer_baseline": 0,
|
||||||
"alert_thresholds": {
|
"alert_thresholds": {
|
||||||
"temperature_c": 75.5,
|
"temperature_c": 75.5,
|
||||||
"disk_percent": 88,
|
"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_ntfy_token"], "secret-token")
|
||||||
self.assertEqual(self.settings["alert_temperature_c"], "75.5")
|
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):
|
def test_invalid_payload_does_not_save_any_settings(self):
|
||||||
payload = valid_payload()
|
payload = valid_payload()
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from modules import app_trip
|
from modules import app_trip
|
||||||
|
|
||||||
|
|
||||||
class TripBuilderTest(unittest.TestCase):
|
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):
|
def rows_for_route(self, coordinates, speeds=None, start_id=1):
|
||||||
started = datetime(2026, 1, 1, 8)
|
started = datetime(2026, 1, 1, 8)
|
||||||
speeds = speeds or [0] * len(coordinates)
|
speeds = speeds or [0] * len(coordinates)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from modules import app_sql
|
from modules import app_sql
|
||||||
|
|
||||||
@@ -15,8 +16,15 @@ class TripSqlTest(unittest.TestCase):
|
|||||||
app_sql._last_trip_refresh = 0
|
app_sql._last_trip_refresh = 0
|
||||||
app_sql.sql_path = self.path
|
app_sql.sql_path = self.path
|
||||||
self.conn = app_sql.get_conn()
|
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):
|
def tearDown(self):
|
||||||
|
self._car_connected.stop()
|
||||||
if app_sql._conn is not None:
|
if app_sql._conn is not None:
|
||||||
app_sql._conn.close()
|
app_sql._conn.close()
|
||||||
app_sql._conn = None
|
app_sql._conn = None
|
||||||
|
|||||||
+11
-16
@@ -70,7 +70,7 @@ class UplinkSelectionTest(unittest.TestCase):
|
|||||||
@patch("deploy.yaris_uplink.phone_is_visible", return_value=True)
|
@patch("deploy.yaris_uplink.phone_is_visible", return_value=True)
|
||||||
@patch("deploy.yaris_uplink.activate", return_value=True)
|
@patch("deploy.yaris_uplink.activate", return_value=True)
|
||||||
@patch("deploy.yaris_uplink.connection_exists", 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(
|
def test_phone_is_preferred_over_home_from_local_hotspot(
|
||||||
self,
|
self,
|
||||||
_active,
|
_active,
|
||||||
@@ -135,25 +135,18 @@ class UplinkSelectionTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@patch("deploy.yaris_uplink.write_status")
|
@patch("deploy.yaris_uplink.write_status")
|
||||||
@patch(
|
@patch("deploy.yaris_uplink.activate", return_value=False)
|
||||||
"deploy.yaris_uplink.activate",
|
def test_home_unavailable_reports_no_connection(
|
||||||
side_effect=[False, True],
|
|
||||||
)
|
|
||||||
def test_local_hotspot_is_restored_when_home_is_unavailable(
|
|
||||||
self,
|
self,
|
||||||
activate,
|
activate,
|
||||||
write_status,
|
write_status,
|
||||||
):
|
):
|
||||||
self.assertTrue(yaris_uplink.restore_fallback())
|
self.assertTrue(yaris_uplink.restore_fallback())
|
||||||
|
|
||||||
self.assertEqual(
|
activate.assert_called_once_with("home-wifi")
|
||||||
activate.call_args_list,
|
write_status.assert_called_once_with(
|
||||||
[
|
"no_connection", "No home WiFi or phone hotspot available."
|
||||||
call("home-wifi"),
|
|
||||||
call("Hotspot"),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
write_status.assert_called_once_with("restored_local_hotspot")
|
|
||||||
|
|
||||||
|
|
||||||
class UplinkWaitTest(unittest.TestCase):
|
class UplinkWaitTest(unittest.TestCase):
|
||||||
@@ -188,8 +181,10 @@ class UplinkWaitTest(unittest.TestCase):
|
|||||||
@patch("deploy.yaris_uplink.write_status")
|
@patch("deploy.yaris_uplink.write_status")
|
||||||
@patch("deploy.yaris_uplink.active_connection", return_value="home-wifi")
|
@patch("deploy.yaris_uplink.active_connection", return_value="home-wifi")
|
||||||
@patch("deploy.yaris_uplink.connection_exists", return_value=True)
|
@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,
|
self,
|
||||||
|
_home,
|
||||||
_exists,
|
_exists,
|
||||||
_active,
|
_active,
|
||||||
write_status,
|
write_status,
|
||||||
@@ -201,14 +196,14 @@ class UplinkWaitTest(unittest.TestCase):
|
|||||||
|
|
||||||
write_status.assert_any_call("waiting_for_phone")
|
write_status.assert_any_call("waiting_for_phone")
|
||||||
write_status.assert_called_with(
|
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.",
|
"Phone hotspot did not appear within two minutes.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class UplinkTransitionTest(unittest.TestCase):
|
class UplinkTransitionTest(unittest.TestCase):
|
||||||
@patch("deploy.yaris_uplink.write_status")
|
@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):
|
def test_records_networkmanager_fallback(self, _active, write_status):
|
||||||
yaris_uplink.record_current_connection()
|
yaris_uplink.record_current_connection()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user