@@ -497,6 +497,64 @@ def test_get_device_profile_unauthenticated_grpc_error(self, mock_sleep, mock_in
497497 # assertations
498498 self .assertEqual (device_profile_info , "mock_device_profile_info" )
499499
500+ @patch ('chirpstack_api_wrapper.api.DeviceProfileServiceStub' )
501+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
502+ def test_get_device_profile_not_found_grpc_error (self , mock_insecure_channel , mock_device_profile_service_stub ):
503+ """
504+ Test get_device_profile() when grpc error is raised for NOT_FOUND
505+ """
506+ # Mock the gRPC channel and login response
507+ mock_channel = Mock ()
508+ mock_insecure_channel .return_value = mock_channel
509+
510+ # Mock the get_device method to raise grpc.RpcError()
511+ mock_rpc_error = grpc .RpcError ()
512+ mock_rpc_error .code = lambda : grpc .StatusCode .NOT_FOUND
513+ mock_rpc_error .details = lambda : 'Object does not exist'
514+
515+ # Mock the DeviceProfileServiceStub
516+ mock_device_profile_service_stub_instance = mock_device_profile_service_stub .return_value
517+ mock_device_profile_service_stub_instance .Get .side_effect = mock_rpc_error
518+
519+ # Create a ChirpstackClient instance
520+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
521+
522+ # Mock the device profile ID
523+ mock_device_profile_id = "mock_device_profile_id"
524+
525+ result = client .get_device_profile (mock_device_profile_id )
526+
527+ self .assertEqual (result , {})
528+
529+ @patch ('chirpstack_api_wrapper.api.DeviceProfileServiceStub' )
530+ @patch ('chirpstack_api_wrapper.grpc.insecure_channel' )
531+ def test_get_device_other_grpc_error (self , mock_insecure_channel , mock_device_profile_service_stub ):
532+ """
533+ Test get_device_profile() when grpc error is not NOT_FOUND or UNAUTHENTICATED
534+ """
535+ # Mock the gRPC channel and login response
536+ mock_channel = Mock ()
537+ mock_insecure_channel .return_value = mock_channel
538+
539+ # Mock the get_device method to raise grpc.RpcError()
540+ mock_rpc_error = grpc .RpcError ()
541+ mock_rpc_error .code = lambda : grpc .StatusCode .INTERNAL
542+ mock_rpc_error .details = lambda : 'other'
543+
544+ # Mock the DeviceProfileServiceStub
545+ mock_device_profile_service_stub_instance = mock_device_profile_service_stub .return_value
546+ mock_device_profile_service_stub_instance .Get .side_effect = mock_rpc_error
547+
548+ # Create a ChirpstackClient instance
549+ client = ChirpstackClient (CHIRPSTACK_ACT_EMAIL , CHIRPSTACK_ACT_PASSWORD , CHIRPSTACK_API_INTERFACE )
550+
551+ # Mock the device profile ID
552+ mock_device_profile_id = "mock_device_profile_id"
553+
554+ result = client .get_device_profile (mock_device_profile_id )
555+
556+ self .assertEqual (result , {})
557+
500558class TestGetDeviceAppKey (unittest .TestCase ):
501559
502560 @patch ('chirpstack_api_wrapper.api.DeviceServiceStub' )
0 commit comments