@@ -1656,6 +1656,67 @@ def test_create_gw_unauthenticated_grpc_error(self, mock_sleep, mock_insecure_ch
16561656 # assertations
16571657 self .assertEqual (return_val , None )
16581658
1659+ class TestDeleteApp (unittest .TestCase ):
1660+
1661+ @patch ('chirpstack_api_wrapper.api.ApplicationServiceStub' )
1662+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
1663+ def test_delete_app_happy_path (self , mock_insecure_channel , mock_app_service_stub ):
1664+ """
1665+ Test delete_app() method's happy path
1666+ """
1667+
1668+ # Mock the gRPC channel and login response
1669+ mock_channel = Mock ()
1670+ mock_insecure_channel .return_value = mock_channel
1671+
1672+ # Mock the ApplicationServiceStub
1673+ mock_app_service_stub_instance = mock_app_service_stub .return_value
1674+ mock_app_service_stub_instance .Delete .return_value = None
1675+
1676+ # Create a ChirpstackClient instance
1677+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
1678+
1679+ # Call method in testing
1680+ return_val = client .delete_app ("mock id" )
1681+
1682+ # Assert the result
1683+ self .assertEqual (return_val , None )
1684+
1685+
1686+ @patch ("chirpstack_api_wrapper.api.ApplicationServiceStub" )
1687+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
1688+ @patch ("chirpstack_api_wrapper.time.sleep" , return_value = None ) #dont time.sleep() for test case
1689+ def test_delete_app_unauthenticated_grpc_error (self , mock_sleep , mock_insecure_channel , mock_app_service_stub ):
1690+ """
1691+ Test delete_app() when grpc error is raised for UNAUTHENTICATED and token needs to be refreshed
1692+ """
1693+ # Mock the gRPC channel and login response
1694+ mock_channel = Mock ()
1695+ mock_insecure_channel .return_value = mock_channel
1696+
1697+ # Mock the method to raise grpc.RpcError()
1698+ mock_rpc_error = grpc .RpcError ()
1699+ mock_rpc_error .code = lambda : grpc .StatusCode .UNAUTHENTICATED
1700+ mock_rpc_error .details = lambda : 'ExpiredSignature'
1701+
1702+ # Mock the ApplicationServiceStub
1703+ mock_app_service_stub_instance = mock_app_service_stub .return_value
1704+ mock_app_service_stub_instance .Delete .side_effect = mock_rpc_error
1705+
1706+ # Create a ChirpstackClient instance
1707+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
1708+
1709+ # Mock the login method to return a dummy token
1710+ with patch .object (client , "login" , return_value = "dummy_token" ):
1711+
1712+ #mock refresh token successfully logging in and retrying the method in testing
1713+ with patch .object (client , "refresh_token" , return_value = None ):
1714+ # Call the method in testing
1715+ return_val = client .delete_app ("mock id" )
1716+
1717+ # assertations
1718+ self .assertEqual (return_val , None )
1719+
16591720class TestDeleteDevice (unittest .TestCase ):
16601721
16611722 @patch ('chirpstack_api_wrapper.api.DeviceServiceStub' )
@@ -1716,7 +1777,6 @@ def test_delete_device_unauthenticated_grpc_error(self, mock_sleep, mock_insecur
17161777 # assertations
17171778 self .assertEqual (return_val , None )
17181779
1719-
17201780class TestDeleteProfile (unittest .TestCase ):
17211781
17221782 @patch ('chirpstack_api_wrapper.api.DeviceProfileServiceStub' )
@@ -1778,7 +1838,6 @@ def test_delete_device_profile_unauthenticated_grpc_error(self, mock_sleep, mock
17781838 # assertations
17791839 self .assertEqual (return_val , None )
17801840
1781-
17821841class TestRefreshToken (unittest .TestCase ):
17831842
17841843 @patch ("chirpstack_api_wrapper.api.DeviceServiceStub" )
0 commit comments