|  |  | @ -4,6 +4,7 @@ from openpilot.system.hardware import TICI | 
			
		
	
		
		
			
				
					
					|  |  |  | from openpilot.system.hardware.tici.esim import LPA2, LPAProfileNotFoundError |  |  |  | from openpilot.system.hardware.tici.esim import LPA2, LPAProfileNotFoundError | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | # https://euicc-manual.osmocom.org/docs/rsp/known-test-profile |  |  |  | # https://euicc-manual.osmocom.org/docs/rsp/known-test-profile | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | # iccid is always the same for the given activation code | 
			
		
	
		
		
			
				
					
					|  |  |  | TEST_ACTIVATION_CODE = 'LPA:1$rsp.truphone.com$QRF-BETTERROAMING-PMRDGIR2EARDEIT5' |  |  |  | TEST_ACTIVATION_CODE = 'LPA:1$rsp.truphone.com$QRF-BETTERROAMING-PMRDGIR2EARDEIT5' | 
			
		
	
		
		
			
				
					
					|  |  |  | TEST_ICCID = '8944476500001944011' |  |  |  | TEST_ICCID = '8944476500001944011' | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -15,7 +16,6 @@ def cleanup(): | 
			
		
	
		
		
			
				
					
					|  |  |  |     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 +25,27 @@ class TestEsim: | 
			
		
	
		
		
			
				
					
					|  |  |  |   def setup_class(cls): |  |  |  |   def setup_class(cls): | 
			
		
	
		
		
			
				
					
					|  |  |  |     if not TICI: |  |  |  |     if not TICI: | 
			
		
	
		
		
			
				
					
					|  |  |  |       pytest.skip() |  |  |  |       pytest.skip() | 
			
		
	
		
		
			
				
					
					|  |  |  |       return |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cleanup() |  |  |  |     cleanup() | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def teardown_class(self): |  |  |  |   def teardown_class(self): | 
			
		
	
		
		
			
				
					
					|  |  |  |     cleanup() |  |  |  |     cleanup() | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def test_list_profiles(self): |  |  |  |   def test_provision_enable_disable(self): | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     lpa = LPA2() |  |  |  |     lpa = LPA2() | 
			
		
	
		
		
			
				
					
					|  |  |  |     profiles = lpa.list_profiles() |  |  |  |     current_active = lpa.get_active_profile() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     assert profiles is not None |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def test_download_enable_disable_profile(self): |  |  |  |     lpa.download_profile(TEST_ACTIVATION_CODE, TEST_NICKNAME) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     lpa = LPA2() |  |  |  |     assert any(p['iccid'] == TEST_ICCID and p['nickname'] == TEST_NICKNAME for p in lpa.list_profiles()) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     lpa.download_profile(self.TEST_ACTIVATION_CODE, self.TEST_NICKNAME) |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     assert self._profile_exists(lpa, self.TEST_ICCID, self.TEST_NICKNAME) |  |  |  |     lpa.enable_profile(TEST_ICCID) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     new_active = lpa.get_active_profile() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     self._enable_profile(lpa) |  |  |  |     assert new_active is not None | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     self._disable_profile(lpa) |  |  |  |     assert new_active['iccid'] == TEST_ICCID | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     assert new_active['nickname'] == TEST_NICKNAME | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   def _enable_profile(self, lpa: LPA2): |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     lpa.enable_profile(self.TEST_ICCID) |  |  |  |     lpa.disable_profile(TEST_ICCID) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     current = lpa.get_active_profile() |  |  |  |     new_active = lpa.get_active_profile() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     assert current is not None |  |  |  |     assert new_active is None | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     assert current['iccid'] == self.TEST_ICCID |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     if current_active: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   def _disable_profile(self, lpa: LPA2): |  |  |  |       lpa.enable_profile(current_active['iccid']) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     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) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
	
		
		
			
				
					|  |  | 
 |