-
Notifications
You must be signed in to change notification settings - Fork 2
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
14 changed files
with
278 additions
and
22 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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from django.urls import path, reverse | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase, APIRequestFactory, APIClient | ||
from authors.apps.authentication.views import RegistrationAPIView, AccountVerified | ||
from authors.apps.authentication.models import User | ||
from authors.apps.authentication.backends import JWTAuthentication | ||
|
||
|
||
class BaseTest(APITestCase): | ||
|
||
def setUp(self): | ||
self.slug = 0 | ||
self.user_data = { | ||
"user": { | ||
"username": "minime", | ||
"email": "alexkayabula@gmail.com", | ||
"password": "W123456/78"}} | ||
self.url = reverse("registration") | ||
self.client = APIClient() | ||
self.client.post(self.url, self.user_data, format='json') | ||
self.request = APIRequestFactory().post( | ||
reverse("registration") | ||
) | ||
|
||
self.new_article = { | ||
"article": { | ||
"title": "How to fight dragons 8", | ||
"description": "Ever wonder jckvlahvhow?", | ||
"body": "You have kenglto believe" | ||
} | ||
} | ||
|
||
self.update_article = { | ||
"article": { | ||
"title": "How to fight dragons 8", | ||
"description": "Ever wonder jckvlahvhow?", | ||
"body": "You have kenglto believe" | ||
} | ||
} | ||
|
||
self.article_without_title = { | ||
"article": { | ||
"description": "Ever wonder jckvlahvhow?", | ||
"body": "You have kenglto believe" | ||
} | ||
} | ||
|
||
user = User.objects.get() | ||
request = self.request | ||
token, uid = RegistrationAPIView.generate_token(user, request) | ||
response = self.account_verification(token, uid) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
user = User.objects.get() | ||
self.assertTrue(user.is_verified) | ||
|
||
response = self.client.post( | ||
'/api/users/login/', | ||
self.user_data, | ||
format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.login_token = response.data['token'] | ||
self.client.credentials( | ||
HTTP_AUTHORIZATION='Bearer ' + | ||
self.login_token) | ||
|
||
def account_verification(self, token, uid): | ||
request = APIRequestFactory().get( | ||
reverse("verify_account", kwargs={"token": token, "uid": uid}) | ||
) | ||
verify = AccountVerified.as_view() | ||
response = verify(request, token=token, uid=uid) | ||
return response | ||
|
||
def get_slug(self, response=[]): | ||
self.client.post( | ||
'/api/articles/', | ||
data=self.new_article, | ||
format='json') | ||
response = self.client.get('/api/articles/', format='json') | ||
for i in response.data: | ||
self.slug = i['slug'] | ||
return self.slug |
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,30 @@ | ||
from .base_test import BaseTest | ||
from rest_framework import status | ||
|
||
|
||
class TestRestPassWord(BaseTest): | ||
|
||
def test_reset_password(self): | ||
usr = { | ||
"user": { | ||
"username": "minime", | ||
"email": "alexkayabula@gmail.com", | ||
"password": "W123456/78"}} | ||
self.client.post('/api/users/password_reset/',data = usr,format = 'json') | ||
reset_data = { | ||
"user": { | ||
"username": "minime", | ||
"email": "alexkayabula@gmail.com", | ||
"password": "Whbdc^734"}} | ||
response = self.client.post('/api/users/password_reset/',data = reset_data ,format = 'json') | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_reset_password_with_missing_email(self): | ||
usr = { | ||
"user": { | ||
"username": "minime", | ||
"email": "", | ||
"password": "W123456/78"}} | ||
response = self.client.post('/api/users/password_reset/',data = usr,format = 'json') | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
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
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,74 @@ | ||
from django.urls import path, reverse | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase, APIRequestFactory, APIClient | ||
from authors.apps.authentication.views import RegistrationAPIView, AccountVerified | ||
from authors.apps.authentication.models import User | ||
from authors.apps.authentication.backends import JWTAuthentication | ||
|
||
|
||
class BaseTest(APITestCase): | ||
|
||
def setUp(self): | ||
self.slug = 0 | ||
self.user_data = { | ||
"user": { | ||
"username": "minime", | ||
"email": "alexkayabula@gmail.com", | ||
"password": "W123456/78"}} | ||
self.url = reverse("registration") | ||
self.client = APIClient() | ||
self.client.post(self.url, self.user_data, format='json') | ||
self.request = APIRequestFactory().post( | ||
reverse("registration") | ||
) | ||
|
||
self.new_article = { | ||
"article": { | ||
"title": "How to fight dragons 8", | ||
"description": "Ever wonder jckvlahvhow?", | ||
"body": "You have kenglto believe" | ||
} | ||
} | ||
|
||
self.article_without_title = { | ||
"article": { | ||
"description": "Ever wonder jckvlahvhow?", | ||
"body": "You have kenglto believe" | ||
} | ||
} | ||
|
||
user = User.objects.get() | ||
request = self.request | ||
token, uid = RegistrationAPIView.generate_token(user, request) | ||
response = self.account_verification(token, uid) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
user = User.objects.get() | ||
self.assertTrue(user.is_verified) | ||
|
||
response = self.client.post( | ||
'/api/users/login/', | ||
self.user_data, | ||
format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.login_token = response.data['token'] | ||
self.client.credentials( | ||
HTTP_AUTHORIZATION='Bearer ' + | ||
self.login_token) | ||
|
||
def account_verification(self, token, uid): | ||
request = APIRequestFactory().get( | ||
reverse("verify_account", kwargs={"token": token, "uid": uid}) | ||
) | ||
verify = AccountVerified.as_view() | ||
response = verify(request, token=token, uid=uid) | ||
return response | ||
|
||
def get_slug(self, response=[]): | ||
self.client.post( | ||
'/api/articles/', | ||
data=self.new_article, | ||
format='json') | ||
response = self.client.get('/api/articles/', format='json') | ||
for i in response.data['results']: | ||
self.slug = i['slug'] | ||
return self.slug |
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,28 @@ | ||
from .base_test import BaseTest | ||
from rest_framework import status | ||
|
||
class TestfavoriteArticle(BaseTest): | ||
|
||
def test_favorite_article(self): | ||
article = self.client.post('/api/articles/', data = self.new_article,format='json') | ||
slug = self.get_slug( article) | ||
response = self.client.put('/api/users/article/favorite/{}'.format(slug)) | ||
self.assertEqual(response.status_code,status.HTTP_200_OK) | ||
|
||
def test_favorite_article_which_doesnot_exist(self): | ||
response = self.client.put('/api/users/article/favorite/best-43hbc',format='json') | ||
self.assertEqual(response.status_code,status.HTTP_404_NOT_FOUND) | ||
|
||
def test_unfavorite_article(self): | ||
article = self.client.post('/api/articles/', data = self.new_article,format='json') | ||
slug = self.get_slug( article) | ||
self.client.put('/api/users/article/favorite/{}'.format(slug)) | ||
response = self.client.put('/api/users/article/favorite/{}'.format(slug)) | ||
self.assertEqual(response.status_code,status.HTTP_200_OK) | ||
|
||
def test_unfavorite_article_which_doesnot_exist(self): | ||
article = self.client.post('/api/articles/', data = self.new_article,format='json') | ||
slug = self.get_slug( article) | ||
self.client.put('/api/users/article/favorite/{}'.format(slug)) | ||
response = self.client.put('/api/users/article/favorite/man-1628t492') | ||
self.assertEqual(response.status_code,status.HTTP_404_NOT_FOUND) |
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,9 +1,10 @@ | ||
from django.urls import path | ||
|
||
from .views import UserProfiles,Updateprofile | ||
from .views import UserProfiles,Updateprofile,FavoriteArticle | ||
|
||
urlpatterns = [ | ||
path('users/profiles', UserProfiles.as_view()), | ||
path('users/profiles/', Updateprofile.as_view(),name="profile") | ||
path('users/profiles/', Updateprofile.as_view(),name="profile"), | ||
path('users/article/favorite/<slug>',FavoriteArticle.as_view()) | ||
|
||
] |
Oops, something went wrong.