github: Return '' when name is None.

This commit is contained in:
Umair Khan 2017-03-09 13:45:21 +05:00 committed by Tim Abbott
parent e44e58f6d5
commit 0d296afa54
2 changed files with 14 additions and 1 deletions

View File

@ -358,6 +358,10 @@ class GitHubAuthBackendTest(ZulipTestCase):
# type: () -> None
self.assertEqual(self.backend.get_full_name(), '')
def test_full_name_with_none(self):
# type: () -> None
self.assertEqual(self.backend.get_full_name(response={'email': None}), '')
def test_github_backend_do_auth_without_subdomains(self):
# type: () -> None
with mock.patch('social_core.backends.github.GithubOAuth2.do_auth',

View File

@ -419,11 +419,20 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
def get_full_name(self, *args, **kwargs):
# type: (*Any, **Any) -> Text
# In case of any error return an empty string. Name is used by
# the registration page to pre-populate the name field. However,
# if it is not supplied, our registration process will make sure
# that the user enters a valid name.
try:
return kwargs['response']['name']
name = kwargs['response']['name']
except KeyError:
name = ''
if name is None:
return ''
return name
def do_auth(self, *args, **kwargs):
# type: (*Any, **Any) -> Optional[HttpResponse]
kwargs['return_data'] = {}