8
8
from threadedcomments.models import MARKDOWN, TEXTILE, REST, PLAINTEXT
11
__all__ = ("ModeratorTestCase",)
11
__all__ = ('ModeratorTestCase',)
14
14
class ModeratorTestCase(TestCase):
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')
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')
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!',
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!',
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!',
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?',
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!",
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?',
46
48
class Moderator1(CommentModerator):
47
49
enable_field = 'is_public'
48
50
auto_close_field = 'date'
50
52
moderator.register(TestModel, Moderator1)
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?',
57
59
topic.is_public = False
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',
65
67
moderator.unregister(TestModel)
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',
72
74
self.assertEquals(len(mail.outbox), 0)
76
78
class Moderator2(CommentModerator):
77
79
enable_field = 'is_public'
78
80
auto_close_field = 'date'
81
83
email_notification = True
82
84
moderator.register(TestModel, Moderator2)
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.',
89
91
topic.is_public = True
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.',
97
99
self.assertEquals(len(mail.outbox), 1)
100
topic.date = topic.date - datetime.timedelta(days = 20)
102
topic.date = topic.date - datetime.timedelta(days=20)
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.",
108
topic.date = topic.date + datetime.timedelta(days = 20)
110
topic.date = topic.date + datetime.timedelta(days=20)
111
113
moderator.unregister(TestModel)
113
115
class Moderator3(CommentModerator):
114
116
max_comment_length = 10
115
117
moderator.register(TestModel, Moderator3)
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.",
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,
127
129
moderator.unregister(TestModel)
129
131
class Moderator4(CommentModerator):
130
allowed_markup = [REST,]
132
allowed_markup = [REST, ]
131
133
moderator.register(TestModel, Moderator4)
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
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
143
145
moderator.unregister(TestModel)
145
147
tree = ThreadedComment.public.get_tree(topic)
147
149
for comment in tree:
148
output.append("%s %s" % (" " * comment.depth, comment.comment))
149
self.assertEquals("\n".join(output),
150
output.append('%s %s' % (' ' * comment.depth, comment.comment))
151
self.assertEquals('\n'.join(output),
151
153
This is fun! This is very fun!
152
154
What are you talking about?
153
155
This should appear again.
180
182
VALID Markup. Should show up.
181
183
This should appear again, due to unregistration
184
186
tree = ThreadedComment.objects.get_tree(topic, root=comment2)
186
188
for comment in tree:
187
output.append("%s %s" % (" " * comment.depth, comment.comment))
188
self.assertEquals("\n".join(output),
189
output.append('%s %s' % (' ' * comment.depth, comment.comment))
190
self.assertEquals('\n'.join(output),
190
192
This is stupid! I hate it!
191
193
I agree, the first comment was wrong and you are right!
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
output.append('%s %s' % (' ' * comment.depth, comment.comment))
200
self.assertEquals('\n'.join(output),
200
202
This is stupid! I hate it!
201
203
I agree, the first comment was wrong and you are right!
205
207
def test_freethreadedcomment(self):
207
209
###########################
208
210
### FreeThreadedComment ###
209
211
###########################
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!',
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!',
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!',
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?',
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!",
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?',
237
239
moderator.register(TestModel, Moderator1)
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?',
244
246
topic.is_public = False
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',
252
254
moderator.unregister(TestModel)
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',
259
261
self.assertEquals(len(mail.outbox), 0)
261
263
moderator.register(TestModel, Moderator2)
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.',
268
270
topic.is_public = True
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.',
276
278
self.assertEquals(len(mail.outbox), 1)
280
topic.date = topic.date - datetime.timedelta(days = 20)
282
topic.date = topic.date - datetime.timedelta(days=20)
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.",
288
topic.date = topic.date + datetime.timedelta(days = 20)
290
topic.date = topic.date + datetime.timedelta(days=20)
291
293
moderator.unregister(TestModel)
292
294
moderator.register(TestModel, Moderator3)
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.",
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,
304
306
moderator.unregister(TestModel)
305
308
class Moderator5(CommentModerator):
306
allowed_markup = [REST,]
309
allowed_markup = [REST, ]
308
311
moderator.register(TestModel, Moderator5)
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
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
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
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
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
335
338
moderator.unregister(TestModel)
337
340
tree = FreeThreadedComment.public.get_tree(topic)
339
342
for comment in tree:
340
output.append("%s %s" % (" " * comment.depth, comment.comment))
341
self.assertEquals("\n".join(output),
343
output.append('%s %s' % (' ' * comment.depth, comment.comment))
344
self.assertEquals('\n'.join(output),
343
346
This is fun! This is very fun!
344
347
What are you talking about?
345
348
This should appear again.