def test_commit(self):
     user = users.find(self.test_user_id)
     video = videos.find(self.video_id)
     video._duration = 0
     watchtran.begin(user, video)
     result = watchtran.commit(user, video)
     self.assertIsNotNone(result)
 def test_begin(self):
     user = users.find(self.test_user_id)
     video = videos.find(self.video_id)
     watchtran.begin(user, video)
     key = self.prefix + self.test_user_id
     val = self.redis.get(key)
     self.assertIsNotNone(val)
Exemplo n.º 3
0
def commit():
    video_id = request.json['video_id']
    user = users.current()
    video = videos.find(video_id)
    if not user.anonymous:
        watchtran.commit(user, video)
    user = users.current()
    return jsonify(chances=user.chances)
Exemplo n.º 4
0
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)
 def test_commit(self):
     video = videos.find('5129e49971eeccbbcaf90802')
     video._duration = 0
     user = users.find(self.user_id)
     watchtran.begin(user, video)
     service_url = '/player/commit.json'
     data = dict(video_id=video.sysid)
     with self.app.test_client() as client:
         with client.session_transaction() as sess:
             sess['account'] = self.user_id
         response = post_json(service_url, data, client)
     response_chances = response['chances']
     user = users.find(user.sysid)
     self.assertEqual(response_chances, 223)
     self.assertEqual(user.chances, 223)
 def test_screening_log(self):
     video = videos.find(self.video_id)
     user1 = users.find(self.test_user_id)
     points = user1.chances
     screening_id = users.screening_log(user1, video)
     user2 = users.find(self.test_user_id)
     screening_id = ObjectId(screening_id)
     found = self.database.screening.find_one(screening_id)
     removed = self.database.screening.remove(screening_id)
     self.assertEqual(user2.chances, points+1)
     self.assertIsNotNone(found)
     self.assertEqual(str(found['video']['id']), video.sysid)
     self.assertEqual(str(found['user']['id']), user1.sysid)
     self.assertIsNotNone(removed)
     self.assertTrue(removed['ok'])
     self.assertEqual(removed['n'], 1)
 def setUp(self):
     self.database = connection()
     user = {
         'name': 'test user: {0}'.format(repr(self)),
         'chances': 123
     }
     video = {
         'duration' : 65,
         'random' : 0.31461311114729994,
         'vimeoid' : 24879869,
         'description' : 'The story of a cartoon character', 
         'title' : 'Overcast'
     }
     user_id = str(self.database.accounts.insert(user))
     video_id = str(self.database.videos.insert(video))
     self.video = videos.find(video_id)
     self.user = users.find(user_id)
Exemplo n.º 9
0
def show(vidid):
    g.menu['select_top_menu']['home'] = True
    user = users.current()
    render_data = {}
    if vidid == 'random':
        render_data['mode'] = 'normal'
        video = videos.random()
        watchtran.begin(user, video)
    else:
        render_data['mode'] = 'specific'
        video = videos.find(vidid)
        # TODO: remove line below
        watchtran.begin(user, video)
        if video is None:
            abort(404)
    render_data['video'] = video
    render_data['user_message_size'] = USER_MESSAGE_SIZE
    scomments = comments.for_screening(video, user)
    render_data['comments'] = scomments
    return render_template('player/screening.html', **render_data)
 def test_commit_too_early(self):
     user = users.find(self.test_user_id)
     video = videos.find(self.video_id)
     watchtran.begin(user, video)
     result = watchtran.commit(user, video)
     self.assertIsNone(result)
 def test_commit_without_begin(self):
     user = users.find(self.test_user_id)
     video = videos.find(self.video_id)
     result = watchtran.commit(user, video)
     self.assertIsNone(result)
Exemplo n.º 12
0
 def test_find(self):
     '''Test of the video search by system identifier'''
     video = videos.find(self.video_id)
     self.assertIsNotNone(video)