~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to threadedcomments/tests/views_tests.py

  • Committer: franku
  • Author(s): GunChleoc
  • Date: 2016-12-13 18:30:38 UTC
  • mfrom: (438.1.6 pyformat_util)
  • Revision ID: somal@arcor.de-20161213183038-5cgmvfh2fkgmoc1s
adding a script to run pyformat over the code base

Show diffs side-by-side

added added

removed removed

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