コード例 #1
0
def conversation_page(environ, start_response):
    # Page that displays all conversations about the web site the user requested.
    url = environ['QUERY_STRING']
    url = urllib.unquote(url)
    url = url.replace('page=', '')
    webpage = url.replace('http://','')
    conversation_text = "<H1> Recent comments on %s </H1>" % (webpage)
    conversation_comments = comments(interface.list_comments_page(db, url))
    if conversation_comments != '':
        headers = [('content-type', 'text/html')]
        start_response('200 OK', headers)
        page = ["<HTML>", css, topnav(environ), conversation_text, conversation_comments, "</DIV></HTML>"]
        return page
    else:
        return conversation_invalid(environ, start_response)
コード例 #2
0
def conversation_page(environ, start_response):
    # Page that displays all conversations about the web site the user requested.
    url = environ['QUERY_STRING']
    url = urllib.unquote(url)
    url = url.replace('page=', '')
    webpage = url.replace('http://', '')
    conversation_text = "<H1> Recent comments on %s </H1>" % (webpage)
    conversation_comments = comments(interface.list_comments_page(db, url))
    if conversation_comments != '':
        headers = [('content-type', 'text/html')]
        start_response('200 OK', headers)
        page = [
            "<HTML>", css,
            topnav(environ), conversation_text, conversation_comments,
            "</DIV></HTML>"
        ]
        return page
    else:
        return conversation_invalid(environ, start_response)
コード例 #3
0
    def test_list_comments_page(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
        testpage = self.pages[0]

        comments = interface.list_comments_page(self.db, testpage)

        # this time only those where the user is our test user
        refcomments = [u for u in self.comments if u[2] == testpage]

        # we should have the same units in self.units
        self.assertEquals(
            len(comments), len(refcomments),
            "Wrong number of comments returned from list_comments_page")

        # 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_page %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, ))
コード例 #4
0
    def test_list_comments_page(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
        testpage = self.pages[0]

        comments = interface.list_comments_page(self.db, testpage)

        # this time only those where the user is our test user
        refcomments = [u for u in self.comments if u[2] == testpage]

        # we should have the same units in self.units
        self.assertEquals(len(comments), len(refcomments), "Wrong number of comments returned from list_comments_page")

        # 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_page %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,)
        )