openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5 KiB

import pytest
5 days ago
from openpilot.system.hardware.base import LPABase, Profile
5 days ago
class MockLPA(LPABase):
def bootstrap(self) -> None:
pass
def list_profiles(self) -> list[Profile]:
return []
def get_active_profile(self) -> Profile | None:
return None
def delete_profile(self, iccid: str) -> None:
pass
def download_profile(self, qr: str, nickname: str | None = None) -> None:
pass
def nickname_profile(self, iccid: str, nickname: str) -> None:
pass
def switch_profile(self, iccid: str) -> None:
pass
class TestLPAValidation:
def setup_method(self):
5 days ago
self.lpa = MockLPA()
def test_validate_iccid(self):
5 days ago
self.lpa.validate_iccid('8988303000000614227')
with pytest.raises(AssertionError, match='invalid ICCID format'):
5 days ago
self.lpa.validate_iccid('')
with pytest.raises(AssertionError, match='invalid ICCID format'):
5 days ago
self.lpa.validate_iccid('1234567890123456789') # Doesn't start with 89
def test_validate_lpa_activation_code(self):
5 days ago
self.lpa.validate_lpa_activation_code('LPA:1$rsp.truphone.com$QRF-BETTERROAMING-PMRDGIR2EARDEIT5')
with pytest.raises(AssertionError, match='invalid LPA activation code format'):
5 days ago
self.lpa.validate_lpa_activation_code('')
with pytest.raises(AssertionError, match='invalid LPA activation code format'):
5 days ago
self.lpa.validate_lpa_activation_code('LPA:1$domain.com') # Missing third part
def test_validate_nickname(self):
5 days ago
self.lpa.validate_nickname('test_profile')
with pytest.raises(AssertionError, match='nickname must be between 1 and 16 characters'):
5 days ago
self.lpa.validate_nickname('')
with pytest.raises(AssertionError, match='nickname must contain only alphanumeric characters'):
5 days ago
self.lpa.validate_nickname('test.profile') # Contains invalid character
def test_validate_profile_exists(self, mocker):
existing_profiles = [Profile(iccid='8988303000000614227', nickname='test1', enabled=True, provider='Test Provider')]
mocker.patch.object(self.lpa, 'list_profiles', return_value=existing_profiles)
5 days ago
self.lpa.validate_profile_exists('8988303000000614227')
mocker.patch.object(self.lpa, 'list_profiles', return_value=[])
5 days ago
with pytest.raises(AssertionError, match='profile 8988303000000614227 does not exist'):
self.lpa.validate_profile_exists('8988303000000614227')
mocker.patch.object(self.lpa, 'list_profiles', return_value=existing_profiles)
5 days ago
with pytest.raises(AssertionError, match='profile 8988303000000614229 does not exist'):
self.lpa.validate_profile_exists('8988303000000614229')