vibe coded uts

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

@ -9,13 +9,12 @@ TEST_ICCID = '8944476500001944011'
TEST_NICKNAME = 'test_profile' TEST_NICKNAME = 'test_profile'
def cleanup(): def cleanup(active_profile_iccid: str):
lpa = LPA2() lpa = LPA2()
try: try:
lpa.delete_profile(TEST_ICCID) lpa.delete_profile(TEST_ICCID)
except LPAProfileNotFoundError: except LPAProfileNotFoundError:
pass pass
assert lpa.get_active_profile() is None
lpa.process_notifications() lpa.process_notifications()
assert len(lpa.list_notifications()) == 0 assert len(lpa.list_notifications()) == 0
@ -25,36 +24,119 @@ class TestEsim:
def setup_class(cls): def setup_class(cls):
if not TICI: if not TICI:
pytest.skip() pytest.skip()
return
cleanup()
def teardown_class(self): # Save the active profile before running tests
cleanup() 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): def test_list_profiles(self):
lpa = LPA2() profiles = self.lpa.list_profiles()
profiles = lpa.list_profiles() assert isinstance(profiles, list)
assert profiles is not None for profile in profiles:
assert isinstance(profile, dict)
def test_download_enable_disable_profile(self): assert 'iccid' in profile
lpa = LPA2() assert 'isdp_aid' in profile
lpa.download_profile(self.TEST_ACTIVATION_CODE, self.TEST_NICKNAME) assert 'nickname' in profile
assert self._profile_exists(lpa, self.TEST_ICCID, self.TEST_NICKNAME) assert 'enabled' in profile
assert 'provider' in profile
self._enable_profile(lpa)
self._disable_profile(lpa) def test_get_active_profile(self):
active_profile = self.lpa.get_active_profile()
def _enable_profile(self, lpa: LPA2): if active_profile:
lpa.enable_profile(self.TEST_ICCID) assert isinstance(active_profile, dict)
current = lpa.get_active_profile() assert active_profile['enabled']
assert current is not None assert 'iccid' in active_profile
assert current['iccid'] == self.TEST_ICCID assert 'isdp_aid' in active_profile
assert 'nickname' in active_profile
def _disable_profile(self, lpa: LPA2): assert 'provider' in active_profile
lpa.disable_profile(self.TEST_ICCID)
current = lpa.get_active_profile() def test_list_notifications(self):
assert current is None notifications = self.lpa.list_notifications()
assert isinstance(notifications, list)
def _profile_exists(self, lpa: LPA2, iccid: str, nickname: str) -> bool: for notification in notifications:
profiles = lpa.list_profiles() assert isinstance(notification, dict)
return any(p['iccid'] == iccid and p['nickname'] == nickname for p in profiles) 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