|
21 | 21 |
|
22 | 22 | import firebase_admin
|
23 | 23 | from firebase_admin import auth
|
| 24 | +from firebase_admin import exceptions |
24 | 25 | from firebase_admin import _auth_utils
|
25 | 26 | from firebase_admin import _user_import
|
26 | 27 | from firebase_admin import _user_mgt
|
@@ -211,30 +212,79 @@ def test_get_user_by_phone(self, user_mgt_app):
|
211 | 212 |
|
212 | 213 | def test_get_user_non_existing(self, user_mgt_app):
|
213 | 214 | _instrument_user_manager(user_mgt_app, 200, '{"users":[]}')
|
214 |
| - with pytest.raises(auth.AuthError) as excinfo: |
| 215 | + with pytest.raises(auth.UserNotFoundError) as excinfo: |
215 | 216 | auth.get_user('nonexistentuser', user_mgt_app)
|
216 |
| - assert excinfo.value.code == _user_mgt.USER_NOT_FOUND_ERROR |
| 217 | + error_msg = 'No user record found for the provided user ID: nonexistentuser.' |
| 218 | + assert excinfo.value.code == exceptions.NOT_FOUND |
| 219 | + assert str(excinfo.value) == error_msg |
| 220 | + assert excinfo.value.http_response is not None |
| 221 | + assert excinfo.value.cause is None |
| 222 | + |
| 223 | + def test_get_user_by_email_non_existing(self, user_mgt_app): |
| 224 | + _instrument_user_manager(user_mgt_app, 200, '{"users":[]}') |
| 225 | + with pytest.raises(auth.UserNotFoundError) as excinfo: |
| 226 | + auth.get_user_by_email('nonexistent@user', user_mgt_app) |
| 227 | + error_msg = 'No user record found for the provided email: nonexistent@user.' |
| 228 | + assert excinfo.value.code == exceptions.NOT_FOUND |
| 229 | + assert str(excinfo.value) == error_msg |
| 230 | + assert excinfo.value.http_response is not None |
| 231 | + assert excinfo.value.cause is None |
| 232 | + |
| 233 | + def test_get_user_by_phone_non_existing(self, user_mgt_app): |
| 234 | + _instrument_user_manager(user_mgt_app, 200, '{"users":[]}') |
| 235 | + with pytest.raises(auth.UserNotFoundError) as excinfo: |
| 236 | + auth.get_user_by_phone_number('+1234567890', user_mgt_app) |
| 237 | + error_msg = 'No user record found for the provided phone number: +1234567890.' |
| 238 | + assert excinfo.value.code == exceptions.NOT_FOUND |
| 239 | + assert str(excinfo.value) == error_msg |
| 240 | + assert excinfo.value.http_response is not None |
| 241 | + assert excinfo.value.cause is None |
217 | 242 |
|
218 | 243 | def test_get_user_http_error(self, user_mgt_app):
|
219 |
| - _instrument_user_manager(user_mgt_app, 500, '{"error":"test"}') |
220 |
| - with pytest.raises(auth.AuthError) as excinfo: |
| 244 | + _instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "USER_NOT_FOUND"}}') |
| 245 | + with pytest.raises(auth.UserNotFoundError) as excinfo: |
221 | 246 | auth.get_user('testuser', user_mgt_app)
|
222 |
| - assert excinfo.value.code == _user_mgt.INTERNAL_ERROR |
223 |
| - assert '{"error":"test"}' in str(excinfo.value) |
| 247 | + error_msg = 'No user record found for the given identifier (USER_NOT_FOUND).' |
| 248 | + assert excinfo.value.code == exceptions.NOT_FOUND |
| 249 | + assert str(excinfo.value) == error_msg |
| 250 | + assert excinfo.value.http_response is not None |
| 251 | + assert excinfo.value.cause is not None |
| 252 | + |
| 253 | + def test_get_user_http_error_unexpected_code(self, user_mgt_app): |
| 254 | + _instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "UNEXPECTED_CODE"}}') |
| 255 | + with pytest.raises(exceptions.InternalError) as excinfo: |
| 256 | + auth.get_user('testuser', user_mgt_app) |
| 257 | + assert str(excinfo.value) == 'Error while calling Auth service (UNEXPECTED_CODE).' |
| 258 | + assert excinfo.value.http_response is not None |
| 259 | + assert excinfo.value.cause is not None |
| 260 | + |
| 261 | + def test_get_user_http_error_malformed_response(self, user_mgt_app): |
| 262 | + _instrument_user_manager(user_mgt_app, 500, '{"error": "UNEXPECTED_CODE"}') |
| 263 | + with pytest.raises(exceptions.InternalError) as excinfo: |
| 264 | + auth.get_user('testuser', user_mgt_app) |
| 265 | + assert str(excinfo.value) == 'Unexpected error response: {"error": "UNEXPECTED_CODE"}' |
| 266 | + assert excinfo.value.http_response is not None |
| 267 | + assert excinfo.value.cause is not None |
224 | 268 |
|
225 | 269 | def test_get_user_by_email_http_error(self, user_mgt_app):
|
226 |
| - _instrument_user_manager(user_mgt_app, 500, '{"error":"test"}') |
227 |
| - with pytest.raises(auth.AuthError) as excinfo: |
| 270 | + _instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "USER_NOT_FOUND"}}') |
| 271 | + with pytest.raises(auth.UserNotFoundError) as excinfo: |
228 | 272 | auth. get_user_by_email( '[email protected]', user_mgt_app)
|
229 |
| - assert excinfo.value.code == _user_mgt.INTERNAL_ERROR |
230 |
| - assert '{"error":"test"}' in str(excinfo.value) |
| 273 | + error_msg = 'No user record found for the given identifier (USER_NOT_FOUND).' |
| 274 | + assert excinfo.value.code == exceptions.NOT_FOUND |
| 275 | + assert str(excinfo.value) == error_msg |
| 276 | + assert excinfo.value.http_response is not None |
| 277 | + assert excinfo.value.cause is not None |
231 | 278 |
|
232 | 279 | def test_get_user_by_phone_http_error(self, user_mgt_app):
|
233 |
| - _instrument_user_manager(user_mgt_app, 500, '{"error":"test"}') |
234 |
| - with pytest.raises(auth.AuthError) as excinfo: |
| 280 | + _instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "USER_NOT_FOUND"}}') |
| 281 | + with pytest.raises(auth.UserNotFoundError) as excinfo: |
235 | 282 | auth.get_user_by_phone_number('+1234567890', user_mgt_app)
|
236 |
| - assert excinfo.value.code == _user_mgt.INTERNAL_ERROR |
237 |
| - assert '{"error":"test"}' in str(excinfo.value) |
| 283 | + error_msg = 'No user record found for the given identifier (USER_NOT_FOUND).' |
| 284 | + assert excinfo.value.code == exceptions.NOT_FOUND |
| 285 | + assert str(excinfo.value) == error_msg |
| 286 | + assert excinfo.value.http_response is not None |
| 287 | + assert excinfo.value.cause is not None |
238 | 288 |
|
239 | 289 |
|
240 | 290 | class TestCreateUser(object):
|
@@ -718,6 +768,7 @@ def test_invalid_args(self, arg):
|
718 | 768 | with pytest.raises(ValueError):
|
719 | 769 | auth.UserMetadata(**arg)
|
720 | 770 |
|
| 771 | + |
721 | 772 | class TestImportUserRecord(object):
|
722 | 773 |
|
723 | 774 | _INVALID_USERS = (
|
@@ -1003,6 +1054,7 @@ def test_revoke_refresh_tokens(self, user_mgt_app):
|
1003 | 1054 | assert int(request['validSince']) >= int(before_time)
|
1004 | 1055 | assert int(request['validSince']) <= int(after_time)
|
1005 | 1056 |
|
| 1057 | + |
1006 | 1058 | class TestActionCodeSetting(object):
|
1007 | 1059 |
|
1008 | 1060 | def test_valid_data(self):
|
@@ -1047,6 +1099,7 @@ def test_encode_action_code_bad_data(self):
|
1047 | 1099 | with pytest.raises(AttributeError):
|
1048 | 1100 | _user_mgt.encode_action_code_settings({"foo":"bar"})
|
1049 | 1101 |
|
| 1102 | + |
1050 | 1103 | class TestGenerateEmailActionLink(object):
|
1051 | 1104 |
|
1052 | 1105 | def test_email_verification_no_settings(self, user_mgt_app):
|
|
0 commit comments