本文整理汇总了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)
示例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)
示例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)
示例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)
示例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>')
示例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
示例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)
示例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()
示例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)
示例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)
示例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)