def testEditCommentByBannedUserStatus(self): ban = CommentsBannedFromIpAddress(ip_address='127.0.0.1') ban.save() self.client.login(username='******', password='******') response = self.client.post('/comments/edit/', data={'comment': 'changed', 'comment_id': '1'}) self.assertEquals(response.status_code, 400)
def testDeleteCommentByBannedUserResult(self): ban = CommentsBannedFromIpAddress(ip_address='127.0.0.1') ban.save() self.client.login(username='******', password='******') self.client.post('/comments/delete_comment/1/') oc = OslComment.objects.get(pk=1) self.assertEquals(oc.is_deleted_by_user, False)
def testEditCommentByBannedUserResult(self): ban = CommentsBannedFromIpAddress(ip_address='127.0.0.1') ban.save() self.client.login(username='******', password='******') self.client.post('/comments/edit/', data={'comment': 'changed', 'comment_id': '1'}) oc = OslComment.objects.get(pk=1) self.assertEquals(oc.comment, u'First!')
def update_ip_address_ban(request, comment_id, next=None): comment = get_object_or_404(OslComment, pk=comment_id) if request.method == 'GET': banned = \ CommentsBannedFromIpAddress.objects.is_banned(comment.ip_address) return render_to_response('comments/update_ip_address_ban.html', {'banned': banned}, RequestContext(request) ) if request.method == 'POST': data = request.POST banned_str = data.get('ban', None) if banned_str == 'True': banned = True elif banned_str == 'False': banned = False else: return HttpResponseBadRequest() try: ban = CommentsBannedFromIpAddress.objects.get( ip_address=comment.ip_address) except CommentsBannedFromIpAddress.DoesNotExist: ban = CommentsBannedFromIpAddress(ip_address=comment.ip_address) ban.comments_banned = banned ban.save() signals.ip_address_ban_was_updated.send( sender = comment.__class__, banned = banned, request = request ) return next_redirect(request.POST.copy(), next, update_ip_address_ban_done)
def testBannedFromCommentingNoCommentsArticleAccess(self): ban = CommentsBannedFromIpAddress(ip_address='127.0.0.1') ban.save() response = self.client.get('/articles/view/no-comments/') self.assertEquals(response.status_code, 200)
def testDeleteCommentByBannedUserStatus(self): ban = CommentsBannedFromIpAddress(ip_address='127.0.0.1') ban.save() self.client.login(username='******', password='******') response = self.client.post('/comments/delete_comment/1/') self.assertEquals(response.status_code, 403)