Example #1
0
def watchlist(*args, **kwargs):
    logger = logging.getLogger('app')
    user_id = kwargs.get('user_id')
    process = kwargs.get('process')
    queue = kwargs.get('queue')
    torrents = kwargs.get('torrents')
    provider = 'imdb'

    try:
        user = User.query.filter_by(id=user_id).one()
    except NoResultFound:
        sentry.captureException()
        return

    prefix = 'Process watchlist queue for user "%s"' % user.login

    if process:
        logger.info('%s: start.' % prefix)
        fill_queue_from_csv(user_id=user.id, provider=provider)
        logger.info('%s: finished' % prefix)

    if queue:
        process_queue(count=1, queue='watchlist_queue', save_relations=True,
                      title='users watchlist')

    if torrents:
        find_torrents(user_id=user_id)
Example #2
0
    def test_process_multiple_more_than_keys(self):
        with self.instance.test_request_context() as request:
            u = UserFactory()
            self.db.session.commit()

            keys = ['watchlist:1:movie:tt0167260:imdb',
                    'watchlist:1:movie:tt1229238:imdb',
                    'watchlist:1:movie:tt1272878:imdb']
            for key in keys:
                self.redis.lpush(Watchlist.watchlist_key, key)

            process_queue(count=10, queue=Watchlist.watchlist_key,
                          title='users watchlist')

            self.assertEqual(self.redis.llen(Watchlist.watchlist_key), 0)

            movies = self.db.session.query(Movie).all()
            self.assertEqual(len(movies), 3)

            watchlist = self.db.session.query(Watchlist).all()
            self.assertEqual(len(watchlist), 3)