Exemple #1
0
    def test_get_gist_comments(self):
        GistComment.add(self.gist1.id, 'xutao', "sent from iCode")
        GistComment.add(
            self.gist1.id, 'chengeng', "sent from Code for Android")

        ret = self.app.get(
            "/api/gists/%s/comments/" % self.gist1.id,
            status=200,
            headers=dict(Authorization="Bearer %s" % self.api_token.token)
        ).json
        self.assertEquals(len(ret), 2)
Exemple #2
0
 def _q_lookup(self, request, comment_id):
     if request.method == 'POST':
         act = request.get_form_var('act', None)
         if act and act in ('delete', 'update'):
             comment = GistComment.get(comment_id)
             if act == 'delete' and comment:
                 if comment.can_delete(request.user.username):
                     comment.delete()
                     return json.dumps({'r': 1})
                 raise TraversalError("Unable to delete comment %s" %
                                      comment_id)
     return request.redirect(self.gist.url)
Exemple #3
0
 def _q_lookup(self, request, comment_id):
     if request.method == 'POST':
         act = request.get_form_var('act', None)
         if act and act in ('delete', 'update'):
             comment = GistComment.get(comment_id)
             if act == 'delete' and comment:
                 if comment.can_delete(request.user.username):
                     comment.delete()
                     return json.dumps({'r': 1})
                 raise TraversalError(
                     "Unable to delete comment %s" % comment_id)
     return request.redirect(self.gist.url)
Exemple #4
0
    def test_gist_comment(self):
        gist = self._add_gist()
        user_id = 'testuser'
        content = 'xxoo'
        new_content = 'ooxx'

        gc = GistComment.add(gist.id, user_id, content)
        assert isinstance(gc, GistComment)

        gcs = GistComment.gets_by_gist_id(gist.id)
        eq_(len(gcs), 1)

        assert gc.can_delete(user_id)

        gc.update(new_content)
        gc = GistComment.get(gc.id)

        eq_(gc.content, new_content)

        gc.delete()
        ret = GistComment.get(gc.id)
        eq_(ret, None)
    def test_gist_comment(self):
        gist = self._add_gist()
        user_id = 'testuser'
        content = 'xxoo'
        new_content = 'ooxx'

        gc = GistComment.add(gist.id, user_id, content)
        assert isinstance(gc, GistComment)

        gcs = GistComment.gets_by_gist_id(gist.id)
        eq_(len(gcs), 1)

        assert gc.can_delete(user_id)

        gc.update(new_content)
        gc = GistComment.get(gc.id)

        eq_(gc.content, new_content)

        gc.delete()
        ret = GistComment.get(gc.id)
        eq_(ret, None)
Exemple #6
0
 def comments(self):
     return GistComment.gets_by_gist_id(self.id)
Exemple #7
0
 def comments(self):
     return GistComment.gets_by_gist_id(self.id)
Exemple #8
0
 def _q_index(self, request):
     if request.method == 'POST':
         content = request.get_form_var('content', '')
         if content:
             GistComment.add(self.gist.id, request.user.username, content)
     return request.redirect(self.gist.url)
Exemple #9
0
 def _q_index(self, request):
     if request.method == 'POST':
         content = request.get_form_var('content', '')
         if content:
             GistComment.add(self.gist.id, request.user.username, content)
     return request.redirect(self.gist.url)