Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions django_comments_xtd/api/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ def get_props(cls, obj, user, request=None):
"flag_url": cls._reverse("comments-flag", args=(0,)),
"list_url": cls._reverse('comments-xtd-api-list',
kwargs={'content_type': ctype_slug,
'object_pk': obj.id}),
'object_pk': obj.pk}),
"count_url": cls._reverse('comments-xtd-api-count',
kwargs={'content_type': ctype_slug,
'object_pk': obj.id}),
'object_pk': obj.pk}),
"send_url": cls._reverse("comments-xtd-api-create"),
"preview_url": cls._reverse("comments-xtd-api-preview"),
"form": {
Expand Down
22 changes: 22 additions & 0 deletions django_comments_xtd/tests/migrations/0003_uuiddiary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.0.6 on 2022-07-08 11:28

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


class Migration(migrations.Migration):

dependencies = [
('tests', '0002_auto_20170523_1624'),
]

operations = [
migrations.CreateModel(
name='UUIDDiary',
fields=[
('diary_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, to='tests.diary')),
('uuid', models.UUIDField(editable=False, primary_key=True, serialize=False, verbose_name='uuid')),
],
bases=('tests.diary',),
),
]
5 changes: 5 additions & 0 deletions django_comments_xtd/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class Meta:
ordering = ('-publish',)


class UUIDDiary(Diary):
"""Diary, that accepts comments."""
uuid = models.UUIDField("uuid", editable=False, primary_key=True)


class DiaryCommentModerator(XtdCommentModerator):
email_notification = True
enable_field = 'allow_comments'
Expand Down
70 changes: 70 additions & 0 deletions django_comments_xtd/tests/test_frontend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import uuid

from django.contrib.auth.models import AnonymousUser, User
from django.test import RequestFactory, TestCase

from django_comments_xtd.api.frontend import commentbox_props_response
from django_comments_xtd.models import XtdComment
from django_comments_xtd.tests.models import Diary, UUIDDiary


class CommentBoxTestCase(TestCase):
def test_commentbox_props_response(self):
request_factory = RequestFactory()
request = request_factory.get("/")
user = User.objects.create_user("bob", "[email protected]", "pwd")
diary = Diary.objects.create(
body='Lorem ipsum',
allow_comments=True
)
XtdComment.objects.create(
content_object=diary,
site_id=1,
)
response = commentbox_props_response(diary, user, request)
d = response.data
self.assertEqual(d['comment_count'], 1)
self.assertEqual(d['form']['object_pk'], str(diary.id))
self.assertEqual(d['count_url'], '/comments/api/tests-diary/1/count/')
self.assertEqual(d['list_url'], '/comments/api/tests-diary/1/')
self.assertEqual(d['current_user'], "1:bob")

def test_commentbox_props_response_anonymous(self):
request_factory = RequestFactory()
request = request_factory.get("/")
user = AnonymousUser()
diary = Diary.objects.create(
body='Lorem ipsum',
allow_comments=True
)
XtdComment.objects.create(
content_object=diary,
site_id=1,
)
response = commentbox_props_response(diary, user, request)
d = response.data
self.assertEqual(d['comment_count'], 1)
self.assertEqual(d['form']['object_pk'], str(diary.id))
self.assertEqual(d['count_url'], '/comments/api/tests-diary/1/count/')
self.assertEqual(d['list_url'], '/comments/api/tests-diary/1/')
self.assertEqual(d['current_user'], "0:Anonymous")

def test_commentbox_props_response_uuid(self):
request_factory = RequestFactory()
request = request_factory.get("/")
user = AnonymousUser()
diary = UUIDDiary.objects.create(
uuid=uuid.uuid4(),
body='Lorem ipsum',
allow_comments=True
)
XtdComment.objects.create(
content_object=diary,
site_id=1,
)
response = commentbox_props_response(diary, user, request)
d = response.data
self.assertEqual(d['comment_count'], 1)
self.assertEqual(d['form']['object_pk'], str(diary.uuid))
self.assertEqual(d['count_url'], f'/comments/api/tests-uuiddiary/{diary.uuid}/count/')
self.assertEqual(d['list_url'], f'/comments/api/tests-uuiddiary/{diary.uuid}/')