-
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(comments): Comment on articles
- Users can comment on the articles created [Delivers #162948915]
- Loading branch information
1 parent
a384763
commit 67506bb
Showing
26 changed files
with
501 additions
and
108 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
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,4 @@ | ||
from django.contrib import admin | ||
from .models import Comments | ||
# Register comments models | ||
admin.site.register(Comments) |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CommentsConfig(AppConfig): | ||
name = 'comments' |
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 @@ | ||
# 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.
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,16 @@ | ||
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.
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,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.
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,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 |
Oops, something went wrong.