5252
5353USER_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v1/projects/mock-project-id'
5454
55+ TEST_TIMEOUT = 42
56+
5557
5658@pytest .fixture (scope = 'module' )
5759def user_mgt_app ():
@@ -60,6 +62,16 @@ def user_mgt_app():
6062 yield app
6163 firebase_admin .delete_app (app )
6264
65+ @pytest .fixture (scope = 'module' )
66+ def user_mgt_app_with_timeout ():
67+ app = firebase_admin .initialize_app (
68+ testutils .MockCredential (),
69+ name = 'userMgtTimeout' ,
70+ options = {'projectId' : 'mock-project-id' , 'httpTimeout' : TEST_TIMEOUT }
71+ )
72+ yield app
73+ firebase_admin .delete_app (app )
74+
6375def _instrument_user_manager (app , status , payload ):
6476 client = auth ._get_client (app )
6577 user_manager = client ._user_manager
@@ -105,14 +117,16 @@ def _check_user_record(user, expected_uid='testuser'):
105117 assert provider .provider_id == 'phone'
106118
107119
108- def _check_request (recorder , want_url , want_body = None ):
120+ def _check_request (recorder , want_url , want_body = None , want_timeout = None ):
109121 assert len (recorder ) == 1
110122 req = recorder [0 ]
111123 assert req .method == 'POST'
112124 assert req .url == '{0}{1}' .format (USER_MGT_URL_PREFIX , want_url )
113125 if want_body :
114126 body = json .loads (req .body .decode ())
115127 assert body == want_body
128+ if want_timeout :
129+ assert recorder [0 ]._extra_kwargs ['timeout' ] == pytest .approx (want_timeout , 0.001 )
116130
117131
118132class TestAuthServiceInitialization :
@@ -122,6 +136,11 @@ def test_default_timeout(self, user_mgt_app):
122136 user_manager = client ._user_manager
123137 assert user_manager .http_client .timeout == _http_client .DEFAULT_TIMEOUT_SECONDS
124138
139+ def test_app_options_timeout (self , user_mgt_app_with_timeout ):
140+ client = auth ._get_client (user_mgt_app_with_timeout )
141+ user_manager = client ._user_manager
142+ assert user_manager .http_client .timeout == TEST_TIMEOUT
143+
125144 def test_fail_on_no_project_id (self ):
126145 app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'userMgt2' )
127146 with pytest .raises (ValueError ):
@@ -225,6 +244,12 @@ def test_get_user(self, user_mgt_app):
225244 _check_user_record (auth .get_user ('testuser' , user_mgt_app ))
226245 _check_request (recorder , '/accounts:lookup' , {'localId' : ['testuser' ]})
227246
247+ def test_get_user_with_timeout (self , user_mgt_app_with_timeout ):
248+ _ , recorder = _instrument_user_manager (
249+ user_mgt_app_with_timeout , 200 , MOCK_GET_USER_RESPONSE )
250+ _check_user_record (auth .get_user ('testuser' , user_mgt_app_with_timeout ))
251+ _check_request (recorder , '/accounts:lookup' , {'localId' : ['testuser' ]}, TEST_TIMEOUT )
252+
228253 @pytest .mark .parametrize ('arg' , INVALID_STRINGS + ['not-an-email' ])
229254 def test_invalid_get_user_by_email (self , arg , user_mgt_app ):
230255 with pytest .raises (ValueError ):
0 commit comments