當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Comment方法代碼示例

本文整理匯總了Python中app.models.Comment方法的典型用法代碼示例。如果您正苦於以下問題:Python models.Comment方法的具體用法?Python models.Comment怎麽用?Python models.Comment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app.models的用法示例。


在下文中一共展示了models.Comment方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_moderation

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_moderation(self):
        db.create_all()
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='susan@example.com', username='susan', password='cat',
                  is_admin=True)
        t = Talk(title='t', description='d', author=u1)
        c1 = Comment(talk=t, body='c1', author_name='n',
                     author_email='e@e.com', approved=True)
        c2 = Comment(talk=t, body='c2', author_name='n',
                     author_email='e@e.com', approved=False)
        db.session.add_all([u1, u2, t, c1, c2])
        db.session.commit()
        for_mod1 = u1.for_moderation().all()
        for_mod1_admin = u1.for_moderation(True).all()
        for_mod2 = u2.for_moderation().all()
        for_mod2_admin = u2.for_moderation(True).all()
        self.assertTrue(len(for_mod1) == 1)
        self.assertTrue(for_mod1[0] == c2)
        self.assertTrue(for_mod1_admin == for_mod1)
        self.assertTrue(len(for_mod2) == 0)
        self.assertTrue(len(for_mod2_admin) == 1)
        self.assertTrue(for_mod2_admin[0] == c2) 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:24,代碼來源:test_user_model.py

示例2: make_shell_context

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role,
                Permission=Permission, Post=Post, Comment=Comment) 
開發者ID:CircleCI-Public,項目名稱:circleci-demo-python-flask,代碼行數:5,代碼來源:manage.py

示例3: test_delete

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_delete(self):
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='susan@example.com', username='susan', password='cat')
        t = Talk(title='t', description='d', author=u1)
        c = Comment(talk=t, body='c1', author_name='n',
                    author_email='e@e.com', approved=False)
        db.session.add_all([u1, u2, t, c])
        db.session.commit()

        # wrong user --> 403
        token = u2.get_api_token()
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='DELETE',
                data=json.dumps({'token': token}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 403)

        token = u1.get_api_token()
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='DELETE',
                data=json.dumps({'token': token}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 200)
            c = Comment.query.get(c.id)
            self.assertIsNone(c) 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:31,代碼來源:test_api.py

示例4: test_approved

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_approved(self):
        db.create_all()
        u = User(email='john@example.com', username='john', password='cat')
        t = Talk(title='t', description='d', author=u)
        c1 = Comment(talk=t, body='c1', author_name='n',
                     author_email='e@e.com', approved=True)
        c2 = Comment(talk=t, body='c2', author_name='n',
                     author_email='e@e.com', approved=False)
        db.session.add_all([u, t, c1, c2])
        db.session.commit()
        approved = t.approved_comments().all()
        self.assertTrue(len(approved) == 1)
        self.assertTrue(approved[0] == c1) 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:15,代碼來源:test_talk_model.py

示例5: test_markdown

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_markdown(self):
        c = Comment()
        c.body = '# title\n\n## section\n\ntext **bold** and *italic*'
        self.assertTrue(c.body_html == '<h1>title</h1>\n<h2>section</h2>\n'
                        '<p>text <strong>bold</strong> '
                        'and <em>italic</em></p>') 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:8,代碼來源:test_comment_model.py

示例6: test_notification_list

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_notification_list(self):
        db.create_all()
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='susan@example.com', username='susan', password='cat')
        t = Talk(title='t', description='d', author=u1)
        c1 = Comment(talk=t, body='c1', author_name='n1',
                     author_email='e@e.com', approved=True)
        c2 = Comment(talk=t, body='c2', author_name='n2',
                     author_email='e2@e2.com', approved=True, notify=False)
        c3 = Comment(talk=t, body='c3', author=u2, approved=True)
        c4 = Comment(talk=t, body='c4', author_name='n4',
                     author_email='e4@e4.com', approved=False)
        c5 = Comment(talk=t, body='c5', author=u2, approved=True)
        c6 = Comment(talk=t, body='c6', author_name='n6',
                     author_email='e6@e6.com', approved=True, notify=False)
        db.session.add_all([u1, u2, t, c1, c2, c3, c4, c5])
        db.session.commit()
        email_list = c4.notification_list()
        self.assertTrue(('e@e.com', 'n1') in email_list)
        self.assertFalse(('e2@e2.com', 'n2') in email_list)  # notify=False
        self.assertTrue(('susan@example.com', 'susan') in email_list)
        self.assertFalse(('e4@e4.com', 'n4') in email_list)  # comment author
        self.assertFalse(('e6@e6.com', 'n6') in email_list)
        email_list = c5.notification_list()
        self.assertFalse(('john@example.com', 'john') in email_list)
        self.assertTrue(('e4@e4.com', 'n4') in email_list)  # comment author 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:28,代碼來源:test_comment_model.py

示例7: show_post

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def show_post(slug):
    logger.info('Mostrando un post')
    logger.debug(f'Slug: {slug}')
    post = Post.get_by_slug(slug)
    if not post:
        logger.info(f'El post {slug} no existe')
        abort(404)
    form = CommentForm()
    if current_user.is_authenticated and form.validate_on_submit():
        content = form.content.data
        comment = Comment(content=content, user_id=current_user.id,
                          user_name=current_user.name, post_id=post.id)
        comment.save()
        return redirect(url_for('public.show_post', slug=post.title_slug))
    return render_template("public/post_view.html", post=post, form=form) 
開發者ID:j2logo,項目名稱:tutorial-flask,代碼行數:17,代碼來源:routes.py

示例8: clear_all_tables

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def clear_all_tables():
    db_session.query(EventHook).delete()
    db_session.query(FrontPage).delete()
    db_session.query(SubredditPage).delete()
    db_session.query(Subreddit).delete()
    db_session.query(Post).delete()
    db_session.query(User).delete()  
    db_session.query(ModAction).delete()    
    db_session.query(Comment).delete()      
    db_session.commit() 
開發者ID:mitmedialab,項目名稱:CivilServant,代碼行數:12,代碼來源:test_controllers.py

示例9: make_shell_context

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Article=Article, Comment=Comment, Source=Source,
                Category=Category, Tag=Tag) 
開發者ID:adisonhuang,項目名稱:flask-blog,代碼行數:5,代碼來源:manage.py

示例10: test_token_errors

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_token_errors(self):
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='susan@example.com', username='susan', password='cat')
        t = Talk(title='t', description='d', author=u1)
        c = Comment(talk=t, body='c1', author_name='n',
                    author_email='e@e.com', approved=False)
        db.session.add_all([u1, u2, t, c])
        db.session.commit()

        # missing JSON --> 400
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT'):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 400)

        # missing token --> 401
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT',
                data=json.dumps({'bad': 123}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 401)

        # bad token --> 401
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT',
                data=json.dumps({'token': 'a bad token'}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 401)

        # malformed token --> 401
        u3 = User(email='david@example.com', username='david', password='cat')
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT',
                data=json.dumps({'token': u3.get_api_token()}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 401) 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:45,代碼來源:test_api.py

示例11: test_approve

# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Comment [as 別名]
def test_approve(self):
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='susan@example.com', username='susan', password='cat')
        t = Talk(title='t', description='d', author=u1)
        c = Comment(talk=t, body='c1', author_name='n',
                    author_email='e@e.com', approved=False)
        db.session.add_all([u1, u2, t, c])
        db.session.commit()

        # wrong user --> 403
        token = u2.get_api_token()
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT',
                data=json.dumps({'token': token}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 403)

        # correct user --> 200
        token = u1.get_api_token()
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT',
                data=json.dumps({'token': token}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 200)
            c = Comment.query.get(c.id)
            self.assertTrue(c.approved)

        # approve an already approved comment --> 400
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='PUT',
                data=json.dumps({'token': token}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 400)

        # delete an already approved comment --> 400
        with self.app.test_request_context(
                '/api/1.0/comments/' + str(c.id),
                method='DELETE',
                data=json.dumps({'token': token}),
                headers={'Content-Type': 'application/json'}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 400) 
開發者ID:miguelgrinberg,項目名稱:flask-pycon2014,代碼行數:50,代碼來源:test_api.py


注:本文中的app.models.Comment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。