~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to threadedcomments/tests/views_tests.py

  • Committer: Holger Rapp
  • Date: 2016-08-08 10:06:42 UTC
  • mto: This revision was merged to the branch mainline in revision 419.
  • Revision ID: sirver@gmx.de-20160808100642-z62vwqitxoyl5fh4
Added the apt-get update script I run every 30 days.

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