|
1 | 1 | from django.conf import settings
|
2 |
| - |
3 | 2 | from django.contrib.auth.models import User
|
4 | 3 | from django.core.files.uploadedfile import SimpleUploadedFile
|
5 | 4 | from django.test.utils import override_settings
|
6 | 5 |
|
7 |
| -import django_comments |
8 |
| -from django_comments import signals |
| 6 | +from django_comments import signals, get_model |
9 | 7 | from django_comments.abstracts import COMMENT_MAX_LENGTH
|
10 | 8 | from django_comments.models import Comment
|
11 | 9 |
|
@@ -89,20 +87,6 @@ def testPostTooLongComment(self):
|
89 | 87 | response, "Ensure this value has at most %d characters" % COMMENT_MAX_LENGTH
|
90 | 88 | )
|
91 | 89 |
|
92 |
| - @override_settings( |
93 |
| - COMMENTS_APP='custom_comments', |
94 |
| - ) |
95 |
| - def testPostCommentWithFile(self): |
96 |
| - a = Article.objects.get(pk=1) |
97 |
| - data = self.getValidData(a) |
98 |
| - test_file = SimpleUploadedFile("test_file.txt", b"file_content") |
99 |
| - data["file"] = test_file |
100 |
| - response = self.client.post("/post/", data) |
101 |
| - self.assertEqual(response.status_code, 302) |
102 |
| - custom_comment = django_comments.get_model().objects.first() |
103 |
| - self.assertTrue(custom_comment.file) |
104 |
| - self.assertEqual(custom_comment.file.read(), b"file_content") |
105 |
| - |
106 | 90 | def testCommentPreview(self):
|
107 | 91 | a = Article.objects.get(pk=1)
|
108 | 92 | data = self.getValidData(a)
|
@@ -377,3 +361,18 @@ def testCommentNextWithQueryStringAndAnchor(self):
|
377 | 361 | '/somewhere/else/?c=%s#baz' % Comment.objects.latest('id').pk,
|
378 | 362 | fetch_redirect_response=False,
|
379 | 363 | )
|
| 364 | + |
| 365 | +@override_settings( |
| 366 | + COMMENTS_APP='custom_comments', |
| 367 | + ) |
| 368 | +class CustomCommentViewTests(CommentTestCase): |
| 369 | + def testPostCommentWithFile(self): |
| 370 | + a = Article.objects.get(pk=1) |
| 371 | + data = self.getValidData(a) |
| 372 | + test_file = SimpleUploadedFile("test_file.txt", b"file_content") |
| 373 | + data["file"] = test_file |
| 374 | + response = self.client.post("/post/", data) |
| 375 | + self.assertEqual(response.status_code, 302) |
| 376 | + custom_comment = get_model().objects.first() |
| 377 | + self.assertTrue(custom_comment.file) |
| 378 | + self.assertEqual(custom_comment.file.read(), b"file_content") |
0 commit comments