Skip to content

Commit

Permalink
Merge pull request #1552 from gustavomm19/email-verification
Browse files Browse the repository at this point in the history
Fix status code in Email verification
  • Loading branch information
tommygonzaleza authored Feb 7, 2025
2 parents 73ffab9 + 3db9300 commit 5282798
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import pytest
from django.urls.base import reverse_lazy
from linked_services.django.actions import reset_app_cache
from rest_framework import status
from rest_framework.test import APIClient
from linked_services.django.actions import reset_app_cache

from breathecode.tests.mixins.breathecode_mixin.breathecode import Breathecode

Expand All @@ -24,10 +24,10 @@ def test_email_verification_no_user(bc: Breathecode, client: APIClient):
response = client.get(url)

json = response.json()
expected = {"detail": "email-not-found", "status_code": 400}
expected = {"detail": "email-not-found", "status_code": 404}

assert json == expected
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.status_code == status.HTTP_404_NOT_FOUND


def test_email_verification_not_validated(bc: Breathecode, client: APIClient):
Expand All @@ -39,10 +39,10 @@ def test_email_verification_not_validated(bc: Breathecode, client: APIClient):
response = client.get(url)

json = response.json()
expected = {"detail": "email-not-validated", "status_code": 400}
expected = {"detail": "email-not-validated", "status_code": 403}

assert json == expected
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.status_code == status.HTTP_403_FORBIDDEN


def test_email_verification(bc: Breathecode, client: APIClient):
Expand Down
6 changes: 5 additions & 1 deletion breathecode/authenticate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,26 +534,30 @@ class EmailVerification(APIView):
permission_classes = [AllowAny]

def get(self, request, email=None):
get_user_language(request)
lang = get_user_language(request)

invite = UserInvite.objects.filter(email=email).first()
user = User.objects.filter(email=email).first()
if user is None and invite is None:
raise ValidationException(
translation(
lang,
en="We could not find an account with this email",
es="No pudimos encontrar una dirección con este email",
),
slug="email-not-found",
code=404,
)

if invite is not None and not invite.is_email_validated:
raise ValidationException(
translation(
lang,
en="You need to validate your email first",
es="Debes validar tu email primero",
),
slug="email-not-validated",
code=403,
)

return Response(None, status=status.HTTP_204_NO_CONTENT)
Expand Down

0 comments on commit 5282798

Please sign in to comment.