|
| 1 | +from django.test import TestCase, RequestFactory |
| 2 | +from django.contrib.auth.models import AnonymousUser |
| 3 | +from django_comments_xtd.api.frontend import commentbox_props_response |
| 4 | +from django_comments_xtd.tests.models import UUIDDiary, Diary |
| 5 | +from django_comments_xtd.models import XtdComment |
| 6 | +import uuid |
| 7 | +from pprint import pprint |
| 8 | + |
| 9 | + |
| 10 | +class CommentBoxTestCase(TestCase): |
| 11 | + def test_commentbox_props_response(self): |
| 12 | + request_factory = RequestFactory() |
| 13 | + request = request_factory.get("/") |
| 14 | + user = AnonymousUser() |
| 15 | + diary = Diary.objects.create( |
| 16 | + body='Lorem ipsum', |
| 17 | + allow_comments=True |
| 18 | + ) |
| 19 | + XtdComment.objects.create( |
| 20 | + content_object=diary, |
| 21 | + site_id=1, |
| 22 | + ) |
| 23 | + response = commentbox_props_response(diary, user, request) |
| 24 | + d = response.data |
| 25 | + pprint(d) |
| 26 | + self.assertEqual(d['comment_count'], 1) |
| 27 | + self.assertEqual(d['form']['object_pk'], str(diary.id)) |
| 28 | + self.assertEqual(d['count_url'], '/comments/api/tests-diary/1/count/') |
| 29 | + self.assertEqual(d['list_url'], '/comments/api/tests-diary/1/') |
| 30 | + |
| 31 | + def test_commentbox_props_response_uuid(self): |
| 32 | + request_factory = RequestFactory() |
| 33 | + request = request_factory.get("/") |
| 34 | + user = AnonymousUser() |
| 35 | + diary = UUIDDiary.objects.create( |
| 36 | + uuid=uuid.uuid4(), |
| 37 | + body='Lorem ipsum', |
| 38 | + allow_comments=True |
| 39 | + ) |
| 40 | + XtdComment.objects.create( |
| 41 | + content_object=diary, |
| 42 | + site_id=1, |
| 43 | + ) |
| 44 | + response = commentbox_props_response(diary, user, request) |
| 45 | + d = response.data |
| 46 | + pprint(d) |
| 47 | + self.assertEqual(d['comment_count'], 1) |
| 48 | + self.assertEqual(d['form']['object_pk'], str(diary.uuid)) |
| 49 | + self.assertEqual(d['count_url'], f'/comments/api/tests-uuiddiary/{diary.uuid}/count/') |
| 50 | + self.assertEqual(d['list_url'], f'/comments/api/tests-uuiddiary/{diary.uuid}/') |
0 commit comments