-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Email Verification) Email HTML
- Created html template to be sent to the user - Created test for email verification [Delivers #162948909]
- Loading branch information
Showing
4 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,102 @@ | ||
# System libraries | ||
import json | ||
|
||
# Third Party Libraries | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient, APITestCase | ||
from rest_framework.views import status | ||
|
||
|
||
class UserRegistrationTest(APITestCase): | ||
""" | ||
Holds all user registration | ||
""" | ||
|
||
def setUp(self): | ||
"""The setup method""" | ||
self.register_url = reverse("auth:register") | ||
self.client = APIClient() | ||
|
||
# Define the json data | ||
# Data with valid user credentials | ||
self.valid_user_credentials = { | ||
"user": { | ||
"username": "Wachira", | ||
"email": "ewachira254@gmail.com", | ||
"password": "@Wachira254" | ||
} | ||
} | ||
# Data lacking a field <username> | ||
self.missing_field_credentials = { | ||
"user": { | ||
"username": "", | ||
"email": "ewachira254@gmail.com", | ||
"password": "@Wachira254" | ||
} | ||
} | ||
# Data lacking with no username | ||
self.none_field_credentials = { | ||
"user": { | ||
"email": "ewachira254@gmail.com", | ||
"password": "@Wachira254" | ||
} | ||
} | ||
# Data lacking with no email | ||
self.none_field_credentials_2 = { | ||
"user": { | ||
"username":"isasnack", | ||
"password": "@Wachira254" | ||
} | ||
} | ||
# Data with invalid data <password> | ||
self.invalid_field_credentials = { | ||
"user": { | ||
"username": "Wachira", | ||
"email": "ewachira254@gmail.com", | ||
"password": "123456" | ||
} | ||
} | ||
|
||
self.invalid_username = { | ||
"user": { | ||
"username": "W", | ||
"email": "ewachira254@gmail.com", | ||
"password": "123456" | ||
} | ||
} | ||
|
||
self.short_password = { | ||
"user": { | ||
"username": "Wachira", | ||
"email": "ewachira254@gmail.com", | ||
"password": "AS" | ||
} | ||
} | ||
|
||
self.invalid_email = { | ||
"user": { | ||
"username": "Wachira", | ||
"email": "invalid.com", | ||
"password": "AS" | ||
} | ||
} | ||
|
||
def test_user_registration_missing_username(self): | ||
"""Test the user registration""" | ||
response = self.client.post( | ||
self.register_url, | ||
self.none_field_credentials, | ||
format="json" | ||
) | ||
data = response.data | ||
self.assertTrue(data['errors']['username']) | ||
|
||
def test_user_registration_missing_username(self): | ||
"""Test the user registration""" | ||
response = self.client.post( | ||
self.register_url, | ||
self.none_field_credentials_2, | ||
format="json" | ||
) | ||
data = response.data | ||
self.assertTrue(data['errors']['email']) |
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,33 @@ | ||
import os | ||
|
||
from rest_framework.test import APITestCase | ||
|
||
from authors.apps.authentication.models import User | ||
from authors.apps.authentication.serializers import RegistrationSerializer | ||
|
||
class SerializerTest(APITestCase): | ||
""" | ||
Email verification test holder | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
setup method | ||
""" | ||
self.user_details = { | ||
"username":"Diana254", | ||
"email":"diana.kerubo@gmail.com", | ||
"password":"Diana254@" | ||
} | ||
self.serialized_data = { | ||
"username":"Diana254", | ||
"email":"diana.kerubo@gmail.com", | ||
"password":"Diana254@" | ||
} | ||
self.user = User.objects.create(**self.user_details) | ||
self.serializer = RegistrationSerializer(instance=self.user_details) | ||
|
||
def test_registration_serializer(self): | ||
data = self.serializer.data | ||
self.assertEqual(set(data.keys()), set(['email', 'username'])) | ||
|
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,39 @@ | ||
import os | ||
|
||
from rest_framework.test import APITestCase | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient, APITestCase | ||
from rest_framework.views import status | ||
|
||
from authors.apps.authentication.validations import UserValidation | ||
|
||
class ValidationTest(APITestCase): | ||
""" | ||
Email verification test holder | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
setup method | ||
""" | ||
self.email = "diana.kerubo@gmail.com" | ||
self.username = "Diana254" | ||
self.password = "@Diana254" | ||
|
||
def test_valid_email(self): | ||
""" | ||
Test a valid mail | ||
""" | ||
self.assertEqual(UserValidation().valid_email(email=self.email), True) | ||
|
||
def test_valid_username(self): | ||
""" | ||
Test a valid username | ||
""" | ||
self.assertEqual(UserValidation().valid_username(username=self.username), True) | ||
|
||
def test_valid_password(self): | ||
""" | ||
Test a valid password | ||
""" | ||
self.assertEqual(UserValidation().valid_password(password=self.password), True) |