Skip to content

Commit f89471f

Browse files
committed
pep8 cleanups
1 parent 945008d commit f89471f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

rest_auth/registration/serializers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,19 @@ def validate(self, attrs):
116116
# with the same email address: raise an exception.
117117
# This needs to be handled in the frontend. We can not just
118118
# link up the accounts due to security constraints
119-
if(allauth_settings.UNIQUE_EMAIL):
119+
if allauth_settings.UNIQUE_EMAIL:
120120
# Do we have an account already with this email address?
121-
existing_account = get_user_model().objects.filter(
121+
account_exists = get_user_model().objects.filter(
122122
email=login.user.email,
123-
).count()
124-
if(existing_account != 0):
125-
# There is an account already
123+
).exists()
124+
if account_exists:
126125
raise serializers.ValidationError(
127-
_("A user is already registered with this e-mail address."))
126+
_("User is already registered with this e-mail address.")
127+
)
128128

129129
login.lookup()
130130
login.save(request, connect=True)
131+
131132
attrs['user'] = login.account.user
132133

133134
return attrs

rest_auth/tests/test_social.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def test_twitter_social_auth_no_adapter(self):
225225
REST_SESSION_LOGIN=False,
226226
ACCOUNT_EMAIL_CONFIRMATION_HMAC=False
227227
)
228-
def test_edge_case(self):
228+
def test_email_clash_with_existing_account(self):
229229
resp_body = {
230230
"id": "123123123123",
231231
"first_name": "John",
@@ -251,6 +251,8 @@ def test_edge_case(self):
251251

252252
# test empty payload
253253
self.post(self.register_url, data={}, status_code=400)
254+
255+
# register user and send email confirmation
254256
self.post(
255257
self.register_url,
256258
data=self.REGISTRATION_DATA,
@@ -271,16 +273,11 @@ def test_edge_case(self):
271273
self._login()
272274
self._logout()
273275

276+
# fb log in with already existing email
274277
payload = {
275278
'access_token': 'abc123'
276279
}
277-
278-
# You should not have access to an account created through register
279-
# by loging in through FB with an account that has the same
280-
# email address.
281280
self.post(self.fb_login_url, data=payload, status_code=400)
282-
# self.post(self.fb_login_url, data=payload, status_code=200)
283-
# self.assertIn('key', self.response.json.keys())
284281

285282
@responses.activate
286283
@override_settings(

0 commit comments

Comments
 (0)