@@ -1961,6 +1961,67 @@ def test_delete_device_profile_unauthenticated_grpc_error(self, mock_sleep, mock
19611961 # assertations
19621962 self .assertEqual (return_val , None )
19631963
1964+ class TestDeleteGateway (unittest .TestCase ):
1965+
1966+ @patch ('chirpstack_api_wrapper.api.GatewayServiceStub' )
1967+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
1968+ def test_delete_gateway_happy_path (self , mock_insecure_channel , mock_gw_service_stub ):
1969+ """
1970+ Test delete_gateway() method's happy path
1971+ """
1972+
1973+ # Mock the gRPC channel and login response
1974+ mock_channel = Mock ()
1975+ mock_insecure_channel .return_value = mock_channel
1976+
1977+ # Mock the GatewayServiceStub
1978+ mock_gw_service_stub_instance = mock_gw_service_stub .return_value
1979+ mock_gw_service_stub_instance .Delete .return_value = None
1980+
1981+ # Create a ChirpstackClient instance
1982+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
1983+
1984+ # Call method in testing
1985+ return_val = client .delete_gateway ("mock id" )
1986+
1987+ # Assert the result
1988+ self .assertEqual (return_val , None )
1989+
1990+
1991+ @patch ("chirpstack_api_wrapper.api.GatewayServiceStub" )
1992+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
1993+ @patch ("chirpstack_api_wrapper.time.sleep" , return_value = None ) #dont time.sleep() for test case
1994+ def test_delete_gateway_unauthenticated_grpc_error (self , mock_sleep , mock_insecure_channel , mock_gw_service_stub ):
1995+ """
1996+ Test delete_gateway() when grpc error is raised for UNAUTHENTICATED and token needs to be refreshed
1997+ """
1998+ # Mock the gRPC channel and login response
1999+ mock_channel = Mock ()
2000+ mock_insecure_channel .return_value = mock_channel
2001+
2002+ # Mock the method to raise grpc.RpcError()
2003+ mock_rpc_error = grpc .RpcError ()
2004+ mock_rpc_error .code = lambda : grpc .StatusCode .UNAUTHENTICATED
2005+ mock_rpc_error .details = lambda : 'ExpiredSignature'
2006+
2007+ # Mock the GatewayServiceStub
2008+ mock_gw_service_stub_instance = mock_gw_service_stub .return_value
2009+ mock_gw_service_stub_instance .Delete .side_effect = mock_rpc_error
2010+
2011+ # Create a ChirpstackClient instance
2012+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
2013+
2014+ # Mock the login method to return a dummy token
2015+ with patch .object (client , "login" , return_value = "dummy_token" ):
2016+
2017+ #mock refresh token successfully logging in and retrying the method in testing
2018+ with patch .object (client , "refresh_token" , return_value = None ):
2019+ # Call the method in testing
2020+ return_val = client .delete_gateway ("mock id" )
2021+
2022+ # assertations
2023+ self .assertEqual (return_val , None )
2024+
19642025class TestRefreshToken (unittest .TestCase ):
19652026
19662027 @patch ("chirpstack_api_wrapper.api.DeviceServiceStub" )
0 commit comments