vibe coded uts

Trey Moen 5 days ago
parent 7a47efd5fb
commit 8b4d8f8ade
  1. 144
      system/hardware/tici/tests/test_esim.py

@ -9,13 +9,12 @@ TEST_ICCID = '8944476500001944011'
TEST_NICKNAME = 'test_profile'
def cleanup():
def cleanup(active_profile_iccid: str):
lpa = LPA2()
try:
lpa.delete_profile(TEST_ICCID)
except LPAProfileNotFoundError:
pass
assert lpa.get_active_profile() is None
lpa.process_notifications()
assert len(lpa.list_notifications()) == 0
@ -25,36 +24,119 @@ class TestEsim:
def setup_class(cls):
if not TICI:
pytest.skip()
return
cleanup()
def teardown_class(self):
cleanup()
# Save the active profile before running tests
cls.lpa = LPA2()
cls.original_profile = cls.lpa.get_active_profile()
if cls.original_profile:
cls.original_iccid = cls.original_profile['iccid']
else:
cls.original_iccid = None
# Download test profile once for all tests
cleanup(TEST_ICCID)
cls.lpa.download_profile(TEST_ACTIVATION_CODE, TEST_NICKNAME)
# Verify profile was downloaded
profiles = cls.lpa.list_profiles()
cls.test_profile = next((p for p in profiles if p['iccid'] == TEST_ICCID), None)
assert cls.test_profile is not None
assert cls.test_profile['nickname'] == TEST_NICKNAME
@classmethod
def teardown_class(cls):
# Restore the original profile if it existed
if cls.original_iccid:
try:
cls.lpa.enable_profile(cls.original_iccid)
except Exception as e:
print(f"Failed to restore original profile: {e}")
cleanup(TEST_ICCID)
def setup_method(self):
# Clean up any test profile before each test
cleanup(TEST_ICCID)
def test_list_profiles(self):
lpa = LPA2()
profiles = lpa.list_profiles()
assert profiles is not None
profiles = self.lpa.list_profiles()
assert isinstance(profiles, list)
for profile in profiles:
assert isinstance(profile, dict)
assert 'iccid' in profile
assert 'isdp_aid' in profile
assert 'nickname' in profile
assert 'enabled' in profile
assert 'provider' in profile
def test_download_enable_disable_profile(self):
lpa = LPA2()
lpa.download_profile(self.TEST_ACTIVATION_CODE, self.TEST_NICKNAME)
assert self._profile_exists(lpa, self.TEST_ICCID, self.TEST_NICKNAME)
self._enable_profile(lpa)
self._disable_profile(lpa)
def _enable_profile(self, lpa: LPA2):
lpa.enable_profile(self.TEST_ICCID)
current = lpa.get_active_profile()
assert current is not None
assert current['iccid'] == self.TEST_ICCID
def _disable_profile(self, lpa: LPA2):
lpa.disable_profile(self.TEST_ICCID)
current = lpa.get_active_profile()
assert current is None
def _profile_exists(self, lpa: LPA2, iccid: str, nickname: str) -> bool:
profiles = lpa.list_profiles()
return any(p['iccid'] == iccid and p['nickname'] == nickname for p in profiles)
def test_get_active_profile(self):
active_profile = self.lpa.get_active_profile()
if active_profile:
assert isinstance(active_profile, dict)
assert active_profile['enabled']
assert 'iccid' in active_profile
assert 'isdp_aid' in active_profile
assert 'nickname' in active_profile
assert 'provider' in active_profile
def test_list_notifications(self):
notifications = self.lpa.list_notifications()
assert isinstance(notifications, list)
for notification in notifications:
assert isinstance(notification, dict)
assert 'sequence_number' in notification
assert 'profile_management_operation' in notification
assert 'notification_address' in notification
assert 'iccid' in notification
def test_enable_profile(self):
# Enable the profile
self.lpa.enable_profile(TEST_ICCID)
# Verify profile is enabled
active_profile = self.lpa.get_active_profile()
assert active_profile is not None
assert active_profile['iccid'] == TEST_ICCID
assert active_profile['enabled']
def test_disable_profile(self):
# First enable the profile
self.lpa.enable_profile(TEST_ICCID)
# Disable the profile
self.lpa.disable_profile(TEST_ICCID)
# Verify profile is disabled
active_profile = self.lpa.get_active_profile()
assert active_profile is None or active_profile['iccid'] != TEST_ICCID
def test_delete_profile(self):
# Delete the profile
self.lpa.delete_profile(TEST_ICCID)
# Verify profile is deleted
profiles = self.lpa.list_profiles()
assert not any(p['iccid'] == TEST_ICCID for p in profiles)
def test_nickname_profile(self):
# Change nickname
new_nickname = "new_test_nickname"
self.lpa.nickname_profile(TEST_ICCID, new_nickname)
# Verify nickname was changed
profiles = self.lpa.list_profiles()
test_profile = next((p for p in profiles if p['iccid'] == TEST_ICCID), None)
assert test_profile is not None
assert test_profile['nickname'] == new_nickname
def test_profile_not_found_error(self):
with pytest.raises(LPAProfileNotFoundError):
self.lpa.enable_profile("nonexistent_iccid")
with pytest.raises(LPAProfileNotFoundError):
self.lpa.disable_profile("nonexistent_iccid")
with pytest.raises(LPAProfileNotFoundError):
self.lpa.delete_profile("nonexistent_iccid")
with pytest.raises(LPAProfileNotFoundError):
self.lpa.nickname_profile("nonexistent_iccid", "test")

Loading…
Cancel
Save