52
52
53
53
USER_MGT_URL_PREFIX = 'https://identitytoolkit.googleapis.com/v1/projects/mock-project-id'
54
54
55
+ TEST_TIMEOUT = 42
56
+
55
57
56
58
@pytest .fixture (scope = 'module' )
57
59
def user_mgt_app ():
@@ -60,6 +62,16 @@ def user_mgt_app():
60
62
yield app
61
63
firebase_admin .delete_app (app )
62
64
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
+
63
75
def _instrument_user_manager (app , status , payload ):
64
76
client = auth ._get_client (app )
65
77
user_manager = client ._user_manager
@@ -105,14 +117,16 @@ def _check_user_record(user, expected_uid='testuser'):
105
117
assert provider .provider_id == 'phone'
106
118
107
119
108
- def _check_request (recorder , want_url , want_body = None ):
120
+ def _check_request (recorder , want_url , want_body = None , want_timeout = None ):
109
121
assert len (recorder ) == 1
110
122
req = recorder [0 ]
111
123
assert req .method == 'POST'
112
124
assert req .url == '{0}{1}' .format (USER_MGT_URL_PREFIX , want_url )
113
125
if want_body :
114
126
body = json .loads (req .body .decode ())
115
127
assert body == want_body
128
+ if want_timeout :
129
+ assert recorder [0 ]._extra_kwargs ['timeout' ] == pytest .approx (want_timeout , 0.001 )
116
130
117
131
118
132
class TestAuthServiceInitialization :
@@ -122,6 +136,11 @@ def test_default_timeout(self, user_mgt_app):
122
136
user_manager = client ._user_manager
123
137
assert user_manager .http_client .timeout == _http_client .DEFAULT_TIMEOUT_SECONDS
124
138
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
+
125
144
def test_fail_on_no_project_id (self ):
126
145
app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'userMgt2' )
127
146
with pytest .raises (ValueError ):
@@ -225,6 +244,12 @@ def test_get_user(self, user_mgt_app):
225
244
_check_user_record (auth .get_user ('testuser' , user_mgt_app ))
226
245
_check_request (recorder , '/accounts:lookup' , {'localId' : ['testuser' ]})
227
246
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
+
228
253
@pytest .mark .parametrize ('arg' , INVALID_STRINGS + ['not-an-email' ])
229
254
def test_invalid_get_user_by_email (self , arg , user_mgt_app ):
230
255
with pytest .raises (ValueError ):
0 commit comments