@@ -1669,7 +1669,7 @@ def test_delete_device_happy_path(self, mock_insecure_channel, mock_device_servi
16691669 mock_channel = Mock ()
16701670 mock_insecure_channel .return_value = mock_channel
16711671
1672- # Mock the GatewayServiceStub
1672+ # Mock the DeviceServiceStub
16731673 mock_device_service_stub_instance = mock_device_service_stub .return_value
16741674 mock_device_service_stub_instance .Delete .return_value = None
16751675
@@ -1716,6 +1716,69 @@ def test_delete_device_unauthenticated_grpc_error(self, mock_sleep, mock_insecur
17161716 # assertations
17171717 self .assertEqual (return_val , None )
17181718
1719+
1720+ class TestDeleteProfile (unittest .TestCase ):
1721+
1722+ @patch ('chirpstack_api_wrapper.api.DeviceProfileServiceStub' )
1723+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
1724+ def test_delete_device_profile_happy_path (self , mock_insecure_channel , mock_dp_service_stub ):
1725+ """
1726+ Test delete_device_profile() method's happy path
1727+ """
1728+
1729+ # Mock the gRPC channel and login response
1730+ mock_channel = Mock ()
1731+ mock_insecure_channel .return_value = mock_channel
1732+
1733+ # Mock the DeviceProfileServiceStub
1734+ mock_dp_service_stub_instance = mock_dp_service_stub .return_value
1735+ mock_dp_service_stub_instance .Delete .return_value = None
1736+
1737+ # Create a ChirpstackClient instance
1738+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
1739+
1740+ # Call method in testing
1741+ return_val = client .delete_device_profile ("mock id" )
1742+
1743+ # Assert the result
1744+ self .assertEqual (return_val , None )
1745+
1746+
1747+ @patch ("chirpstack_api_wrapper.api.DeviceProfileServiceStub" )
1748+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
1749+ @patch ("chirpstack_api_wrapper.time.sleep" , return_value = None ) #dont time.sleep() for test case
1750+ def test_delete_device_profile_unauthenticated_grpc_error (self , mock_sleep , mock_insecure_channel , mock_dp_service_stub ):
1751+ """
1752+ Test delete_device_profile() when grpc error is raised for UNAUTHENTICATED and token needs to be refreshed
1753+ """
1754+ # Mock the gRPC channel and login response
1755+ mock_channel = Mock ()
1756+ mock_insecure_channel .return_value = mock_channel
1757+
1758+ # Mock the method to raise grpc.RpcError()
1759+ mock_rpc_error = grpc .RpcError ()
1760+ mock_rpc_error .code = lambda : grpc .StatusCode .UNAUTHENTICATED
1761+ mock_rpc_error .details = lambda : 'ExpiredSignature'
1762+
1763+ # Mock the DeviceProfileServiceStub
1764+ mock_dp_service_stub_instance = mock_dp_service_stub .return_value
1765+ mock_dp_service_stub_instance .Delete .side_effect = mock_rpc_error
1766+
1767+ # Create a ChirpstackClient instance
1768+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
1769+
1770+ # Mock the login method to return a dummy token
1771+ with patch .object (client , "login" , return_value = "dummy_token" ):
1772+
1773+ #mock refresh token successfully logging in and retrying the method in testing
1774+ with patch .object (client , "refresh_token" , return_value = None ):
1775+ # Call the method in testing
1776+ return_val = client .delete_device_profile ("mock id" )
1777+
1778+ # assertations
1779+ self .assertEqual (return_val , None )
1780+
1781+
17191782class TestRefreshToken (unittest .TestCase ):
17201783
17211784 @patch ("chirpstack_api_wrapper.api.DeviceServiceStub" )
0 commit comments