-
Notifications
You must be signed in to change notification settings - Fork 339
Introducing UserNotFoundError type #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import google.oauth2.credentials | ||
from google.auth import transport | ||
|
||
|
||
_verify_token_url = 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken' | ||
_verify_password_url = 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword' | ||
_password_reset_url = 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/resetPassword' | ||
|
@@ -135,14 +136,16 @@ def test_session_cookie_error(): | |
auth.create_session_cookie('not.a.token', expires_in=expires_in) | ||
|
||
def test_get_non_existing_user(): | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user('non.existing') | ||
assert 'USER_NOT_FOUND_ERROR' in str(excinfo.value.code) | ||
assert str(excinfo.value) == 'No user record found for the provided user ID: non.existing.' | ||
|
||
def test_get_non_existing_user_by_email(): | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user_by_email('[email protected]') | ||
assert 'USER_NOT_FOUND_ERROR' in str(excinfo.value.code) | ||
error_msg = ('No user record found for the provided email: ' | ||
'[email protected].') | ||
assert str(excinfo.value) == error_msg | ||
|
||
def test_update_non_existing_user(): | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
import firebase_admin | ||
from firebase_admin import auth | ||
from firebase_admin import exceptions | ||
from firebase_admin import _auth_utils | ||
from firebase_admin import _user_import | ||
from firebase_admin import _user_mgt | ||
|
@@ -211,30 +212,79 @@ def test_get_user_by_phone(self, user_mgt_app): | |
|
||
def test_get_user_non_existing(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 200, '{"users":[]}') | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user('nonexistentuser', user_mgt_app) | ||
assert excinfo.value.code == _user_mgt.USER_NOT_FOUND_ERROR | ||
error_msg = 'No user record found for the provided user ID: nonexistentuser.' | ||
assert excinfo.value.code == exceptions.NOT_FOUND | ||
assert str(excinfo.value) == error_msg | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is None | ||
|
||
def test_get_user_by_email_non_existing(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 200, '{"users":[]}') | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user_by_email('nonexistent@user', user_mgt_app) | ||
error_msg = 'No user record found for the provided email: nonexistent@user.' | ||
assert excinfo.value.code == exceptions.NOT_FOUND | ||
assert str(excinfo.value) == error_msg | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is None | ||
|
||
def test_get_user_by_phone_non_existing(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 200, '{"users":[]}') | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user_by_phone_number('+1234567890', user_mgt_app) | ||
error_msg = 'No user record found for the provided phone number: +1234567890.' | ||
assert excinfo.value.code == exceptions.NOT_FOUND | ||
assert str(excinfo.value) == error_msg | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is None | ||
|
||
def test_get_user_http_error(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":"test"}') | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "USER_NOT_FOUND"}}') | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user('testuser', user_mgt_app) | ||
assert excinfo.value.code == _user_mgt.INTERNAL_ERROR | ||
assert '{"error":"test"}' in str(excinfo.value) | ||
error_msg = 'No user record found for the given identifier (USER_NOT_FOUND).' | ||
assert excinfo.value.code == exceptions.NOT_FOUND | ||
assert str(excinfo.value) == error_msg | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is not None | ||
|
||
def test_get_user_http_error_unexpected_code(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "UNEXPECTED_CODE"}}') | ||
with pytest.raises(exceptions.InternalError) as excinfo: | ||
auth.get_user('testuser', user_mgt_app) | ||
assert str(excinfo.value) == 'Error while calling Auth service (UNEXPECTED_CODE).' | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is not None | ||
|
||
def test_get_user_http_error_malformed_response(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 500, '{"error": "UNEXPECTED_CODE"}') | ||
with pytest.raises(exceptions.InternalError) as excinfo: | ||
auth.get_user('testuser', user_mgt_app) | ||
assert str(excinfo.value) == 'Unexpected error response: {"error": "UNEXPECTED_CODE"}' | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is not None | ||
|
||
def test_get_user_by_email_http_error(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":"test"}') | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "USER_NOT_FOUND"}}') | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user_by_email('[email protected]', user_mgt_app) | ||
assert excinfo.value.code == _user_mgt.INTERNAL_ERROR | ||
assert '{"error":"test"}' in str(excinfo.value) | ||
error_msg = 'No user record found for the given identifier (USER_NOT_FOUND).' | ||
assert excinfo.value.code == exceptions.NOT_FOUND | ||
assert str(excinfo.value) == error_msg | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is not None | ||
|
||
def test_get_user_by_phone_http_error(self, user_mgt_app): | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":"test"}') | ||
with pytest.raises(auth.AuthError) as excinfo: | ||
_instrument_user_manager(user_mgt_app, 500, '{"error":{"message": "USER_NOT_FOUND"}}') | ||
with pytest.raises(auth.UserNotFoundError) as excinfo: | ||
auth.get_user_by_phone_number('+1234567890', user_mgt_app) | ||
assert excinfo.value.code == _user_mgt.INTERNAL_ERROR | ||
assert '{"error":"test"}' in str(excinfo.value) | ||
error_msg = 'No user record found for the given identifier (USER_NOT_FOUND).' | ||
assert excinfo.value.code == exceptions.NOT_FOUND | ||
assert str(excinfo.value) == error_msg | ||
assert excinfo.value.http_response is not None | ||
assert excinfo.value.cause is not None | ||
|
||
|
||
class TestCreateUser(object): | ||
|
@@ -718,6 +768,7 @@ def test_invalid_args(self, arg): | |
with pytest.raises(ValueError): | ||
auth.UserMetadata(**arg) | ||
|
||
|
||
class TestImportUserRecord(object): | ||
|
||
_INVALID_USERS = ( | ||
|
@@ -1003,6 +1054,7 @@ def test_revoke_refresh_tokens(self, user_mgt_app): | |
assert int(request['validSince']) >= int(before_time) | ||
assert int(request['validSince']) <= int(after_time) | ||
|
||
|
||
class TestActionCodeSetting(object): | ||
|
||
def test_valid_data(self): | ||
|
@@ -1047,6 +1099,7 @@ def test_encode_action_code_bad_data(self): | |
with pytest.raises(AttributeError): | ||
_user_mgt.encode_action_code_settings({"foo":"bar"}) | ||
|
||
|
||
class TestGenerateEmailActionLink(object): | ||
|
||
def test_email_verification_no_settings(self, user_mgt_app): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but this doesn't seem very pythonic to me checking
isinstance
. Is it ever valid forerror_dict
to not be 'None' and also not support theget
method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the server response format doesn't change we should be fine. I'm being a little too defensive here. In general, it's not clear what the Auth response format would be in the event of a major outage or similar issue.