def _insert_comments(self, count):
     templ = 'posted at {0} min by {1}'
     screendur = self.video.duration + 20 # seconds
     times = [random.uniform(0, screendur) for _ in range(count)]
     for time in times:
         if time > self.video.duration:
             time = float('inf')
         text = templ.format(time, self.user.display_name)
         comments.new_comment(self.video, self.user, text, time)
def append_comment():
    video_id = request.json['video_id']
    text = request.json['text']
    position = request.json['position']
    user = users.current()
    if user.anonymous:
        return jsonify(comment_id=-1)
    video = videos.find(video_id)
    comment = comments.new_comment(video, user, text, position)
    return jsonify(comment_id=comment.sysid)
 def test_new_comment(self):
     video = videos.find(self.video_id)
     user = users.find(self.user_id)
     text = 'This is a new comment from {0}'.format(repr(self))
     time = float(video.duration) / 3
     comment1 = comments.new_comment(video, user, text, time)
     comment2 = comments.find(comment1.sysid)
     removed = self.database.comments.remove(ObjectId(comment1.sysid))
     self.assertIsNot(comment1, comment2)
     self.assertEqual(comment1.text, text)
     self.assertEqual(comment2.text, text)
     self.assertEqual(removed['n'], 1)