@@ -896,6 +896,64 @@ def test_get_device_activation_unauthenticated_grpc_error(self, mock_sleep, mock
896896 # assertations
897897 self .assertEqual (result , "mock_activation_details" )
898898
899+ @patch ("chirpstack_api_wrapper.api.DeviceServiceStub" )
900+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
901+ def test_get_device_activation_not_found_grpc_error (self , mock_insecure_channel , mock_device_service_stub ):
902+ """
903+ Test get_device_activation() when grpc error is raised for NOT_FOUND
904+ """
905+ # Mock the gRPC channel and login response
906+ mock_channel = Mock ()
907+ mock_insecure_channel .return_value = mock_channel
908+
909+ # Mock the get_device method to raise grpc.RpcError()
910+ mock_rpc_error = grpc .RpcError ()
911+ mock_rpc_error .code = lambda : grpc .StatusCode .NOT_FOUND
912+ mock_rpc_error .details = lambda : 'Object does not exist'
913+
914+ # Mock the DeviceServiceStub
915+ mock_device_service_stub_instance = mock_device_service_stub .return_value
916+ mock_device_service_stub_instance .GetActivation .side_effect = mock_rpc_error
917+
918+ # Create a ChirpstackClient instance
919+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
920+
921+ # Mock the dev_eui
922+ mock_dev_eui = "mock_dev_eui"
923+
924+ result = client .get_device_activation (mock_dev_eui )
925+
926+ self .assertEqual (result , {})
927+
928+ @patch ("chirpstack_api_wrapper.api.DeviceServiceStub" )
929+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
930+ def test_get_device_activation_other_grpc_error (self , mock_insecure_channel , mock_device_service_stub ):
931+ """
932+ Test get_device_activation() when grpc error is not NOT_FOUND or UNAUTHENTICATED
933+ """
934+ # Mock the gRPC channel and login response
935+ mock_channel = Mock ()
936+ mock_insecure_channel .return_value = mock_channel
937+
938+ # Mock the get_device method to raise grpc.RpcError()
939+ mock_rpc_error = grpc .RpcError ()
940+ mock_rpc_error .code = lambda : grpc .StatusCode .INTERNAL
941+ mock_rpc_error .details = lambda : 'other'
942+
943+ # Mock the DeviceServiceStub
944+ mock_device_service_stub_instance = mock_device_service_stub .return_value
945+ mock_device_service_stub_instance .GetActivation .side_effect = mock_rpc_error
946+
947+ # Create a ChirpstackClient instance
948+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
949+
950+ # Mock the dev_eui
951+ mock_dev_eui = "mock_dev_eui"
952+
953+ result = client .get_device_activation (mock_dev_eui )
954+
955+ self .assertEqual (result , {})
956+
899957class TestListAggPagination (unittest .TestCase ):
900958
901959 @patch ('chirpstack_api_wrapper.api.DeviceServiceStub' )
0 commit comments