~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to threadedcomments/tests/views_tests.py

  • Committer: franku
  • Date: 2018-04-26 20:18:55 UTC
  • mfrom: (489.1.28 widelands)
  • Revision ID: somal@arcor.de-20180426201855-uwt3b8gptpav6wrm
updated code base to fit with django 1.11.12; replaced app tracking with a new middleware

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import datetime
2
 
 
3
 
from xml.dom.minidom import parseString
4
 
 
5
 
from django.core import mail
6
 
from django.core.urlresolvers import reverse
7
 
from django.template import Context, Template
8
 
from django.test import TestCase
9
 
from django.utils.simplejson import loads
10
 
 
11
 
from django.contrib.auth.models import User
12
 
from django.contrib.contenttypes.models import ContentType
13
 
 
14
 
from threadedcomments.models import FreeThreadedComment, ThreadedComment, TestModel
15
 
from threadedcomments.models import MARKDOWN, TEXTILE, REST, PLAINTEXT
16
 
from threadedcomments.templatetags import threadedcommentstags as tags
17
 
 
18
 
 
19
 
__all__ = ('ViewsTestCase',)
20
 
 
21
 
 
22
 
class ViewsTestCase(TestCase):
23
 
    urls = 'threadedcomments.tests.threadedcomments_urls'
24
 
 
25
 
    def test_freecomment_create(self):
26
 
 
27
 
        topic = TestModel.objects.create(name='Test2')
28
 
        content_type = ContentType.objects.get_for_model(topic)
29
 
 
30
 
        url = reverse('tc_free_comment', kwargs={
31
 
            'content_type': content_type.id,
32
 
            'object_id': topic.id
33
 
        })
34
 
        response = self.client.post(url, {
35
 
            'comment': 'test1',
36
 
            'name': 'eric',
37
 
            'website': 'http://www.eflorenzano.com/',
38
 
            'email': 'floguy@gmail.com',
39
 
            'next': '/'
40
 
        })
41
 
        o = FreeThreadedComment.objects.latest(
42
 
            'date_submitted').get_base_data(show_dates=False)
43
 
        self.assertEquals(o, {
44
 
            'website': u'http://www.eflorenzano.com/',
45
 
            'comment': u'test1',
46
 
            'name': u'eric',
47
 
            'parent': None,
48
 
            'markup': u'plaintext',
49
 
            'content_object': topic,
50
 
            'is_public': True,
51
 
            'ip_address': u'127.0.0.1',
52
 
            'email': u'floguy@gmail.com',
53
 
            'is_approved': False
54
 
        })
55
 
 
56
 
    def test_freecomment_preview(self):
57
 
 
58
 
        topic = TestModel.objects.create(name='Test2')
59
 
        content_type = ContentType.objects.get_for_model(topic)
60
 
 
61
 
        url = reverse('tc_free_comment', kwargs={
62
 
            'content_type': content_type.id,
63
 
            'object_id': topic.id
64
 
        })
65
 
 
66
 
        response = self.client.post(url, {
67
 
            'comment': 'test1',
68
 
            'name': 'eric',
69
 
            'website': 'http://www.eflorenzano.com/',
70
 
            'email': 'floguy@gmail.com',
71
 
            'next': '/',
72
 
            'preview': 'True'
73
 
        })
74
 
        self.assertEquals(len(response.content) > 0, True)
75
 
 
76
 
    def test_freecomment_edit(self):
77
 
 
78
 
        topic = TestModel.objects.create(name='Test2')
79
 
 
80
 
        comment = FreeThreadedComment.objects.create_for_object(topic,
81
 
                                                                ip_address='127.0.0.1',
82
 
                                                                comment='My test free comment!',
83
 
                                                                )
84
 
 
85
 
        url = reverse('tc_free_comment_edit', kwargs={
86
 
            'edit_id': comment.pk
87
 
        })
88
 
 
89
 
        response = self.client.post(url, {
90
 
            'comment': 'test1_edited',
91
 
            'name': 'eric',
92
 
            'website': 'http://www.eflorenzano.com/',
93
 
            'email': 'floguy@gmail.com',
94
 
            'next': '/'
95
 
        })
96
 
        o = FreeThreadedComment.objects.latest(
97
 
            'date_submitted').get_base_data(show_dates=False)
98
 
        self.assertEquals(o, {
99
 
            'website': u'http://www.eflorenzano.com/',
100
 
            'comment': u'test1_edited',
101
 
            'name': u'eric',
102
 
            'parent': None,
103
 
            'markup': u'plaintext',
104
 
            'content_object': topic,
105
 
            'is_public': True,
106
 
            'ip_address': u'127.0.0.1',
107
 
            'email': u'floguy@gmail.com',
108
 
            'is_approved': False
109
 
        })
110
 
 
111
 
    def test_freecomment_edit_with_preview(self):
112
 
 
113
 
        topic = TestModel.objects.create(name='Test2')
114
 
 
115
 
        comment = FreeThreadedComment.objects.create_for_object(topic,
116
 
                                                                website='http://oebfare.com/',
117
 
                                                                comment='My test free comment!',
118
 
                                                                ip_address='127.0.0.1',
119
 
                                                                )
120
 
 
121
 
        url = reverse('tc_free_comment_edit', kwargs={
122
 
            'edit_id': comment.pk
123
 
        })
124
 
 
125
 
        response = self.client.post(url, {
126
 
            'comment': 'test1_edited',
127
 
            'name': 'eric',
128
 
            'website': 'http://www.eflorenzano.com/',
129
 
            'email': 'floguy@gmail.com',
130
 
            'next': '/',
131
 
            'preview': 'True'
132
 
        })
133
 
        o = FreeThreadedComment.objects.latest(
134
 
            'date_submitted').get_base_data(show_dates=False)
135
 
        self.assertEquals(o, {
136
 
            'website': u'http://oebfare.com/',
137
 
            'comment': u'My test free comment!',
138
 
            'name': u'',
139
 
            'parent': None,
140
 
            'markup': u'plaintext',
141
 
            'content_object': topic,
142
 
            'is_public': True,
143
 
            'ip_address': u'127.0.0.1',
144
 
            'email': u'',
145
 
            'is_approved': False
146
 
        })
147
 
        self.assertEquals(len(response.content) > 0, True)
148
 
 
149
 
    def test_freecomment_json_create(self):
150
 
 
151
 
        topic = TestModel.objects.create(name='Test2')
152
 
        content_type = ContentType.objects.get_for_model(topic)
153
 
 
154
 
        url = reverse('tc_free_comment_ajax', kwargs={
155
 
            'content_type': content_type.id,
156
 
            'object_id': topic.id,
157
 
            'ajax': 'json'
158
 
        })
159
 
 
160
 
        response = self.client.post(url, {
161
 
            'comment': 'test2',
162
 
            'name': 'eric',
163
 
            'website': 'http://www.eflorenzano.com/',
164
 
            'email': 'floguy@gmail.com'
165
 
        })
166
 
        tmp = loads(response.content)
167
 
        o = FreeThreadedComment.objects.latest(
168
 
            'date_submitted').get_base_data(show_dates=False)
169
 
        self.assertEquals(o, {
170
 
            'website': u'http://www.eflorenzano.com/',
171
 
            'comment': u'test2',
172
 
            'name': u'eric',
173
 
            'parent': None,
174
 
            'markup': u'plaintext',
175
 
            'content_object': topic,
176
 
            'is_public': True,
177
 
            'ip_address': u'127.0.0.1',
178
 
            'email': u'floguy@gmail.com',
179
 
            'is_approved': False
180
 
        })
181
 
 
182
 
    def test_freecomment_json_edit(self):
183
 
 
184
 
        topic = TestModel.objects.create(name='Test2')
185
 
 
186
 
        comment = FreeThreadedComment.objects.create_for_object(topic,
187
 
                                                                ip_address='127.0.0.1',
188
 
                                                                comment='My test free comment!',
189
 
                                                                )
190
 
 
191
 
        url = reverse('tc_free_comment_edit_ajax', kwargs={
192
 
            'edit_id': comment.pk,
193
 
            'ajax': 'json'
194
 
        })
195
 
 
196
 
        response = self.client.post(url, {
197
 
            'comment': 'test2_edited',
198
 
            'name': 'eric',
199
 
            'website': 'http://www.eflorenzano.com/',
200
 
            'email': 'floguy@gmail.com'
201
 
        })
202
 
        tmp = loads(response.content)
203
 
        o = FreeThreadedComment.objects.latest(
204
 
            'date_submitted').get_base_data(show_dates=False)
205
 
        self.assertEquals(o, {
206
 
            'website': u'http://www.eflorenzano.com/',
207
 
            'comment': u'test2_edited',
208
 
            'name': u'eric',
209
 
            'parent': None,
210
 
            'markup': u'plaintext',
211
 
            'content_object': topic,
212
 
            'is_public': True,
213
 
            'ip_address': u'127.0.0.1',
214
 
            'email': u'floguy@gmail.com',
215
 
            'is_approved': False
216
 
        })
217
 
 
218
 
    def test_freecomment_xml_create(self):
219
 
 
220
 
        topic = TestModel.objects.create(name='Test2')
221
 
        content_type = ContentType.objects.get_for_model(topic)
222
 
 
223
 
        url = reverse('tc_free_comment_ajax', kwargs={
224
 
            'content_type': content_type.id,
225
 
            'object_id': topic.id,
226
 
            'ajax': 'xml'
227
 
        })
228
 
 
229
 
        response = self.client.post(url, {'comment': 'test3', 'name': 'eric',
230
 
                                          'website': 'http://www.eflorenzano.com/', 'email': 'floguy@gmail.com', 'next': '/'})
231
 
        tmp = parseString(response.content)
232
 
        o = FreeThreadedComment.objects.latest(
233
 
            'date_submitted').get_base_data(show_dates=False)
234
 
        self.assertEquals(o, {
235
 
            'website': u'http://www.eflorenzano.com/',
236
 
            'comment': u'test3',
237
 
            'name': u'eric',
238
 
            'parent': None,
239
 
            'markup': u'plaintext',
240
 
            'content_object': topic,
241
 
            'is_public': True,
242
 
            'ip_address': u'127.0.0.1',
243
 
            'email': u'floguy@gmail.com',
244
 
            'is_approved': False
245
 
        })
246
 
 
247
 
    def test_freecomment_xml_edit(self):
248
 
 
249
 
        topic = TestModel.objects.create(name='Test2')
250
 
 
251
 
        comment = FreeThreadedComment.objects.create_for_object(topic,
252
 
                                                                ip_address='127.0.0.1',
253
 
                                                                comment='My test free comment!',
254
 
                                                                )
255
 
 
256
 
        url = reverse('tc_free_comment_edit_ajax', kwargs={
257
 
            'edit_id': comment.pk,
258
 
            'ajax': 'xml'
259
 
        })
260
 
 
261
 
        response = self.client.post(url, {
262
 
            'comment': 'test2_edited',
263
 
            'name': 'eric',
264
 
            'website': 'http://www.eflorenzano.com/',
265
 
            'email': 'floguy@gmail.com'
266
 
        })
267
 
        tmp = parseString(response.content)
268
 
        o = FreeThreadedComment.objects.latest(
269
 
            'date_submitted').get_base_data(show_dates=False)
270
 
        self.assertEquals(o, {
271
 
            'website': u'http://www.eflorenzano.com/',
272
 
            'comment': u'test2_edited',
273
 
            'name': u'eric',
274
 
            'parent': None,
275
 
            'markup': u'plaintext',
276
 
            'content_object': topic,
277
 
            'is_public': True,
278
 
            'ip_address': u'127.0.0.1',
279
 
            'email': u'floguy@gmail.com',
280
 
            'is_approved': False
281
 
        })
282
 
 
283
 
    def test_freecomment_child_create(self):
284
 
 
285
 
        topic = TestModel.objects.create(name='Test2')
286
 
        content_type = ContentType.objects.get_for_model(topic)
287
 
 
288
 
        parent = FreeThreadedComment.objects.create_for_object(topic,
289
 
                                                               ip_address='127.0.0.1',
290
 
                                                               comment='My test free comment!',
291
 
                                                               )
292
 
 
293
 
        url = reverse('tc_free_comment_parent', kwargs={
294
 
            'content_type': content_type.id,
295
 
            'object_id': topic.id,
296
 
            'parent_id': parent.id
297
 
        })
298
 
        response = self.client.post(url, {
299
 
            'comment': 'test4',
300
 
            'name': 'eric',
301
 
            'website': 'http://www.eflorenzano.com/',
302
 
            'email': 'floguy@gmail.com',
303
 
            'next': '/'
304
 
        })
305
 
        o = FreeThreadedComment.objects.latest(
306
 
            'date_submitted').get_base_data(show_dates=False)
307
 
        self.assertEquals(o, {
308
 
            'website': u'http://www.eflorenzano.com/',
309
 
            'comment': u'test4',
310
 
            'name': u'eric',
311
 
            'parent': parent,
312
 
            'markup': u'plaintext',
313
 
            'content_object': topic,
314
 
            'is_public': True,
315
 
            'ip_address': u'127.0.0.1',
316
 
            'email': u'floguy@gmail.com',
317
 
            'is_approved': False
318
 
        })
319
 
 
320
 
    def test_freecomment_child_json_create(self):
321
 
 
322
 
        topic = TestModel.objects.create(name='Test2')
323
 
        content_type = ContentType.objects.get_for_model(topic)
324
 
 
325
 
        parent = FreeThreadedComment.objects.create_for_object(topic,
326
 
                                                               ip_address='127.0.0.1',
327
 
                                                               comment='My test free comment!',
328
 
                                                               )
329
 
 
330
 
        url = reverse('tc_free_comment_parent_ajax', kwargs={
331
 
            'content_type': content_type.id,
332
 
            'object_id': topic.id,
333
 
            'parent_id': parent.id,
334
 
            'ajax': 'json'
335
 
        })
336
 
 
337
 
        response = self.client.post(url, {
338
 
            'comment': 'test5',
339
 
            'name': 'eric',
340
 
            'website': 'http://www.eflorenzano.com/',
341
 
            'email': 'floguy@gmail.com'
342
 
        })
343
 
        tmp = loads(response.content)
344
 
        o = FreeThreadedComment.objects.latest(
345
 
            'date_submitted').get_base_data(show_dates=False)
346
 
        self.assertEquals(o, {
347
 
            'website': u'http://www.eflorenzano.com/',
348
 
            'comment': u'test5',
349
 
            'name': u'eric',
350
 
            'parent': parent,
351
 
            'markup': u'plaintext',
352
 
            'content_object': topic,
353
 
            'is_public': True,
354
 
            'ip_address': u'127.0.0.1',
355
 
            'email': u'floguy@gmail.com',
356
 
            'is_approved': False
357
 
        })
358
 
 
359
 
    def test_freecomment_child_xml_create(self):
360
 
 
361
 
        topic = TestModel.objects.create(name='Test2')
362
 
        content_type = ContentType.objects.get_for_model(topic)
363
 
 
364
 
        parent = FreeThreadedComment.objects.create_for_object(topic,
365
 
                                                               ip_address='127.0.0.1',
366
 
                                                               comment='My test free comment!',
367
 
                                                               )
368
 
 
369
 
        url = reverse('tc_free_comment_parent_ajax', kwargs={
370
 
            'content_type': content_type.id,
371
 
            'object_id': topic.id,
372
 
            'parent_id': parent.id,
373
 
            'ajax': 'xml'
374
 
        })
375
 
 
376
 
        response = self.client.post(url, {
377
 
            'comment': 'test6', 'name': 'eric',
378
 
            'website': 'http://www.eflorenzano.com/',
379
 
            'email': 'floguy@gmail.com'
380
 
        })
381
 
        tmp = parseString(response.content)
382
 
        o = FreeThreadedComment.objects.latest(
383
 
            'date_submitted').get_base_data(show_dates=False)
384
 
        self.assertEquals(o, {
385
 
            'website': u'http://www.eflorenzano.com/',
386
 
            'comment': u'test6',
387
 
            'name': u'eric',
388
 
            'parent': parent,
389
 
            'markup': u'plaintext',
390
 
            'content_object': topic,
391
 
            'is_public': True,
392
 
            'ip_address': u'127.0.0.1',
393
 
            'email': u'floguy@gmail.com',
394
 
            'is_approved': False
395
 
        })
396
 
 
397
 
    def create_user_and_login(self):
398
 
        user = User.objects.create_user(
399
 
            'testuser',
400
 
            'testuser@gmail.com',
401
 
            'password',
402
 
        )
403
 
        user.is_active = True
404
 
        user.save()
405
 
        self.client.login(username='testuser', password='password')
406
 
        return user
407
 
 
408
 
    def test_comment_create(self):
409
 
 
410
 
        user = self.create_user_and_login()
411
 
 
412
 
        topic = TestModel.objects.create(name='Test2')
413
 
        content_type = ContentType.objects.get_for_model(topic)
414
 
 
415
 
        url = reverse('tc_comment', kwargs={
416
 
            'content_type': content_type.id,
417
 
            'object_id': topic.id
418
 
        })
419
 
 
420
 
        response = self.client.post(url, {
421
 
            'comment': 'test7',
422
 
            'next': '/'
423
 
        })
424
 
        o = ThreadedComment.objects.latest(
425
 
            'date_submitted').get_base_data(show_dates=False)
426
 
        self.assertEquals(o, {
427
 
            'comment': u'test7',
428
 
            'is_approved': False,
429
 
            'parent': None,
430
 
            'markup': u'plaintext',
431
 
            'content_object': topic,
432
 
            'user': user,
433
 
            'is_public': True,
434
 
            'ip_address': u'127.0.0.1',
435
 
        })
436
 
 
437
 
    def test_comment_preview(self):
438
 
 
439
 
        user = self.create_user_and_login()
440
 
 
441
 
        topic = TestModel.objects.create(name='Test2')
442
 
        content_type = ContentType.objects.get_for_model(topic)
443
 
 
444
 
        url = reverse('tc_comment', kwargs={
445
 
            'content_type': content_type.id,
446
 
            'object_id': topic.id
447
 
        })
448
 
 
449
 
        response = self.client.post(url, {
450
 
            'comment': 'test7',
451
 
            'next': '/',
452
 
            'preview': 'True'
453
 
        })
454
 
        self.assertEquals(len(response.content) > 0, True)
455
 
 
456
 
    def test_comment_edit(self):
457
 
 
458
 
        user = self.create_user_and_login()
459
 
 
460
 
        topic = TestModel.objects.create(name='Test2')
461
 
        comment = ThreadedComment.objects.create_for_object(topic,
462
 
                                                            user=user,
463
 
                                                            ip_address=u'127.0.0.1',
464
 
                                                            comment='My test comment!',
465
 
                                                            )
466
 
 
467
 
        url = reverse('tc_comment_edit', kwargs={
468
 
            'edit_id': comment.pk,
469
 
        })
470
 
 
471
 
        response = self.client.post(url, {
472
 
            'comment': 'test7_edited',
473
 
            'next': '/',
474
 
        })
475
 
        o = ThreadedComment.objects.latest(
476
 
            'date_submitted').get_base_data(show_dates=False)
477
 
        self.assertEquals(o, {
478
 
            'comment': u'test7_edited',
479
 
            'is_approved': False,
480
 
            'parent': None,
481
 
            'markup': u'plaintext',
482
 
            'content_object': topic,
483
 
            'user': user,
484
 
            'is_public': True,
485
 
            'ip_address': u'127.0.0.1',
486
 
        })
487
 
 
488
 
    def test_comment_edit_with_preview(self):
489
 
 
490
 
        user = self.create_user_and_login()
491
 
 
492
 
        topic = TestModel.objects.create(name='Test2')
493
 
        comment = ThreadedComment.objects.create_for_object(topic,
494
 
                                                            user=user,
495
 
                                                            ip_address=u'127.0.0.1',
496
 
                                                            comment='My test comment!',
497
 
                                                            )
498
 
 
499
 
        url = reverse('tc_comment_edit', kwargs={
500
 
            'edit_id': comment.pk,
501
 
        })
502
 
 
503
 
        response = self.client.post(url, {
504
 
            'comment': 'test7_edited',
505
 
            'next': '/',
506
 
            'preview': 'True'
507
 
        })
508
 
 
509
 
        self.assertEquals(len(response.content) > 0, True)
510
 
        o = ThreadedComment.objects.latest(
511
 
            'date_submitted').get_base_data(show_dates=False)
512
 
        self.assertEquals(o, {
513
 
            'comment': u'My test comment!',
514
 
            'is_approved': False,
515
 
            'parent': None,
516
 
            'markup': u'plaintext',
517
 
            'content_object': topic,
518
 
            'user': user,
519
 
            'is_public': True,
520
 
            'ip_address': u'127.0.0.1',
521
 
        })
522
 
 
523
 
    def test_comment_json_create(self):
524
 
 
525
 
        user = self.create_user_and_login()
526
 
 
527
 
        topic = TestModel.objects.create(name='Test2')
528
 
        content_type = ContentType.objects.get_for_model(topic)
529
 
 
530
 
        url = reverse('tc_comment_ajax', kwargs={
531
 
            'content_type': content_type.id,
532
 
            'object_id': topic.id,
533
 
            'ajax': 'json'
534
 
        })
535
 
 
536
 
        response = self.client.post(url, {
537
 
            'comment': 'test8'
538
 
        })
539
 
        tmp = loads(response.content)
540
 
        o = ThreadedComment.objects.latest(
541
 
            'date_submitted').get_base_data(show_dates=False)
542
 
        self.assertEquals(o, {
543
 
            'comment': u'test8',
544
 
            'is_approved': False,
545
 
            'parent': None,
546
 
            'markup': u'plaintext',
547
 
            'content_object': topic,
548
 
            'user': user,
549
 
            'is_public': True,
550
 
            'ip_address': u'127.0.0.1',
551
 
        })
552
 
 
553
 
    def test_comment_json_edit(self):
554
 
 
555
 
        user = self.create_user_and_login()
556
 
 
557
 
        topic = TestModel.objects.create(name='Test2')
558
 
        comment = ThreadedComment.objects.create_for_object(topic,
559
 
                                                            user=user,
560
 
                                                            ip_address=u'127.0.0.1',
561
 
                                                            comment='My test comment!',
562
 
                                                            )
563
 
 
564
 
        url = reverse('tc_comment_edit_ajax', kwargs={
565
 
            'edit_id': comment.pk,
566
 
            'ajax': 'json',
567
 
        })
568
 
 
569
 
        response = self.client.post(url, {
570
 
            'comment': 'test8_edited'
571
 
        })
572
 
        tmp = loads(response.content)
573
 
        o = ThreadedComment.objects.latest(
574
 
            'date_submitted').get_base_data(show_dates=False)
575
 
        self.assertEquals(o, {
576
 
            'comment': u'test8_edited',
577
 
            'is_approved': False,
578
 
            'parent': None,
579
 
            'markup': u'plaintext',
580
 
            'content_object': topic,
581
 
            'user': user,
582
 
            'is_public': True,
583
 
            'ip_address': u'127.0.0.1',
584
 
        })
585
 
 
586
 
    def test_comment_xml_create(self):
587
 
 
588
 
        user = self.create_user_and_login()
589
 
 
590
 
        topic = TestModel.objects.create(name='Test2')
591
 
        content_type = ContentType.objects.get_for_model(topic)
592
 
 
593
 
        url = reverse('tc_comment_ajax', kwargs={
594
 
            'content_type': content_type.id,
595
 
            'object_id': topic.id,
596
 
            'ajax': 'xml'
597
 
        })
598
 
 
599
 
        response = self.client.post(url, {
600
 
            'comment': 'test9'
601
 
        })
602
 
        tmp = parseString(response.content)
603
 
        o = ThreadedComment.objects.latest(
604
 
            'date_submitted').get_base_data(show_dates=False)
605
 
        self.assertEquals(o, {
606
 
            'comment': u'test9',
607
 
            'is_approved': False,
608
 
            'parent': None,
609
 
            'markup': u'plaintext',
610
 
            'content_object': topic,
611
 
            'user': user,
612
 
            'is_public': True,
613
 
            'ip_address': u'127.0.0.1',
614
 
        })
615
 
 
616
 
    def test_comment_xml_edit(self):
617
 
 
618
 
        user = self.create_user_and_login()
619
 
 
620
 
        topic = TestModel.objects.create(name='Test2')
621
 
        comment = ThreadedComment.objects.create_for_object(topic,
622
 
                                                            user=user,
623
 
                                                            ip_address=u'127.0.0.1',
624
 
                                                            comment='My test comment!',
625
 
                                                            )
626
 
 
627
 
        url = reverse('tc_comment_edit_ajax', kwargs={
628
 
            'edit_id': comment.pk,
629
 
            'ajax': 'xml',
630
 
        })
631
 
 
632
 
        response = self.client.post(url, {
633
 
            'comment': 'test8_edited'
634
 
        })
635
 
        tmp = parseString(response.content)
636
 
        o = ThreadedComment.objects.latest(
637
 
            'date_submitted').get_base_data(show_dates=False)
638
 
        self.assertEquals(o, {
639
 
            'comment': u'test8_edited',
640
 
            'is_approved': False,
641
 
            'parent': None,
642
 
            'markup': u'plaintext',
643
 
            'content_object': topic,
644
 
            'user': user,
645
 
            'is_public': True,
646
 
            'ip_address': u'127.0.0.1',
647
 
        })
648
 
 
649
 
    def test_comment_child_create(self):
650
 
 
651
 
        user = self.create_user_and_login()
652
 
 
653
 
        topic = TestModel.objects.create(name='Test2')
654
 
        content_type = ContentType.objects.get_for_model(topic)
655
 
 
656
 
        parent = ThreadedComment.objects.create_for_object(topic,
657
 
                                                           user=user,
658
 
                                                           ip_address=u'127.0.0.1',
659
 
                                                           comment='My test comment!',
660
 
                                                           )
661
 
 
662
 
        url = reverse('tc_comment_parent', kwargs={
663
 
            'content_type': content_type.id,
664
 
            'object_id': topic.id,
665
 
            'parent_id': parent.id
666
 
        })
667
 
 
668
 
        response = self.client.post(url, {
669
 
            'comment': 'test10',
670
 
            'next': '/'
671
 
        })
672
 
        o = ThreadedComment.objects.latest(
673
 
            'date_submitted').get_base_data(show_dates=False)
674
 
        self.assertEquals(o, {
675
 
            'comment': u'test10',
676
 
            'is_approved': False,
677
 
            'parent': parent,
678
 
            'markup': u'plaintext',
679
 
            'content_object': topic,
680
 
            'user': user,
681
 
            'is_public': True,
682
 
            'ip_address': u'127.0.0.1',
683
 
        })
684
 
 
685
 
    def test_comment_child_json_create(self):
686
 
 
687
 
        user = self.create_user_and_login()
688
 
 
689
 
        topic = TestModel.objects.create(name='Test2')
690
 
        content_type = ContentType.objects.get_for_model(topic)
691
 
 
692
 
        parent = ThreadedComment.objects.create_for_object(topic,
693
 
                                                           user=user,
694
 
                                                           ip_address=u'127.0.0.1',
695
 
                                                           comment='My test comment!',
696
 
                                                           )
697
 
 
698
 
        url = reverse('tc_comment_parent_ajax', kwargs={
699
 
            'content_type': content_type.id,
700
 
            'object_id': topic.id,
701
 
            'parent_id': parent.id,
702
 
            'ajax': 'json'
703
 
        })
704
 
 
705
 
        response = self.client.post(url, {
706
 
            'comment': 'test11'
707
 
        })
708
 
        tmp = loads(response.content)
709
 
        o = ThreadedComment.objects.latest(
710
 
            'date_submitted').get_base_data(show_dates=False)
711
 
        self.assertEquals(o, {
712
 
            'comment': u'test11',
713
 
            'is_approved': False,
714
 
            'parent': parent,
715
 
            'markup': u'plaintext',
716
 
            'content_object': topic,
717
 
            'user': user,
718
 
            'is_public': True,
719
 
            'ip_address': u'127.0.0.1',
720
 
        })
721
 
 
722
 
    def test_comment_child_xml_create(self):
723
 
 
724
 
        user = self.create_user_and_login()
725
 
 
726
 
        topic = TestModel.objects.create(name='Test2')
727
 
        content_type = ContentType.objects.get_for_model(topic)
728
 
 
729
 
        parent = ThreadedComment.objects.create_for_object(topic,
730
 
                                                           user=user,
731
 
                                                           ip_address=u'127.0.0.1',
732
 
                                                           comment='My test comment!',
733
 
                                                           )
734
 
 
735
 
        url = reverse('tc_comment_parent_ajax', kwargs={
736
 
            'content_type': content_type.id,
737
 
            'object_id': topic.id,
738
 
            'parent_id': parent.id,
739
 
            'ajax': 'xml'
740
 
        })
741
 
 
742
 
        response = self.client.post(url, {
743
 
            'comment': 'test12'
744
 
        })
745
 
        tmp = parseString(response.content)
746
 
        o = ThreadedComment.objects.latest(
747
 
            'date_submitted').get_base_data(show_dates=False)
748
 
        self.assertEquals(o, {
749
 
            'comment': u'test12',
750
 
            'is_approved': False,
751
 
            'parent': parent,
752
 
            'markup': u'plaintext',
753
 
            'content_object': topic,
754
 
            'user': user,
755
 
            'is_public': True,
756
 
            'ip_address': u'127.0.0.1',
757
 
        })
758
 
 
759
 
    def test_freecomment_delete(self):
760
 
 
761
 
        user = User.objects.create_user(
762
 
            'testuser',
763
 
            'testuser@gmail.com',
764
 
            'password',
765
 
        )
766
 
        user.is_active = True
767
 
        user.save()
768
 
        self.client.login(username='testuser', password='password')
769
 
 
770
 
        topic = TestModel.objects.create(name='Test2')
771
 
 
772
 
        comment = FreeThreadedComment.objects.create_for_object(topic,
773
 
                                                                ip_address=u'127.0.0.1',
774
 
                                                                comment='My test comment!',
775
 
                                                                )
776
 
        deleted_id = comment.id
777
 
 
778
 
        url = reverse('tc_free_comment_delete', kwargs={
779
 
            'object_id': comment.id,
780
 
        })
781
 
 
782
 
        response = self.client.post(url, {'next': '/'})
783
 
        o = response['Location'].split(
784
 
            '?')[-1] == 'next=/freecomment/%d/delete/' % deleted_id
785
 
        self.assertEquals(o, True)
786
 
 
787
 
        # become super user and try deleting comment
788
 
        user.is_superuser = True
789
 
        user.save()
790
 
 
791
 
        response = self.client.post(url, {'next': '/'})
792
 
        self.assertEquals(response['Location'], 'http://testserver/')
793
 
        self.assertRaises(
794
 
            FreeThreadedComment.DoesNotExist,
795
 
            lambda: FreeThreadedComment.objects.get(id=deleted_id)
796
 
        )
797
 
 
798
 
        # re-create comment
799
 
        comment.save()
800
 
 
801
 
        response = self.client.get(url, {'next': '/'})
802
 
        self.assertEquals(len(response.content) > 0, True)
803
 
 
804
 
        o = FreeThreadedComment.objects.get(id=deleted_id) != None
805
 
        self.assertEquals(o, True)
806
 
 
807
 
    def test_comment_delete(self):
808
 
 
809
 
        some_other_guy = User.objects.create_user(
810
 
            'some_other_guy',
811
 
            'somewhere@overthemoon.com',
812
 
            'password1',
813
 
        )
814
 
        user = User.objects.create_user(
815
 
            'testuser',
816
 
            'testuser@gmail.com',
817
 
            'password',
818
 
        )
819
 
        user.is_active = True
820
 
        user.save()
821
 
        self.client.login(username='testuser', password='password')
822
 
 
823
 
        topic = TestModel.objects.create(name='Test2')
824
 
 
825
 
        comment = ThreadedComment.objects.create_for_object(topic,
826
 
                                                            user=some_other_guy,
827
 
                                                            ip_address=u'127.0.0.1',
828
 
                                                            comment='My test comment!',
829
 
                                                            )
830
 
        deleted_id = comment.id
831
 
 
832
 
        url = reverse('tc_comment_delete', kwargs={
833
 
            'object_id': comment.id,
834
 
        })
835
 
        response = self.client.post(url, {'next': '/'})
836
 
        self.assertEquals(response['Location'].split(
837
 
            '?')[-1], 'next=/comment/%s/delete/' % deleted_id)
838
 
 
839
 
        user.is_superuser = True
840
 
        user.save()
841
 
 
842
 
        response = self.client.post(url, {'next': '/'})
843
 
        self.assertEquals(response['Location'], 'http://testserver/')
844
 
        self.assertRaises(
845
 
            ThreadedComment.DoesNotExist,
846
 
            lambda: ThreadedComment.objects.get(id=deleted_id)
847
 
        )
848
 
 
849
 
        # re-create comment
850
 
        comment.save()
851
 
 
852
 
        response = self.client.get(url, {'next': '/'})
853
 
        self.assertEquals(len(response.content) > 0, True)
854
 
 
855
 
        o = ThreadedComment.objects.get(id=deleted_id) != None
856
 
        self.assertEquals(o, True)