Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Feb 6, 2025
1 parent 118b98c commit 490ac35
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
64 changes: 64 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,64 @@
"""
Test cases for /emailvalidation
"""

import re
import urllib
from unittest import mock

import capyc.pytest as capy
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

import staging.pytest as staging
from breathecode.authenticate.tests.mocks.mocks import FakeResponse
from breathecode.tests.mixins.breathecode_mixin.breathecode import Breathecode

from ...mocks import GithubRequestsMock


@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
4 changes: 2 additions & 2 deletions breathecode/authenticate/urls/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
UserMeView,
UserSettingsView,
WaitingListView,
EmailConfirmation,
EmailVerification,
get_facebook_token,
get_github_token,
get_google_token,
Expand Down Expand Up @@ -90,7 +90,7 @@

app_name = "authenticate"
urlpatterns = [
path("emailverification/<str:email>", EmailConfirmation.as_view(), name="email_confirmation"),
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
2 changes: 1 addition & 1 deletion breathecode/authenticate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def put(self, request, profile_academy_id=None, new_status=None):
return Response(serializer.data)


class EmailConfirmation(APIView):
class EmailVerification(APIView):
permission_classes = [AllowAny]

def get(self, request, email=None):
Expand Down

0 comments on commit 490ac35

Please sign in to comment.