-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
173 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
authors/apps/authentication/migrations/0002_user_social_id.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
authors/apps/authentication/tests/test_email_verification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""This module tests the login and registration of a user.""" | ||
from django.utils.encoding import force_text | ||
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode | ||
|
||
from django.test import TestCase | ||
|
||
from rest_framework.test import APIClient | ||
from rest_framework import status | ||
|
||
from authors.apps.authentication.models import User | ||
|
||
from authors.apps.authentication.tests.base_test import BaseTest | ||
|
||
|
||
class RegistrationAPIViewTestCase(TestCase, BaseTest): | ||
"""Test suite for the api views.""" | ||
|
||
def setUp(self): | ||
"""Define the test client and other test variables.""" | ||
BaseTest.__init__(self) | ||
self.client = APIClient() | ||
self.response = self.client.post( | ||
"/api/users/", | ||
self.user_data, | ||
format="json") | ||
self.user = User.objects.get(email=self.user_email) | ||
|
||
def test_wrong_token_on_confirm_registration(self): | ||
self.user1 = User.objects.get(email=self.user_email) | ||
self.uid = force_text(urlsafe_base64_encode(self.user1.email.encode("utf8"))) | ||
self.response = self.client.get( | ||
"/api/users/activate_account/{}/gfgcgffdxfd/".format(self.uid), | ||
format="json") | ||
self.assertEqual(403, self.response.status_code) | ||
self.assertEqual('Invalid token. Please log in again.', | ||
self.response.json()['detail']) | ||
|
||
def test_correct_token_on_confirm_registration(self): | ||
self.user1 = User.objects.get(email=self.user_email) | ||
self.uid = force_text(urlsafe_base64_encode(self.user1.email.encode("utf8"))) | ||
self.token = self.user1.token | ||
self.response = self.client.get( | ||
"/api/users/activate_account/{}/{}/".format(self.uid, self.token), | ||
format="json") | ||
self.assertEqual(200, self.response.status_code) | ||
self.assertEqual('Email verified, continue to login', | ||
self.response.json()['message']) | ||
self.response = self.client.get( | ||
"/api/users/activate_account/{}/{}/".format(self.uid, self.token), | ||
format="json") | ||
self.assertEqual('Email is already verified, continue to login', | ||
self.response.json()['message']) | ||
|
||
def test_api_Doesnt_login_an_unverified_user(self): | ||
"""Test the api can login a user.""" | ||
self.user.is_active = True | ||
self.user.is_email_verified = False | ||
self.user.save() | ||
self.response = self.client.post( | ||
"/api/users/login/", | ||
self.login_data, | ||
format="json") | ||
self.assertEqual(status.HTTP_400_BAD_REQUEST, self.response.status_code) | ||
self.assertEqual('An account with this email is not verified.', | ||
self.response.json()['errors']['error'][0]) | ||
|
||
def test_invalid_activation_link(self): | ||
self.user1 = User.objects.get(email=self.user_email) | ||
self.token = self.user1.token | ||
self.response = self.client.get( | ||
"/api/users/activate_account/fcfcfcafd/{}/".format(self.token), | ||
format="json") | ||
self.assertIn('error', self.response.data) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
from django.urls import path | ||
|
||
from .views import ( | ||
LoginAPIView, RegistrationAPIView, UserRetrieveUpdateAPIView, InvokePasswordResetAPIView | ||
) | ||
LoginAPIView, RegistrationAPIView, UserRetrieveUpdateAPIView, InvokePasswordResetAPIView, | ||
ActivateAccountView) | ||
|
||
urlpatterns = [ | ||
path('user/', UserRetrieveUpdateAPIView.as_view()), | ||
path('users/', RegistrationAPIView.as_view()), | ||
path('users/login/', LoginAPIView.as_view()), | ||
path('users/reset/password', InvokePasswordResetAPIView.as_view()), | ||
path('user/reset-password/<token>', UserRetrieveUpdateAPIView.as_view()) | ||
path('user/reset-password/<token>', UserRetrieveUpdateAPIView.as_view()), | ||
path('users/activate_account/<uid>/<token>/', | ||
ActivateAccountView.as_view(), name='activate_account'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.