Beispiel #1
0
    def test_list_comments(self):
        """The list_comments procedure should return a list of tuples
        one for each of the comment entries in the database, each tuple
        should contain """

        clist = interface.list_comments(self.db)

        # we should have the same number of comments as we created
        self.assertEquals(
            len(clist), len(self.comments),
            "Wrong number of comments returned from list_units, expected %d, got %d"
            % (len(self.comments), len(clist)))

        # comments should be in order so the largest id should be first
        self.assertEquals(
            clist[0][0], self.comments[-1][0],
            "Wrong comment id first in comment list, expected %d, got %d" %
            (clist[0][0], self.comments[-1][0]))

        # and the comment list should be ordered by id
        ids = [c[0] for c in clist]
        self.assertEqual(
            sorted(ids, reverse=True), ids,
            "List of comments returned is not in large-to-small order: %s" %
            (ids, ))

        # try the limit argument
        clist = interface.list_comments(self.db, 3)
        self.assertEquals(
            len(clist), 3,
            "Wrong number of comments returned from list_comments with a limit argument, expected 3, got %d"
            % (len(clist), ))
    def test_list_comments(self):
        """The list_comments procedure should return a list of tuples
        one for each of the comment entries in the database, each tuple
        should contain """

        clist = interface.list_comments(self.db)

        # we should have the same number of comments as we created
        self.assertEquals(
            len(clist),
            len(self.comments),
            "Wrong number of comments returned from list_units, expected %d, got %d" % (len(self.comments), len(clist)),
        )

        # comments should be in order so the largest id should be first
        self.assertEquals(
            clist[0][0],
            self.comments[-1][0],
            "Wrong comment id first in comment list, expected %d, got %d" % (clist[0][0], self.comments[-1][0]),
        )

        # and the comment list should be ordered by id
        ids = [c[0] for c in clist]
        self.assertEqual(
            sorted(ids, reverse=True), ids, "List of comments returned is not in large-to-small order: %s" % (ids,)
        )

        # try the limit argument
        clist = interface.list_comments(self.db, 3)
        self.assertEquals(
            len(clist),
            3,
            "Wrong number of comments returned from list_comments with a limit argument, expected 3, got %d"
            % (len(clist),),
        )
def main_page(environ, start_response):
    # Main Page of the website
    main_page_text = "<H1> Welcome to Philip's Webpage </H1><BR><H2> Recent Comments </H2>"
    main_page_comments = comments(interface.list_comments(db, 10))
    headers = [('content-type', 'text/html')]
    start_response('200 OK', headers)
    page = ["<HTML>", css, topnav(environ), main_page_text, main_page_comments,"</DIV></HTML>"]
    return page
Beispiel #4
0
def main_page(environ, start_response):
    # Main Page of the website
    main_page_text = "<H1> Welcome to Philip's Webpage </H1><BR><H2> Recent Comments </H2>"
    main_page_comments = comments(interface.list_comments(db, 10))
    headers = [('content-type', 'text/html')]
    start_response('200 OK', headers)
    page = [
        "<HTML>", css,
        topnav(environ), main_page_text, main_page_comments, "</DIV></HTML>"
    ]
    return page
Beispiel #5
0
def render_image_list(listing):
    result = ""
    for image in listing:
        image_mapping = {
            'image': image[0],
            'date': image[1],
            'useremail': image[2],
            'comments': render_comment_list(list_comments(db, image[0]))
        }
        result += render_plain('includes/image_item.html', image_mapping)
    return result
Beispiel #6
0
    def test_add_comment(self):
        """Test that add_comment is able to add new comments"""
        
        image = 'seashell.jpg'
        testcomment = 'she sells sea shells on the sea shore'

        interface.add_comment(self.db, image, testcomment)
        
        # use list_comments to retrieve the comments, this assumes that list_comments works
        
        comments = interface.list_comments(self.db, image)
        self.assertEqual(1, len(comments), "expected just one comment for seashell.jpg")
        self.assertEqual(testcomment, comments[0])
Beispiel #7
0
 def test_list_comments(self):
     """Test that list_comments returns all comments on an image"""
     
     
     # list comments should return the three comments we inserted
     for image in self.images:
         comments = interface.list_comments(self.db, image[0])
         
         if image[0] == 'seashell.jpg':
             # should have no comments
             self.assertEqual([], comments)
         else:
             self.assertEqual(len(self.comments), len(comments), "wrong number of comments")
             # check that all comments are present
             self.assertTrue(all([c in comments for c in self.comments]), "didn't find all comments")
Beispiel #8
0
def my_content(environ):
    # gets current logged in user
    current_user = users.user_from_cookie(db, environ)
    image_list = interface.list_images_for_user(db, current_user)
    result = []
    for index in range(len(image_list)):
        comments = interface.list_comments(db, image_list[index][0])
        new_row = image_list[index] + (comments,)
        result.append(new_row)
    image_list = result
    # html form for image upload
    item = (
        """<div class="well uploadform">
    <form id="uploadform" method="post" action="/upload" enctype="multipart/form-data">
    <fieldset class="form-group">
      <legend>Upload New Image</legend>
       <input class="form-control" type="file" name="file">
       <input type="hidden" name="user" value="""
        + current_user
        + """>
       <br><div class="text-center"><input class="btn btn-primary" type="submit" value="Upload File"></div>
      </fieldset>
    </form>  
    </div> 
    """
    )
    # constructs html for each image div
    for index in range(len(image_list)):
        comments = "<ul>"
        item += '<div class="flowtow">'
        item += '<span class="date"> ' + image_list[index][1] + "</span>"
        item += '<span class="name"> ' + image_list[index][2] + "</span>"
        item += '<img src="/static/images/' + image_list[index][0] + '">'
        for comment in range(len(image_list[index][3])):
            comments = comments + "<li>" + image_list[index][3][comment] + "</li>"
        item += '<div class="comments">' + comments + "</ul></div>"
        # creates a form for commenting
        item += (
            """<form method="post" action="/add_comment"> 
                        <input type="hidden" name="image" value="""
            + image_list[index][0]
            + """>
                        <input type="text" class="form-control" name="comment" id="comment" placeholder="Enter your comment here"><br>
                        <input type="submit" class="btn btn-primary" value="Submit">
                        </form></div>"""
        )
    return item