~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to threadedcomments/tests/moderator_tests.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from threadedcomments.models import MARKDOWN, TEXTILE, REST, PLAINTEXT
9
9
 
10
10
 
11
 
__all__ = ("ModeratorTestCase",)
 
11
__all__ = ('ModeratorTestCase',)
12
12
 
13
13
 
14
14
class ModeratorTestCase(TestCase):
15
 
    
 
15
 
16
16
    def test_threadedcomment(self):
17
 
        topic = TestModel.objects.create(name = "Test")
18
 
        user = User.objects.create_user('user', 'floguy@gmail.com', password='password')
19
 
        user2 = User.objects.create_user('user2', 'floguy@gmail.com', password='password')
20
 
        
 
17
        topic = TestModel.objects.create(name='Test')
 
18
        user = User.objects.create_user(
 
19
            'user', 'floguy@gmail.com', password='password')
 
20
        user2 = User.objects.create_user(
 
21
            'user2', 'floguy@gmail.com', password='password')
 
22
 
21
23
        comment1 = ThreadedComment.objects.create_for_object(
22
 
            topic, user = user, ip_address = '127.0.0.1',
23
 
            comment = 'This is fun!  This is very fun!',
 
24
            topic, user=user, ip_address='127.0.0.1',
 
25
            comment='This is fun!  This is very fun!',
24
26
        )
25
27
        comment2 = ThreadedComment.objects.create_for_object(
26
 
            topic, user = user, ip_address = '127.0.0.1',
27
 
            comment = 'This is stupid!  I hate it!',
 
28
            topic, user=user, ip_address='127.0.0.1',
 
29
            comment='This is stupid!  I hate it!',
28
30
        )
29
31
        comment3 = ThreadedComment.objects.create_for_object(
30
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment2,
31
 
            comment = 'I agree, the first comment was wrong and you are right!',
 
32
            topic, user=user, ip_address='127.0.0.1', parent=comment2,
 
33
            comment='I agree, the first comment was wrong and you are right!',
32
34
        )
33
35
        comment4 = ThreadedComment.objects.create_for_object(
34
 
            topic, user = user, ip_address = '127.0.0.1',
35
 
            comment = 'What are we talking about?',
 
36
            topic, user=user, ip_address='127.0.0.1',
 
37
            comment='What are we talking about?',
36
38
        )
37
39
        comment5 = ThreadedComment.objects.create_for_object(
38
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment3,
39
 
            comment = "I'm a fanboy!",
 
40
            topic, user=user, ip_address='127.0.0.1', parent=comment3,
 
41
            comment="I'm a fanboy!",
40
42
        )
41
43
        comment6 = ThreadedComment.objects.create_for_object(
42
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment1,
43
 
            comment = "What are you talking about?",
 
44
            topic, user=user, ip_address='127.0.0.1', parent=comment1,
 
45
            comment='What are you talking about?',
44
46
        )
45
 
        
 
47
 
46
48
        class Moderator1(CommentModerator):
47
49
            enable_field = 'is_public'
48
50
            auto_close_field = 'date'
49
51
            close_after = 15
50
52
        moderator.register(TestModel, Moderator1)
51
 
        
 
53
 
52
54
        comment7 = ThreadedComment.objects.create_for_object(
53
 
            topic, user = user, ip_address = '127.0.0.1',
54
 
            comment = "Post moderator addition.  Does it still work?",
 
55
            topic, user=user, ip_address='127.0.0.1',
 
56
            comment='Post moderator addition.  Does it still work?',
55
57
        )
56
 
        
 
58
 
57
59
        topic.is_public = False
58
60
        topic.save()
59
 
        
 
61
 
60
62
        comment8 = ThreadedComment.objects.create_for_object(
61
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
62
 
            comment = "This should not appear, due to enable_field",
 
63
            topic, user=user, ip_address='127.0.0.1', parent=comment7,
 
64
            comment='This should not appear, due to enable_field',
63
65
        )
64
 
        
 
66
 
65
67
        moderator.unregister(TestModel)
66
 
        
 
68
 
67
69
        comment9 = ThreadedComment.objects.create_for_object(
68
 
            topic, user = user, ip_address = '127.0.0.1',
69
 
            comment = "This should appear again, due to unregistration",
 
70
            topic, user=user, ip_address='127.0.0.1',
 
71
            comment='This should appear again, due to unregistration',
70
72
        )
71
73
 
72
74
        self.assertEquals(len(mail.outbox), 0)
73
 
        
 
75
 
74
76
        ##################
75
 
        
 
77
 
76
78
        class Moderator2(CommentModerator):
77
79
            enable_field = 'is_public'
78
80
            auto_close_field = 'date'
80
82
            akismet = False
81
83
            email_notification = True
82
84
        moderator.register(TestModel, Moderator2)
83
 
        
 
85
 
84
86
        comment10 = ThreadedComment.objects.create_for_object(
85
 
            topic, user = user, ip_address = '127.0.0.1',
86
 
            comment = "This should not appear again, due to registration with a new manager.",
 
87
            topic, user=user, ip_address='127.0.0.1',
 
88
            comment='This should not appear again, due to registration with a new manager.',
87
89
        )
88
 
        
 
90
 
89
91
        topic.is_public = True
90
92
        topic.save()
91
 
        
 
93
 
92
94
        comment11 = ThreadedComment.objects.create_for_object(
93
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment1,
94
 
            comment = "This should appear again.",
 
95
            topic, user=user, ip_address='127.0.0.1', parent=comment1,
 
96
            comment='This should appear again.',
95
97
        )
96
 
        
 
98
 
97
99
        self.assertEquals(len(mail.outbox), 1)
98
100
        mail.outbox = []
99
 
        
100
 
        topic.date = topic.date - datetime.timedelta(days = 20)
 
101
 
 
102
        topic.date = topic.date - datetime.timedelta(days=20)
101
103
        topic.save()
102
 
        
 
104
 
103
105
        comment12 = ThreadedComment.objects.create_for_object(
104
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
105
 
            comment = "This shouldn't appear, due to close_after=15.",
 
106
            topic, user=user, ip_address='127.0.0.1', parent=comment7,
 
107
            comment="This shouldn't appear, due to close_after=15.",
106
108
        )
107
 
        
108
 
        topic.date = topic.date + datetime.timedelta(days = 20)
 
109
 
 
110
        topic.date = topic.date + datetime.timedelta(days=20)
109
111
        topic.save()
110
 
        
 
112
 
111
113
        moderator.unregister(TestModel)
112
 
        
 
114
 
113
115
        class Moderator3(CommentModerator):
114
116
            max_comment_length = 10
115
117
        moderator.register(TestModel, Moderator3)
116
 
        
 
118
 
117
119
        comment13 = ThreadedComment.objects.create_for_object(
118
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
119
 
            comment = "This shouldn't appear because it has more than 10 chars.",
 
120
            topic, user=user, ip_address='127.0.0.1', parent=comment7,
 
121
            comment="This shouldn't appear because it has more than 10 chars.",
120
122
        )
121
 
        
 
123
 
122
124
        comment14 = ThreadedComment.objects.create_for_object(
123
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
124
 
            comment = "<10chars",
 
125
            topic, user=user, ip_address='127.0.0.1', parent=comment7,
 
126
            comment='<10chars',
125
127
        )
126
 
        
 
128
 
127
129
        moderator.unregister(TestModel)
128
 
        
 
130
 
129
131
        class Moderator4(CommentModerator):
130
 
            allowed_markup = [REST,]
 
132
            allowed_markup = [REST, ]
131
133
        moderator.register(TestModel, Moderator4)
132
 
        
 
134
 
133
135
        comment15 = ThreadedComment.objects.create_for_object(
134
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
135
 
            comment = "INVALID Markup.  Should not show up.", markup=TEXTILE
 
136
            topic, user=user, ip_address='127.0.0.1', parent=comment7,
 
137
            comment='INVALID Markup.  Should not show up.', markup=TEXTILE
136
138
        )
137
 
        
 
139
 
138
140
        comment16 = ThreadedComment.objects.create_for_object(
139
 
            topic, user = user, ip_address = '127.0.0.1', parent = comment7,
140
 
            comment = "VALID Markup.  Should show up.", markup=REST
 
141
            topic, user=user, ip_address='127.0.0.1', parent=comment7,
 
142
            comment='VALID Markup.  Should show up.', markup=REST
141
143
        )
142
 
        
 
144
 
143
145
        moderator.unregister(TestModel)
144
 
        
 
146
 
145
147
        tree = ThreadedComment.public.get_tree(topic)
146
148
        output = []
147
149
        for comment in tree:
148
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
149
 
        self.assertEquals("\n".join(output),
150
 
"""
 
150
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
151
        self.assertEquals('\n'.join(output),
 
152
                          """
151
153
This is fun!  This is very fun!
152
154
    What are you talking about?
153
155
    This should appear again.
164
166
        tree = ThreadedComment.objects.get_tree(topic)
165
167
        output = []
166
168
        for comment in tree:
167
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
168
 
        self.assertEquals("\n".join(output),
169
 
"""
 
169
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
170
        self.assertEquals('\n'.join(output),
 
171
                          """
170
172
This is fun!  This is very fun!
171
173
    What are you talking about?
172
174
    This should appear again.
180
182
    VALID Markup.  Should show up.
181
183
This should appear again, due to unregistration
182
184
""".lstrip())
183
 
        
 
185
 
184
186
        tree = ThreadedComment.objects.get_tree(topic, root=comment2)
185
187
        output = []
186
188
        for comment in tree:
187
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
188
 
        self.assertEquals("\n".join(output),
189
 
"""
 
189
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
190
        self.assertEquals('\n'.join(output),
 
191
                          """
190
192
This is stupid!  I hate it!
191
193
    I agree, the first comment was wrong and you are right!
192
194
        I'm a fanboy!
193
195
""".lstrip())
194
 
        
 
196
 
195
197
        tree = ThreadedComment.objects.get_tree(topic, root=comment2.id)
196
198
        for comment in tree:
197
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
198
 
        self.assertEquals("\n".join(output),
199
 
"""
 
199
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
200
        self.assertEquals('\n'.join(output),
 
201
                          """
200
202
This is stupid!  I hate it!
201
203
    I agree, the first comment was wrong and you are right!
202
204
        I'm a fanboy!
203
205
""".lstrip())
204
 
        
 
206
 
205
207
    def test_freethreadedcomment(self):
206
 
        
 
208
 
207
209
        ###########################
208
210
        ### FreeThreadedComment ###
209
211
        ###########################
210
 
        
 
212
 
211
213
        fcomment1 = FreeThreadedComment.objects.create_for_object(
212
 
            topic, name = "Eric", ip_address = '127.0.0.1',
213
 
            comment = 'This is fun!  This is very fun!',
 
214
            topic, name='Eric', ip_address='127.0.0.1',
 
215
            comment='This is fun!  This is very fun!',
214
216
        )
215
217
        fcomment2 = FreeThreadedComment.objects.create_for_object(
216
 
            topic, name = "Eric", ip_address = '127.0.0.1',
217
 
            comment = 'This is stupid!  I hate it!',
 
218
            topic, name='Eric', ip_address='127.0.0.1',
 
219
            comment='This is stupid!  I hate it!',
218
220
        )
219
221
        fcomment3 = FreeThreadedComment.objects.create_for_object(
220
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment2,
221
 
            comment = 'I agree, the first comment was wrong and you are right!',
 
222
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment2,
 
223
            comment='I agree, the first comment was wrong and you are right!',
222
224
        )
223
225
        fcomment4 = FreeThreadedComment.objects.create_for_object(
224
 
            topic, name = "Eric", ip_address = '127.0.0.1', 
225
 
            website="http://www.eflorenzano.com/", email="floguy@gmail.com",
226
 
            comment = 'What are we talking about?',
 
226
            topic, name='Eric', ip_address='127.0.0.1',
 
227
            website='http://www.eflorenzano.com/', email='floguy@gmail.com',
 
228
            comment='What are we talking about?',
227
229
        )
228
230
        fcomment5 = FreeThreadedComment.objects.create_for_object(
229
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment3,
230
 
            comment = "I'm a fanboy!",
 
231
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment3,
 
232
            comment="I'm a fanboy!",
231
233
        )
232
234
        fcomment6 = FreeThreadedComment.objects.create_for_object(
233
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment1,
234
 
            comment = "What are you talking about?",
 
235
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment1,
 
236
            comment='What are you talking about?',
235
237
        )
236
 
        
 
238
 
237
239
        moderator.register(TestModel, Moderator1)
238
 
        
 
240
 
239
241
        fcomment7 = FreeThreadedComment.objects.create_for_object(
240
 
            topic, name = "Eric", ip_address = '127.0.0.1',
241
 
            comment = "Post moderator addition.  Does it still work?",
 
242
            topic, name='Eric', ip_address='127.0.0.1',
 
243
            comment='Post moderator addition.  Does it still work?',
242
244
        )
243
 
        
 
245
 
244
246
        topic.is_public = False
245
247
        topic.save()
246
 
        
 
248
 
247
249
        fcomment8 = FreeThreadedComment.objects.create_for_object(
248
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
249
 
            comment = "This should not appear, due to enable_field",
 
250
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment7,
 
251
            comment='This should not appear, due to enable_field',
250
252
        )
251
 
        
 
253
 
252
254
        moderator.unregister(TestModel)
253
 
        
 
255
 
254
256
        fcomment9 = FreeThreadedComment.objects.create_for_object(
255
 
            topic, name = "Eric", ip_address = '127.0.0.1',
256
 
            comment = "This should appear again, due to unregistration",
 
257
            topic, name='Eric', ip_address='127.0.0.1',
 
258
            comment='This should appear again, due to unregistration',
257
259
        )
258
 
        
 
260
 
259
261
        self.assertEquals(len(mail.outbox), 0)
260
262
 
261
263
        moderator.register(TestModel, Moderator2)
262
 
        
 
264
 
263
265
        fcomment10 = FreeThreadedComment.objects.create_for_object(
264
 
            topic, name = "Eric", ip_address = '127.0.0.1',
265
 
            comment = "This should not appear again, due to registration with a new manager.",
 
266
            topic, name='Eric', ip_address='127.0.0.1',
 
267
            comment='This should not appear again, due to registration with a new manager.',
266
268
        )
267
 
        
 
269
 
268
270
        topic.is_public = True
269
271
        topic.save()
270
 
        
 
272
 
271
273
        fcomment11 = FreeThreadedComment.objects.create_for_object(
272
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment1,
273
 
            comment = "This should appear again.",
 
274
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment1,
 
275
            comment='This should appear again.',
274
276
        )
275
 
        
 
277
 
276
278
        self.assertEquals(len(mail.outbox), 1)
277
 
        
 
279
 
278
280
        mail.outbox = []
279
 
        
280
 
        topic.date = topic.date - datetime.timedelta(days = 20)
 
281
 
 
282
        topic.date = topic.date - datetime.timedelta(days=20)
281
283
        topic.save()
282
 
        
 
284
 
283
285
        fcomment12 = FreeThreadedComment.objects.create_for_object(
284
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
285
 
            comment = "This shouldn't appear, due to close_after=15.",
 
286
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment7,
 
287
            comment="This shouldn't appear, due to close_after=15.",
286
288
        )
287
 
        
288
 
        topic.date = topic.date + datetime.timedelta(days = 20)
 
289
 
 
290
        topic.date = topic.date + datetime.timedelta(days=20)
289
291
        topic.save()
290
 
        
 
292
 
291
293
        moderator.unregister(TestModel)
292
294
        moderator.register(TestModel, Moderator3)
293
 
        
 
295
 
294
296
        fcomment13 = FreeThreadedComment.objects.create_for_object(
295
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
296
 
            comment = "This shouldn't appear because it has more than 10 chars.",
 
297
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment7,
 
298
            comment="This shouldn't appear because it has more than 10 chars.",
297
299
        )
298
 
        
 
300
 
299
301
        fcomment14 = FreeThreadedComment.objects.create_for_object(
300
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
301
 
            comment = "<10chars",
 
302
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment7,
 
303
            comment='<10chars',
302
304
        )
303
 
        
 
305
 
304
306
        moderator.unregister(TestModel)
 
307
 
305
308
        class Moderator5(CommentModerator):
306
 
            allowed_markup = [REST,]
 
309
            allowed_markup = [REST, ]
307
310
            max_depth = 3
308
311
        moderator.register(TestModel, Moderator5)
309
 
        
 
312
 
310
313
        fcomment15 = FreeThreadedComment.objects.create_for_object(
311
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment7,
312
 
            comment = "INVALID Markup.  Should not show up.", markup=TEXTILE
 
314
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment7,
 
315
            comment='INVALID Markup.  Should not show up.', markup=TEXTILE
313
316
        )
314
 
        
 
317
 
315
318
        fcomment16 = FreeThreadedComment.objects.create_for_object(
316
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = None,
317
 
            comment = "VALID Markup.  Should show up.", markup=REST
 
319
            topic, name='Eric', ip_address='127.0.0.1', parent=None,
 
320
            comment='VALID Markup.  Should show up.', markup=REST
318
321
        )
319
 
        
 
322
 
320
323
        fcomment17 = FreeThreadedComment.objects.create_for_object(
321
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment16,
322
 
            comment = "Building Depth...Should Show Up.", markup=REST
 
324
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment16,
 
325
            comment='Building Depth...Should Show Up.', markup=REST
323
326
        )
324
 
        
 
327
 
325
328
        fcomment18 = FreeThreadedComment.objects.create_for_object(
326
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment17,
327
 
            comment = "More Depth...Should Show Up.", markup=REST
 
329
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment17,
 
330
            comment='More Depth...Should Show Up.', markup=REST
328
331
        )
329
 
        
 
332
 
330
333
        fcomment19 = FreeThreadedComment.objects.create_for_object(
331
 
            topic, name = "Eric", ip_address = '127.0.0.1', parent = fcomment18,
332
 
            comment = "Too Deep..Should NOT Show UP", markup=REST
 
334
            topic, name='Eric', ip_address='127.0.0.1', parent=fcomment18,
 
335
            comment='Too Deep..Should NOT Show UP', markup=REST
333
336
        )
334
 
        
 
337
 
335
338
        moderator.unregister(TestModel)
336
 
        
 
339
 
337
340
        tree = FreeThreadedComment.public.get_tree(topic)
338
341
        output = []
339
342
        for comment in tree:
340
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
341
 
        self.assertEquals("\n".join(output),
342
 
"""
 
343
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
344
        self.assertEquals('\n'.join(output),
 
345
                          """
343
346
This is fun!  This is very fun!
344
347
    What are you talking about?
345
348
    This should appear again.
354
357
    Building Depth...Should Show Up.
355
358
        More Depth...Should Show Up.
356
359
""".lstrip())
357
 
        
 
360
 
358
361
        tree = FreeThreadedComment.objects.get_tree(topic)
359
362
        output = []
360
363
        for comment in tree:
361
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
362
 
        self.assertEquals("\n".join(output),
363
 
"""
 
364
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
365
        self.assertEquals('\n'.join(output),
 
366
                          """
364
367
This is fun!  This is very fun!
365
368
    What are you talking about?
366
369
    This should appear again.
376
379
    Building Depth...Should Show Up.
377
380
        More Depth...Should Show Up.
378
381
""".lstrip())
379
 
        
 
382
 
380
383
        tree = FreeThreadedComment.objects.get_tree(topic, root=comment2)
381
384
        output = []
382
385
        for comment in tree:
383
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
384
 
        self.assertEquals("\n".join(output),
385
 
"""
 
386
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
387
        self.assertEquals('\n'.join(output),
 
388
                          """
386
389
This is stupid!  I hate it!
387
390
    I agree, the first comment was wrong and you are right!
388
391
        I'm a fanboy!
389
392
""".lstrip())
390
 
        
 
393
 
391
394
        tree = FreeThreadedComment.objects.get_tree(topic, root=comment2.id)
392
395
        output = []
393
396
        for comment in tree:
394
 
            output.append("%s %s" % ("    " * comment.depth, comment.comment))
395
 
        self.assertEquals("\n".join(output),
396
 
"""
 
397
            output.append('%s %s' % ('    ' * comment.depth, comment.comment))
 
398
        self.assertEquals('\n'.join(output),
 
399
                          """
397
400
This is stupid!  I hate it!
398
401
    I agree, the first comment was wrong and you are right!
399
402
        I'm a fanboy!