Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
def commit(user, video):
    key = 'watch-transaction:' + str(user.sysid)
    redis = _redis()
    val = redis.get(key)
    redis.delete(key)
    if val is None:
        return None
    start, dur_sec, video_id = val.split('.')
    if video.sysid != video_id:
        return None
    start, dur_sec = int(start), int(dur_sec)
    start = datetime.utcfromtimestamp(start)
    now = datetime.utcnow()
    tot_sec = (now - start).total_seconds()
    sec = tot_sec - dur_sec
    threshold  = dur_sec * WATCH_TIME_ROUND 
    if sec < threshold:
        return None
    return users.screening_log(user, video)