|
1 | 1 | import time
|
2 | 2 |
|
3 | 3 | from django.conf import settings
|
| 4 | +from django.contrib.contenttypes.models import ContentType |
4 | 5 | from django.contrib.sites.models import Site
|
5 | 6 |
|
6 | 7 | from django_comments.forms import CommentForm
|
7 | 8 | from django_comments.models import Comment
|
8 | 9 |
|
9 | 10 | from . import CommentTestCase
|
10 |
| -from testapp.models import Article |
| 11 | +from testapp.models import UUIDArticle, Article |
| 12 | +from django.test.utils import override_settings |
11 | 13 |
|
12 | 14 |
|
13 | 15 | class CommentFormTests(CommentTestCase):
|
@@ -75,6 +77,34 @@ def testGetCommentObject(self):
|
75 | 77 | c = f.get_comment_object(site_id=self.site_2.id)
|
76 | 78 | self.assertEqual(c.site_id, self.site_2.id)
|
77 | 79 |
|
| 80 | + def testGetCommentCreateData(self): |
| 81 | + """ |
| 82 | + Test that get_comment_create_data() returns |
| 83 | + content_type for Article even if the proxy model UUIDArticle |
| 84 | + is set to CommentForm. |
| 85 | + """ |
| 86 | + a = UUIDArticle.objects.get(pk=1) |
| 87 | + d = self.getValidData(a) |
| 88 | + d["comment"] = "testGetCommentObject with a site" |
| 89 | + f = CommentForm(UUIDArticle.objects.get(pk=1), data=d) |
| 90 | + self.assertTrue(f.is_valid()) |
| 91 | + c = f.get_comment_create_data(site_id=self.site_2.id) |
| 92 | + self.assertEqual(c["content_type"], ContentType.objects.get_for_model(Article, for_concrete_model=False)) |
| 93 | + |
| 94 | + @override_settings(COMMENTS_FOR_CONCRETE_MODEL=False) |
| 95 | + def testGetCommentCreateDataConcreteModel(self): |
| 96 | + """ |
| 97 | + Test that get_comment_create_data() returns |
| 98 | + content_type for UUIDArticle if COMMENTS_FOR_CONCRETE_MODEL is False. |
| 99 | + """ |
| 100 | + a = UUIDArticle.objects.get(pk=1) |
| 101 | + d = self.getValidData(a) |
| 102 | + d["comment"] = "testGetCommentObject with a site" |
| 103 | + f = CommentForm(UUIDArticle.objects.get(pk=1), data=d) |
| 104 | + self.assertTrue(f.is_valid()) |
| 105 | + c = f.get_comment_create_data(site_id=self.site_2.id) |
| 106 | + self.assertEqual(c["content_type"], ContentType.objects.get_for_model(UUIDArticle, for_concrete_model=False)) |
| 107 | + |
78 | 108 | def testProfanities(self):
|
79 | 109 | """Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
|
80 | 110 | a = Article.objects.get(pk=1)
|
|
0 commit comments