11# Copyright (c) The Dapr Authors.
22# Licensed under the MIT License.
33
4- from unittest .mock import ANY , patch
4+ from unittest .mock import patch
55
66from durabletask .aio .client import AsyncTaskHubGrpcClient
77from durabletask .aio .internal .grpc_interceptor import DefaultClientInterceptorImpl
1616def test_get_grpc_aio_channel_insecure ():
1717 with patch ("durabletask.aio.internal.shared.grpc_aio.insecure_channel" ) as mock_channel :
1818 get_grpc_aio_channel (HOST_ADDRESS , False , interceptors = INTERCEPTORS_AIO )
19- mock_channel .assert_called_once_with (HOST_ADDRESS , interceptors = INTERCEPTORS_AIO )
19+ args , kwargs = mock_channel .call_args
20+ assert args [0 ] == HOST_ADDRESS
21+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
22+ assert "options" in kwargs and kwargs ["options" ] is None
2023
2124
2225def test_get_grpc_aio_channel_secure ():
@@ -25,23 +28,29 @@ def test_get_grpc_aio_channel_secure():
2528 patch ("grpc.ssl_channel_credentials" ) as mock_credentials ,
2629 ):
2730 get_grpc_aio_channel (HOST_ADDRESS , True , interceptors = INTERCEPTORS_AIO )
28- mock_channel .assert_called_once_with (
29- HOST_ADDRESS , mock_credentials .return_value , interceptors = INTERCEPTORS_AIO
30- )
31+ args , kwargs = mock_channel .call_args
32+ assert args [0 ] == HOST_ADDRESS
33+ assert args [1 ] == mock_credentials .return_value
34+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
35+ assert "options" in kwargs and kwargs ["options" ] is None
3136
3237
3338def test_get_grpc_aio_channel_default_host_address ():
3439 with patch ("durabletask.aio.internal.shared.grpc_aio.insecure_channel" ) as mock_channel :
3540 get_grpc_aio_channel (None , False , interceptors = INTERCEPTORS_AIO )
36- mock_channel .assert_called_once_with (
37- get_default_host_address (), interceptors = INTERCEPTORS_AIO
38- )
41+ args , kwargs = mock_channel .call_args
42+ assert args [0 ] == get_default_host_address ()
43+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
44+ assert "options" in kwargs and kwargs ["options" ] is None
3945
4046
4147def test_get_grpc_aio_channel_with_interceptors ():
4248 with patch ("durabletask.aio.internal.shared.grpc_aio.insecure_channel" ) as mock_channel :
4349 get_grpc_aio_channel (HOST_ADDRESS , False , interceptors = INTERCEPTORS_AIO )
44- mock_channel .assert_called_once_with (HOST_ADDRESS , interceptors = INTERCEPTORS_AIO )
50+ args , kwargs = mock_channel .call_args
51+ assert args [0 ] == HOST_ADDRESS
52+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
53+ assert "options" in kwargs and kwargs ["options" ] is None
4554
4655 # Capture and check the arguments passed to insecure_channel()
4756 args , kwargs = mock_channel .call_args
@@ -61,43 +70,73 @@ def test_grpc_aio_channel_with_host_name_protocol_stripping():
6170
6271 prefix = "grpc://"
6372 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
64- mock_insecure_channel .assert_called_with (host_name , interceptors = INTERCEPTORS_AIO )
73+ args , kwargs = mock_insecure_channel .call_args
74+ assert args [0 ] == host_name
75+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
76+ assert "options" in kwargs and kwargs ["options" ] is None
6577
6678 prefix = "http://"
6779 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
68- mock_insecure_channel .assert_called_with (host_name , interceptors = INTERCEPTORS_AIO )
80+ args , kwargs = mock_insecure_channel .call_args
81+ assert args [0 ] == host_name
82+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
83+ assert "options" in kwargs and kwargs ["options" ] is None
6984
7085 prefix = "HTTP://"
7186 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
72- mock_insecure_channel .assert_called_with (host_name , interceptors = INTERCEPTORS_AIO )
87+ args , kwargs = mock_insecure_channel .call_args
88+ assert args [0 ] == host_name
89+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
90+ assert "options" in kwargs and kwargs ["options" ] is None
7391
7492 prefix = "GRPC://"
7593 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
76- mock_insecure_channel .assert_called_with (host_name , interceptors = INTERCEPTORS_AIO )
94+ args , kwargs = mock_insecure_channel .call_args
95+ assert args [0 ] == host_name
96+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
97+ assert "options" in kwargs and kwargs ["options" ] is None
7798
7899 prefix = ""
79100 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
80- mock_insecure_channel .assert_called_with (host_name , interceptors = INTERCEPTORS_AIO )
101+ args , kwargs = mock_insecure_channel .call_args
102+ assert args [0 ] == host_name
103+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
104+ assert "options" in kwargs and kwargs ["options" ] is None
81105
82106 prefix = "grpcs://"
83107 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
84- mock_secure_channel .assert_called_with (host_name , ANY , interceptors = INTERCEPTORS_AIO )
108+ args , kwargs = mock_secure_channel .call_args
109+ assert args [0 ] == host_name
110+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
111+ assert "options" in kwargs and kwargs ["options" ] is None
85112
86113 prefix = "https://"
87114 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
88- mock_secure_channel .assert_called_with (host_name , ANY , interceptors = INTERCEPTORS_AIO )
115+ args , kwargs = mock_secure_channel .call_args
116+ assert args [0 ] == host_name
117+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
118+ assert "options" in kwargs and kwargs ["options" ] is None
89119
90120 prefix = "HTTPS://"
91121 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
92- mock_secure_channel .assert_called_with (host_name , ANY , interceptors = INTERCEPTORS_AIO )
122+ args , kwargs = mock_secure_channel .call_args
123+ assert args [0 ] == host_name
124+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
125+ assert "options" in kwargs and kwargs ["options" ] is None
93126
94127 prefix = "GRPCS://"
95128 get_grpc_aio_channel (prefix + host_name , interceptors = INTERCEPTORS_AIO )
96- mock_secure_channel .assert_called_with (host_name , ANY , interceptors = INTERCEPTORS_AIO )
129+ args , kwargs = mock_secure_channel .call_args
130+ assert args [0 ] == host_name
131+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
132+ assert "options" in kwargs and kwargs ["options" ] is None
97133
98134 prefix = ""
99135 get_grpc_aio_channel (prefix + host_name , True , interceptors = INTERCEPTORS_AIO )
100- mock_secure_channel .assert_called_with (host_name , ANY , interceptors = INTERCEPTORS_AIO )
136+ args , kwargs = mock_secure_channel .call_args
137+ assert args [0 ] == host_name
138+ assert kwargs .get ("interceptors" ) == INTERCEPTORS_AIO
139+ assert "options" in kwargs and kwargs ["options" ] is None
101140
102141
103142def test_async_client_construct_with_metadata ():
0 commit comments