Skip to content

Commit

Permalink
Merge 91cb3fa into a384763
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbeamie committed Jan 31, 2019
2 parents a384763 + 91cb3fa commit e6f6e83
Show file tree
Hide file tree
Showing 26 changed files with 502 additions and 108 deletions.
15 changes: 10 additions & 5 deletions authors/apps/articles/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image_path', cloudinary.models.CloudinaryField(blank=True, max_length=255, null=True)),
('id', models.AutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('image_path', cloudinary.models.CloudinaryField(
blank=True, max_length=255, null=True)),
('slug', models.SlugField(max_length=255)),
('title', models.CharField(db_index=True, max_length=255)),
('body', models.CharField(db_index=True, max_length=8055)),
('title', models.CharField(
db_index=True, max_length=255)),
('body', models.CharField(
db_index=True, max_length=8055)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('favourites', models.BooleanField(default=False)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='author', to=settings.AUTH_USER_MODEL)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
related_name='author', to=settings.AUTH_USER_MODEL)),
],
),
]
1 change: 0 additions & 1 deletion authors/apps/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.db import models
from cloudinary.models import CloudinaryField
from django.template.defaultfilters import slugify

from authors.apps.authentication.models import User
from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
Expand Down
2 changes: 2 additions & 0 deletions authors/apps/articles/tests/test_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from ..models import Article
from ...authentication.models import User


class ArticleTestCase(APITestCase):
"""
Article endpoints test
"""

def setUp(self):
"""
Setup method
Expand Down
10 changes: 6 additions & 4 deletions authors/apps/authentication/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"require_pwd": "Password is required to login",
"email_pwd": "Email address is required to login",
"profile_not_there": "User profile not found",
"cannot_update_profile": "No Permission to Edit"
"cannot_update_profile": "No Permission to Edit",
"no_slug":"Article with that slug does not exist",
"no_comment":"Comment with that ID does not exist"
}

success_msg = {
Expand All @@ -27,9 +29,9 @@
"email_verify": "Your verification link sent, check your email",
"profil_update": "Profile update successful",
"profil_success": "Request successful",
"Like": "Great, you've liked this",
'Dislike': "Okay, you've disliked this",
'Null': "Undone!",
"deleted_comment":"Comment Successfully deleted",
"added_comment":"Comment Successfully added",
"update_success":"Comment successfully updated"
}

statusmessage = {
Expand Down
53 changes: 26 additions & 27 deletions authors/apps/authentication/tests/test_social_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,46 @@
from django.test import TestCase
from rest_framework import status


class SocialAuthTest(APITestCase):
"""This class tests the social login and social signup"""

def setUp(self):
self.client = APIClient()
self.namespace = 'auth'

self. social_auth_url = reverse(self.namespace + ':social_signin_signup')
self. social_auth_url = reverse(
self.namespace + ':social_signin_signup')
self.test_social_body = {
"provider":"facebook",
"access_token":os.getenv('FB_TOKEN')
"provider": "facebook",
"access_token": os.getenv('FB_TOKEN')
}
self.test_google_body= {
"provider":"google-oauth2",
"access_token":os.getenv('GOOGLE_TOKEN')
}
self.test_twitter_body= {
"provider":"twitter",
"access_token":os.getenv('TWITTER_ACCESS_TOKEN'),
"access_token_secret":os.getenv('TWITTER_TOKEN_SECRET')
self.test_twitter_body = {
"provider": "twitter",
"access_token": os.getenv('TWITTER_ACCESS_TOKEN'),
"access_token_secret": os.getenv('TWITTER_TOKEN_SECRET')
}
self.test_invalid_provider={
"provider":"invalid-provider",
"access_token":os.getenv('GOOGLE_TOKEN')
self.test_invalid_provider = {
"provider": "invalid-provider",
"access_token": os.getenv('GOOGLE_TOKEN')
}
self.test_invalid_token={
"provider":"google-oauth2",
"access_token":"invalid-token"
self.test_invalid_token = {
"provider": "google-oauth2",
"access_token": "invalid-token"
}


def test_social_auth_api(self):
facebookresponse = self.client.post(self.social_auth_url, self.test_social_body, format='json')
twitterresponse = self.client.post(self.social_auth_url, self.test_twitter_body, format='json')
googleresponse =self.client.post(self.social_auth_url, self.test_google_body, format='json')
invalidtoken = self.client.post(self.social_auth_url, self.test_invalid_token, format= 'json')
invalidprovider = self.client.post(self.social_auth_url, self.test_invalid_provider, format='json')
facebookresponse = self.client.post(
self.social_auth_url, self.test_social_body, format='json')
twitterresponse = self.client.post(
self.social_auth_url, self.test_twitter_body, format='json')
invalidtoken = self.client.post(
self.social_auth_url, self.test_invalid_token, format='json')
invalidprovider = self.client.post(
self.social_auth_url, self.test_invalid_provider, format='json')

self.assertEqual(facebookresponse.status_code, status.HTTP_201_CREATED)
self.assertEqual(twitterresponse.status_code, status.HTTP_201_CREATED)
self.assertEqual(googleresponse.status_code, status.HTTP_201_CREATED)
self.assertTrue(invalidtoken.status_code, status.HTTP_400_BAD_REQUEST)
self.assertTrue(invalidprovider.status_code, status.HTTP_400_BAD_REQUEST)


self.assertTrue(invalidprovider.status_code,
status.HTTP_400_BAD_REQUEST)
Empty file.
4 changes: 4 additions & 0 deletions authors/apps/comments/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Comments
# Register comments models
admin.site.register(Comments)
5 changes: 5 additions & 0 deletions authors/apps/comments/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CommentsConfig(AppConfig):
name = 'comments'
28 changes: 28 additions & 0 deletions authors/apps/comments/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.1.4 on 2019-01-28 11:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('profiles', '__first__'),
('articles', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Comments',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now_add=True)),
('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article')),
('author_profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='author_profile', to='profiles.Profile')),
],
),
]
Empty file.
17 changes: 17 additions & 0 deletions authors/apps/comments/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.db import models
from authors.apps.authentication.models import User
from authors.apps.articles.models import Article
from authors.apps.profiles.models import Profile


class Comments(models.Model):

author_profile = models.ForeignKey(Profile, related_name='author_profile', on_delete=models.CASCADE)
article = models.ForeignKey(Article,on_delete=models.CASCADE)
body = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return str(self.author_profile)

Empty file.
21 changes: 21 additions & 0 deletions authors/apps/comments/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from rest_framework import serializers
from authors.apps.authentication.serializers import UserSerializer
from authors.apps.profiles.serializers import UserProfileSerializer
from .models import Comments


class CommentSerializer(serializers.ModelSerializer):
"""
Serializer class for comments
"""
author_profile = UserProfileSerializer(
many=False, read_only=True, required=False)

class Meta:
model = Comments
fields = ('article', 'id', 'created_at', 'updated_at',
'body', 'author_profile')

read_only_fields = ('id', 'author_profile',
'created_at', 'updated_at', 'article')

Empty file.
59 changes: 59 additions & 0 deletions authors/apps/comments/tests/base_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.urls import reverse
from rest_framework.test import APITestCase, APIClient
from ..models import Article
from authors.apps.authentication.models import User
from django.template.defaultfilters import slugify

class TestBaseCase(APITestCase):
def setUp(self):
self.client = APIClient()
self.signup_url = reverse('auth:register')
self.login_url = reverse('auth:login')
self.create_list_article_url = reverse('articles:articles')


self.test_user1 = {
'user': {
'email': 'james@gmail.com',
'password': 'TestUser123'
}}

self.article = {
"title":"Its a test article",
"body":"Its a test article body",
"description":"hello"

}

self.comment = {
"comment":{
"body": "This is a test comment body."
}
}

self.update_comment = {
"comment":{
"body": "This is a test update comment body."
}
}

self.test_user = User.objects.create_user(
username="jamess",
email="james@gmail.com",
password="TestUser123")

def login_user(self):
response = self.client.post(self.login_url,
self.test_user1,
format='json')
token = response.data['token']
return token

def create_article(self):
token=self.login_user()
response=self.client.post(self.create_list_article_url,
self.article,
HTTP_AUTHORIZATION="Bearer " + token,
format='json')
slug=response.data['slug']
return slug
Loading

0 comments on commit e6f6e83

Please sign in to comment.