def test_add_comment(self): """The add_comment procedure adds a new comment for a user Test relies on list_comments_user working properly""" useremail = "*****@*****.**" page = "http://example.com/" firstcomment = "First Comment" secondcomment = "Second Comment" interface.add_comment(self.db, useremail, page, firstcomment) # now retrieve the info and verify comments = interface.list_comments_user(self.db, useremail) # our comment should be the first i, e, p, c = comments[0] self.assertEquals( (useremail, page, firstcomment), (e, p, c), "Stored comment not found first in comments list, got %s instead" % str(comments[0])) # do it again to check we don't lose the above interface.add_comment(self.db, useremail, page, secondcomment) # now retrieve the info and verify comments = interface.list_comments_user(self.db, useremail) # our comment should be the first i, e, p, c = comments[0] self.assertEquals((useremail, page, secondcomment), ( e, p, c ), "Second stored comment not found first in comments list, got %s instead" % str(comments[0])) i, e, p, c = comments[1] self.assertEquals((useremail, page, firstcomment), ( e, p, c ), "First stored comment not found second in comments list, got %s instead" % str(comments[0]))
def my_comments(environ, start_response): # Page to look at your own comments. username = interface.user_from_cookie(db, environ) user_details = interface.get_user_details(db, username) my_page_text = "<H1> Welcome back %s! </H1><BR><H2> Your recent comments </H2>" % (user_details[0]) my_page_comments = comments(interface.list_comments_user(db, username)) headers = [('content-type', 'text/html')] start_response('200 OK', headers) page = ["<HTML>", css, topnav(environ), my_page_text, my_page_comments, "</DIV></HTML>" ] return page
def test_add_comment(self): """The add_comment procedure adds a new comment for a user Test relies on list_comments_user working properly""" useremail = "*****@*****.**" page = "http://example.com/" firstcomment = "First Comment" secondcomment = "Second Comment" interface.add_comment(self.db, useremail, page, firstcomment) # now retrieve the info and verify comments = interface.list_comments_user(self.db, useremail) # our comment should be the first i, e, p, c = comments[0] self.assertEquals( (useremail, page, firstcomment), (e, p, c), "Stored comment not found first in comments list, got %s instead" % str(comments[0]), ) # do it again to check we don't lose the above interface.add_comment(self.db, useremail, page, secondcomment) # now retrieve the info and verify comments = interface.list_comments_user(self.db, useremail) # our comment should be the first i, e, p, c = comments[0] self.assertEquals( (useremail, page, secondcomment), (e, p, c), "Second stored comment not found first in comments list, got %s instead" % str(comments[0]), ) i, e, p, c = comments[1] self.assertEquals( (useremail, page, firstcomment), (e, p, c), "First stored comment not found second in comments list, got %s instead" % str(comments[0]), )
def my_comments(environ, start_response): # Page to look at your own comments. username = interface.user_from_cookie(db, environ) user_details = interface.get_user_details(db, username) my_page_text = "<H1> Welcome back %s! </H1><BR><H2> Your recent comments </H2>" % ( user_details[0]) my_page_comments = comments(interface.list_comments_user(db, username)) headers = [('content-type', 'text/html')] start_response('200 OK', headers) page = [ "<HTML>", css, topnav(environ), my_page_text, my_page_comments, "</DIV></HTML>" ] return page
def test_list_comments_user(self): """The list_comments_user procedure should return a list of tuples one for each of the comment entries in the database entered by the given user, each tuple should contain e""" # grab a test user email address testuser = self.users[0][0] comments = interface.list_comments_user(self.db, testuser) # this time only those where the user is our test user refcomments = [u for u in self.comments if u[1] == testuser] # we should have the same units in self.units self.assertEquals( len(comments), len(refcomments), "Wrong number of comments returned from list_comments_user") # check that all comments in our list are present in the returned list for comment in refcomments: self.assertTrue( comment in comments, "Didn't find comment %s in list returned from list_comments_user %s" % (comment, comments)) # comments should be in order so the largest id should be first self.assertEquals( refcomments[-1][0], comments[0][0], "Wrong comment id first in comment list, expected %d, got %d" % (refcomments[-1][0], comments[0][0])) # and the comment list should be ordered by id ids = [c[0] for c in comments] self.assertEqual( sorted(ids, reverse=True), ids, "List of comments returned is not in large-to-small order: %s" % (ids, ))
def test_list_comments_user(self): """The list_comments_user procedure should return a list of tuples one for each of the comment entries in the database entered by the given user, each tuple should contain e""" # grab a test user email address testuser = self.users[0][0] comments = interface.list_comments_user(self.db, testuser) # this time only those where the user is our test user refcomments = [u for u in self.comments if u[1] == testuser] # we should have the same units in self.units self.assertEquals(len(comments), len(refcomments), "Wrong number of comments returned from list_comments_user") # check that all comments in our list are present in the returned list for comment in refcomments: self.assertTrue( comment in comments, "Didn't find comment %s in list returned from list_comments_user %s" % (comment, comments), ) # comments should be in order so the largest id should be first self.assertEquals( refcomments[-1][0], comments[0][0], "Wrong comment id first in comment list, expected %d, got %d" % (refcomments[-1][0], comments[0][0]), ) # and the comment list should be ordered by id ids = [c[0] for c in comments] self.assertEqual( sorted(ids, reverse=True), ids, "List of comments returned is not in large-to-small order: %s" % (ids,) )