From 6cdcbfacd22d219234e2f8abaf42ea922786b434 Mon Sep 17 00:00:00 2001 From: Bruno Michetti Date: Mon, 1 Jun 2020 17:53:33 -0300 Subject: [PATCH 1/2] Make verify email browsable --- dj_rest_auth/registration/views.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dj_rest_auth/registration/views.py b/dj_rest_auth/registration/views.py index 937f327..dd5bc4c 100644 --- a/dj_rest_auth/registration/views.py +++ b/dj_rest_auth/registration/views.py @@ -19,7 +19,7 @@ from django.utils.decorators import method_decorator from django.utils.translation import ugettext_lazy as _ from django.views.decorators.debug import sensitive_post_parameters from rest_framework import status -from rest_framework.exceptions import NotFound +from rest_framework.exceptions import NotFound, MethodNotAllowed from rest_framework.generics import CreateAPIView, GenericAPIView, ListAPIView from rest_framework.permissions import AllowAny, IsAuthenticated from rest_framework.response import Response @@ -86,6 +86,9 @@ class VerifyEmailView(APIView, ConfirmEmailView): def get_serializer(self, *args, **kwargs): return VerifyEmailSerializer(*args, **kwargs) + def get(self, *args, **kwargs): + raise MethodNotAllowed('GET') + def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) From 9e8c98e89271d90ca486aa450a4b11bfaf2ea3c5 Mon Sep 17 00:00:00 2001 From: Bruno Michetti Date: Tue, 2 Jun 2020 13:25:00 -0300 Subject: [PATCH 2/2] Add test of browsable endpoint to maintain coverage --- dj_rest_auth/tests/test_api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dj_rest_auth/tests/test_api.py b/dj_rest_auth/tests/test_api.py index c53be66..2115415 100644 --- a/dj_rest_auth/tests/test_api.py +++ b/dj_rest_auth/tests/test_api.py @@ -466,6 +466,13 @@ class APIBasicTests(TestsMixin, TestCase): new_user = get_user_model().objects.latest('id') self.assertEqual(new_user.username, self.REGISTRATION_DATA['username']) + # test browsable endpoint + result = self.get( + self.verify_email_url + ) + self.assertEqual(result.status_code, 405) + self.assertEqual(result.json['detail'], 'Method "GET" not allowed.') + # email is not verified yet payload = { "username": self.USERNAME,