本文整理汇总了Python中app.models.Comment.create方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.create方法的具体用法?Python Comment.create怎么用?Python Comment.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Comment
的用法示例。
在下文中一共展示了Comment.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_comment_sentiment_avg
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import create [as 别名]
def test_comment_sentiment_avg(session):
s = Submission.create(session, **const.MOCK_SUBMISSION)
c1 = Comment.create(session, **const.MOCK_COMMENT1)
c1_sentiment = sentiment.comment_sentiment(c1)
c1s = CommentSentiment.create(session, **c1_sentiment)
c2 = Comment.create(session, **const.MOCK_COMMENT2)
c2_sentiment = sentiment.comment_sentiment(c2)
c2s = CommentSentiment.create(session, **c2_sentiment)
comments = session.query(Comment).\
options(joinedload('sentiment')).\
all()
comment_sentiments = []
for c in comments:
comment_sentiments.append({
"polarity": c.sentiment.polarity,
"subjectivity": c.sentiment.subjectivity
})
csa = sentiment.comment_sentiment_avg(comment_sentiments)
csa.update({'submission_id': s.id})
expected_keys = ['submission_id', 'polarity', 'subjectivity']
assert sorted(csa.keys()) == sorted(expected_keys)
assert isinstance(csa['polarity'], float)
assert isinstance(csa['subjectivity'], float)
示例2: test_submissionsentiment_model
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import create [as 别名]
def test_submissionsentiment_model(session):
s = Submission.create(session, **MOCK_SUBMISSION)
c1 = Comment.create(session, **MOCK_COMMENT1)
c1_sentiment = comment_sentiment(c1)
c1s = CommentSentiment.create(session, **c1_sentiment)
c2 = Comment.create(session, **MOCK_COMMENT2)
c2_sentiment = comment_sentiment(c2)
c2s = CommentSentiment.create(session, **c2_sentiment)
comments = session.query(Comment).options(joinedload("sentiment")).all()
comment_sentiments = []
for c in comments:
comment_sentiments.append({"polarity": c.sentiment.polarity, "subjectivity": c.sentiment.subjectivity})
submission_sentiment = comment_sentiment_avg(comment_sentiments)
submission_sentiment.update({"submission_id": s.id})
ss = SubmissionSentiment.create(session, **submission_sentiment)
submission_sentiments = session.query(SubmissionSentiment).all()
ss1 = submission_sentiments[0]
# test object form
assert ss1.id == 1
assert ss1.submission_id == s.id
for k in submission_sentiment.keys():
assert getattr(ss1, k) == submission_sentiment[k]
# test values
assert ss1.polarity < 0.5 and ss1.polarity > -0.5
assert ss1.subjectivity > 0.8
示例3: test_commentsentiment_model
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import create [as 别名]
def test_commentsentiment_model(session):
s = Submission.create(session, **MOCK_SUBMISSION)
c1 = Comment.create(session, **MOCK_COMMENT1)
c1_sentiment = comment_sentiment(c1)
c1s = CommentSentiment.create(session, **c1_sentiment)
c2 = Comment.create(session, **MOCK_COMMENT2)
c2_sentiment = comment_sentiment(c2)
c2s = CommentSentiment.create(session, **c2_sentiment)
# test object form
for k in c1_sentiment.keys():
assert getattr(c1s, k) == c1_sentiment[k]
# test relationship
assert c1.sentiment == c1s
# test values
assert c1s.id == 1
assert c1s.polarity > 0.5
assert c1s.subjectivity > 0.8
assert c2s.id == 2
assert c2s.polarity < -0.5
assert c2s.subjectivity > 0.8
示例4: post
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import create [as 别名]
def post(self, post_id):
content = self.get_argument('content', None)
if content is None:
raise exceptions.EmptyFields()
else:
users, content = at_content(content)
username = self.current_user
comment = yield gen.maybe_future(
Comment.create(username, post_id, content))
# Update gold.
update_gold.apply_async(('sb_2l', username, post_id))
update_gold.apply_async(('comment', username))
if users:
update_gold.apply_async(('be_comment', users))
# Notify users: be comment, someone @you.
notify.apply_async(
('comment', username, post_id, content))
if users:
notify.apply_async(
('at', username, users, post_id, content))
raise gen.Return(comment.to_dict())
示例5: test_comment_model
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import create [as 别名]
def test_comment_model(session):
s = Submission.create(session, **MOCK_SUBMISSION)
c1 = Comment.create(session, **MOCK_COMMENT1)
c2 = Comment.create(session, **MOCK_COMMENT2)
db_submissions = session.query(Submission).all()
db_comments = session.query(Comment).all()
assert db_submissions[0].comments[0] == c1
assert db_submissions[0].comments[1] == c2
assert len(db_comments) == 2
db_c1 = db_comments[0]
for k in MOCK_COMMENT1.keys():
assert getattr(db_c1, k) == MOCK_COMMENT1[k]
# test relationship
assert s.comments == db_comments
示例6: test_comment_sentiment
# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import create [as 别名]
def test_comment_sentiment(session):
s = Submission.create(session, **const.MOCK_SUBMISSION)
c = Comment.create(session, **const.MOCK_COMMENT1)
cs = sentiment.comment_sentiment(c)
expected_keys = ['comment_id', 'polarity', 'subjectivity']
assert sorted(cs.keys()) == sorted(expected_keys)
assert isinstance(cs['polarity'], float)
assert isinstance(cs['subjectivity'], float)