Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/breatheco-de/apiv2 i…
Browse files Browse the repository at this point in the history
…nto development
  • Loading branch information
jefer94 committed Feb 7, 2025
2 parents a97e353 + f4b6553 commit fab38d8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
55 changes: 55 additions & 0 deletions breathecode/authenticate/tests/urls/v1/tests_email_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Test cases for /emailvalidation
"""

import pytest
from django.urls.base import reverse_lazy
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


@pytest.fixture(autouse=True)
def setup(db):
reset_app_cache()
yield


def test_email_verification_no_user(bc: Breathecode, client: APIClient):
email = "[email protected]"

url = reverse_lazy("authenticate:email_verification", kwargs={"email": email})
response = client.get(url)

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

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


def test_email_verification_not_validated(bc: Breathecode, client: APIClient):
email = "[email protected]"

model = bc.database.create(user={"email": email}, user_invite={"email": email, "is_email_validated": False})

url = reverse_lazy("authenticate:email_verification", kwargs={"email": email})
response = client.get(url)

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

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


def test_email_verification(bc: Breathecode, client: APIClient):
email = "[email protected]"
model = bc.database.create(user={"email": email})

url = reverse_lazy("authenticate:email_verification", kwargs={"email": email})
response = client.get(url)

assert response.status_code == status.HTTP_204_NO_CONTENT
2 changes: 2 additions & 0 deletions breathecode/authenticate/urls/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
UserMeView,
UserSettingsView,
WaitingListView,
EmailVerification,
get_facebook_token,
get_github_token,
get_google_token,
Expand Down Expand Up @@ -89,6 +90,7 @@

app_name = "authenticate"
urlpatterns = [
path("emailverification/<str:email>", EmailVerification.as_view(), name="email_verification"),
path("confirmation/<str:token>", ConfirmEmailView.as_view(), name="confirmation_token"),
path("invite/resend/<int:invite_id>", ResendInviteView.as_view(), name="invite_resend_id"),
path("member/invite/resend/<int:invite_id>", AcademyInviteView.as_view(), name="member_invite_resend_id"),
Expand Down
29 changes: 29 additions & 0 deletions breathecode/authenticate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,35 @@ def put(self, request, profile_academy_id=None, new_status=None):
return Response(serializer.data)


class EmailVerification(APIView):
permission_classes = [AllowAny]

def get(self, request, email=None):
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(
en="We could not find an account with this email",
es="No pudimos encontrar una dirección con este email",
),
slug="email-not-found",
)

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

return Response(None, status=status.HTTP_204_NO_CONTENT)


class ConfirmEmailView(APIView):
permission_classes = [AllowAny]

Expand Down

0 comments on commit fab38d8

Please sign in to comment.