|
1 | 1 | import time
|
| 2 | +from datetime import datetime |
2 | 3 |
|
3 | 4 | from django.conf import settings
|
| 5 | +from django.contrib.contenttypes.models import ContentType |
4 | 6 | from django.contrib.sites.models import Site
|
| 7 | +from django.test.utils import override_settings |
| 8 | +from freezegun import freeze_time |
| 9 | +from testapp.models import Article |
5 | 10 |
|
6 | 11 | from django_comments.forms import CommentForm
|
7 | 12 | from django_comments.models import Comment
|
8 | 13 |
|
9 | 14 | from . import CommentTestCase
|
10 |
| -from testapp.models import Article |
11 | 15 |
|
| 16 | +CT = ContentType.objects.get_for_model |
12 | 17 |
|
13 | 18 | class CommentFormTests(CommentTestCase):
|
14 | 19 |
|
@@ -75,6 +80,92 @@ def testGetCommentObject(self):
|
75 | 80 | c = f.get_comment_object(site_id=self.site_2.id)
|
76 | 81 | self.assertEqual(c.site_id, self.site_2.id)
|
77 | 82 |
|
| 83 | + @freeze_time("2012-01-14 13:21:34") |
| 84 | + def test_get_comment_create_data_uuid(self): |
| 85 | + """ |
| 86 | + The get_comment_create_data() method returns |
| 87 | + uuid field as object_pk if overriden by settings |
| 88 | + """ |
| 89 | + a = Article.objects.get(pk=1) |
| 90 | + d = self.getValidData(a) |
| 91 | + d["comment"] = "testGetCommentObject with a site" |
| 92 | + f = CommentForm(Article.objects.get(pk=1), data=d) |
| 93 | + self.assertTrue(f.is_valid()) |
| 94 | + with override_settings( |
| 95 | + COMMENTS_ID_OVERRIDES={ |
| 96 | + "testapp.Article": "uuid", |
| 97 | + } |
| 98 | + ): |
| 99 | + c = f.get_comment_create_data(site_id=self.site_2.id) |
| 100 | + self.assertDictEqual( |
| 101 | + c, |
| 102 | + { |
| 103 | + "comment": "testGetCommentObject with a site", |
| 104 | + "content_type": CT(Article), |
| 105 | + "is_public": True, |
| 106 | + "is_removed": False, |
| 107 | + "object_pk": "336384ea-b04f-4a3a-a06a-1f25a8048f8f", # uuid is returned |
| 108 | + "site_id": 2, |
| 109 | + "submit_date": datetime(2012, 1, 14, 13, 21, 34), |
| 110 | + "user_email": "[email protected]", |
| 111 | + "user_name": "Jim Bob", |
| 112 | + "user_url": "", |
| 113 | + }, |
| 114 | + ) |
| 115 | + c = f.get_comment_create_data(site_id=self.site_2.id) |
| 116 | + self.assertDictEqual( |
| 117 | + c, |
| 118 | + { |
| 119 | + "comment": "testGetCommentObject with a site", |
| 120 | + "content_type": CT(Article), |
| 121 | + "is_public": True, |
| 122 | + "is_removed": False, |
| 123 | + "object_pk": "1", # pk is returned as object_pk |
| 124 | + "site_id": 2, |
| 125 | + "submit_date": datetime(2012, 1, 14, 13, 21, 34), |
| 126 | + "user_email": "[email protected]", |
| 127 | + "user_name": "Jim Bob", |
| 128 | + "user_url": "", |
| 129 | + }, |
| 130 | + ) |
| 131 | + |
| 132 | + @freeze_time("2012-01-14 13:21:34") |
| 133 | + def test_generate_security_data_uuid(self): |
| 134 | + """ |
| 135 | + The generate_security_data() method returns |
| 136 | + uuid field as object_pk if overriden by settings |
| 137 | + """ |
| 138 | + a = Article.objects.get(pk=1) |
| 139 | + d = self.getValidData(a) |
| 140 | + d["comment"] = "testGetCommentObject with a site" |
| 141 | + f = CommentForm(Article.objects.get(pk=1), data=d) |
| 142 | + self.assertTrue(f.is_valid()) |
| 143 | + with override_settings( |
| 144 | + COMMENTS_ID_OVERRIDES={ |
| 145 | + "testapp.Article": "uuid", |
| 146 | + } |
| 147 | + ): |
| 148 | + c = f.generate_security_data() |
| 149 | + self.assertDictEqual( |
| 150 | + c, |
| 151 | + { |
| 152 | + "content_type": "testapp.article", |
| 153 | + "object_pk": "336384ea-b04f-4a3a-a06a-1f25a8048f8f", |
| 154 | + "security_hash": "b89ebc7c1c6ed757991fa06027405aecdf8d51f1", |
| 155 | + "timestamp": "1326547294", |
| 156 | + }, |
| 157 | + ) |
| 158 | + c = f.generate_security_data() |
| 159 | + self.assertDictEqual( |
| 160 | + c, |
| 161 | + { |
| 162 | + "content_type": "testapp.article", |
| 163 | + "object_pk": "1", |
| 164 | + "security_hash": "2f4a55f47e58b22791d4d26f3b1a2e594302fb61", |
| 165 | + "timestamp": "1326547294", |
| 166 | + }, |
| 167 | + ) |
| 168 | + |
78 | 169 | def testProfanities(self):
|
79 | 170 | """Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
|
80 | 171 | a = Article.objects.get(pk=1)
|
|
0 commit comments