def test_add_and_remove_shout(self): # commenter1 posts a shout on owner's page c1 = shout.insert(self.commenter1, orm.Comment(userid=self.owner, content="hello")) self.assertEqual(1, self.count_notifications(self.owner)) # commenter2 posts a reply to c1 c2 = shout.insert(self.commenter2, orm.Comment(userid=self.owner, content="hello", parentid=c1)) self.assertEqual(1, self.count_notifications(self.commenter1)) # owner posts a reply to c2 c3 = shout.insert(self.owner, orm.Comment(userid=self.owner, content="hello", parentid=c2)) self.assertEqual(1, self.count_notifications(self.commenter2)) # commenter1 responds to owner shout.insert(self.commenter1, orm.Comment(userid=self.owner, content="hello", parentid=c3)) self.assertEqual(2, self.count_notifications(self.owner)) # owner deletes comment thread shout.remove(self.owner, commentid=c1) self.assertEqual(0, self.count_notifications(self.owner)) self.assertEqual(0, self.count_notifications(self.commenter1)) self.assertEqual(0, self.count_notifications(self.commenter2))
def submit_shout_(request): form = request.web_input(userid="", parentid="", content="", staffnotes="", format="") if form.staffnotes and request.userid not in staff.MODS: raise WeasylError("InsufficientPermissions") c = orm.Comment() c.parentid = define.get_int(form.parentid) c.userid = define.get_int(form.userid or form.staffnotes) c.content = form.content commentid = shout.insert(request.userid, c, staffnotes=form.staffnotes) if form.format == "json": return {"id": commentid} if form.staffnotes: raise HTTPSeeOther(location='/staffnotes?userid=%i#cid%i' % (define.get_int(form.staffnotes), commentid)) else: raise HTTPSeeOther(location="/shouts?userid=%i#cid%i" % (define.get_int(form.userid), commentid))
def POST(self): form = web.input(userid="", parentid="", content="", staffnotes="", format="") if form.staffnotes and self.user_id not in staff.MODS: raise WeasylError("InsufficientPermissions") c = orm.Comment() c.parentid = define.get_int(form.parentid) c.userid = define.get_int(form.userid or form.staffnotes) c.content = form.content commentid = shout.insert(self.user_id, c, staffnotes=form.staffnotes) if form.format == "json": return {"id": commentid} if form.staffnotes: raise web.seeother('/staffnotes?userid=%i#cid%i' % (define.get_int(form.staffnotes), commentid)) else: raise web.seeother("/shouts?userid=%i#cid%i" % (define.get_int(form.userid), commentid))
def submit_shout_(request): form = request.web_input(userid="", parentid="", content="", staffnotes="", format="") if form.staffnotes and request.userid not in staff.MODS: raise WeasylError("InsufficientPermissions") if not define.is_vouched_for(request.userid): raise WeasylError("vouchRequired") commentid = shout.insert( request.userid, target_user=define.get_int(form.userid or form.staffnotes), parentid=define.get_int(form.parentid), content=form.content, staffnotes=bool(form.staffnotes), ) if form.format == "json": return {"id": commentid} if form.staffnotes: raise HTTPSeeOther(location='/staffnotes?userid=%i#cid%i' % (define.get_int(form.staffnotes), commentid)) else: raise HTTPSeeOther(location="/shouts?userid=%i#cid%i" % (define.get_int(form.userid), commentid))
def test_add_and_remove_shout(self): # commenter1 posts a shout on owner's page c1 = shout.insert(self.commenter1, target_user=self.owner, parentid=None, content="hello", staffnotes=False) self.assertEqual(1, self.count_notifications(self.owner)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 1) self.assertTrue( shouts[0].viewitems() >= {"content": "hello"}.viewitems()) # commenter2 posts a reply to c1 c2 = shout.insert(self.commenter2, target_user=self.owner, parentid=c1, content="reply", staffnotes=False) self.assertEqual(1, self.count_notifications(self.commenter1)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 2) self.assertTrue( shouts[1].viewitems() >= {"content": "reply"}.viewitems()) # owner posts a reply to c2 c3 = shout.insert(self.owner, target_user=self.owner, parentid=c2, content="reply 2", staffnotes=False) self.assertEqual(1, self.count_notifications(self.commenter2)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 3) self.assertTrue( shouts[2].viewitems() >= {"content": "reply 2"}.viewitems()) # commenter1 responds to owner shout.insert(self.commenter1, target_user=self.owner, parentid=c3, content="reply 3", staffnotes=False) self.assertEqual(2, self.count_notifications(self.owner)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 4) self.assertTrue( shouts[3].viewitems() >= {"content": "reply 3"}.viewitems()) # commenter1 posts a new root shout shout.insert(self.commenter1, target_user=self.owner, parentid=None, content="root 2", staffnotes=False) self.assertEqual(3, self.count_notifications(self.owner)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 5) self.assertTrue( shouts[0].viewitems() >= {"content": "root 2"}.viewitems()) self.assertTrue( shouts[4].viewitems() >= {"content": "reply 3"}.viewitems()) # commenter2 posts another reply to c1 shout.insert(self.commenter2, target_user=self.owner, parentid=c1, content="reply 4", staffnotes=False) self.assertEqual(2, self.count_notifications(self.commenter1)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 6) self.assertTrue( shouts[5].viewitems() >= {"content": "reply 4"}.viewitems()) # owner deletes comment thread shout.remove(self.owner, commentid=c1) self.assertEqual(1, self.count_notifications(self.owner)) self.assertEqual(0, self.count_notifications(self.commenter1)) self.assertEqual(0, self.count_notifications(self.commenter2)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 1) self.assertTrue( shouts[0].viewitems() >= {"content": "root 2"}.viewitems())
def test_add_and_remove_shout(self): # commenter1 posts a shout on owner's page c1 = shout.insert(self.commenter1, orm.Comment(userid=self.owner, content="hello")) self.assertEqual(1, self.count_notifications(self.owner)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 1) self.assertTrue(shouts[0].viewitems() >= {"content": "hello"}.viewitems()) # commenter2 posts a reply to c1 c2 = shout.insert(self.commenter2, orm.Comment(userid=self.owner, content="reply", parentid=c1)) self.assertEqual(1, self.count_notifications(self.commenter1)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 2) self.assertTrue(shouts[1].viewitems() >= {"content": "reply"}.viewitems()) # owner posts a reply to c2 c3 = shout.insert(self.owner, orm.Comment(userid=self.owner, content="reply 2", parentid=c2)) self.assertEqual(1, self.count_notifications(self.commenter2)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 3) self.assertTrue(shouts[2].viewitems() >= {"content": "reply 2"}.viewitems()) # commenter1 responds to owner shout.insert(self.commenter1, orm.Comment(userid=self.owner, content="reply 3", parentid=c3)) self.assertEqual(2, self.count_notifications(self.owner)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 4) self.assertTrue(shouts[3].viewitems() >= {"content": "reply 3"}.viewitems()) # commenter1 posts a new root shout shout.insert(self.commenter1, orm.Comment(userid=self.owner, content="root 2")) self.assertEqual(3, self.count_notifications(self.owner)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 5) self.assertTrue(shouts[0].viewitems() >= {"content": "root 2"}.viewitems()) self.assertTrue(shouts[4].viewitems() >= {"content": "reply 3"}.viewitems()) # commenter2 posts another reply to c1 shout.insert(self.commenter2, orm.Comment(userid=self.owner, content="reply 4", parentid=c1)) self.assertEqual(2, self.count_notifications(self.commenter1)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 6) self.assertTrue(shouts[5].viewitems() >= {"content": "reply 4"}.viewitems()) # owner deletes comment thread shout.remove(self.owner, commentid=c1) self.assertEqual(1, self.count_notifications(self.owner)) self.assertEqual(0, self.count_notifications(self.commenter1)) self.assertEqual(0, self.count_notifications(self.commenter2)) shouts = shout.select(0, self.owner) self.assertEqual(len(shouts), 1) self.assertTrue(shouts[0].viewitems() >= {"content": "root 2"}.viewitems())