Skip to content
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

Return 401 responses on failed login #1442

Merged
merged 1 commit into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cadasta/accounts/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_unsuccessful_login(self):
"""The view should return a token to authenticate API calls"""
data = {'username': 'imagine71', 'password': 'iloveyoko78!'}
response = self.request(method='POST', post_data=data)
assert response.status_code == 400
assert response.status_code == 401

def test_login_with_unverified_email(self):
"""The view should return an error message if the User.verify_email_by
Expand All @@ -127,7 +127,7 @@ def test_login_with_unverified_email(self):
self.user.save()
data = {'username': 'imagine71', 'password': 'iloveyoko79!'}
response = self.request(method='POST', post_data=data, user=self.user)
assert response.status_code == 400
assert response.status_code == 401
assert 'auth_token' not in response.content
assert len(mail.outbox) == 1

Expand Down
4 changes: 2 additions & 2 deletions cadasta/accounts/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def post(self, request):
except ValidationError:
return Response(
data=serializer.errors,
status=status.HTTP_400_BAD_REQUEST,
status=status.HTTP_401_UNAUTHORIZED,
)
except EmailNotVerifiedError:
user = serializer.user
Expand All @@ -66,7 +66,7 @@ def post(self, request):

return Response(
data={'detail': _("The email has not been verified.")},
status=status.HTTP_400_BAD_REQUEST,
status=status.HTTP_401_UNAUTHORIZED,
)


Expand Down