mirror of https://github.com/peter4431/rq.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
11 years ago
|
# -*- coding: utf-8 -*-
|
||
|
from __future__ import (absolute_import, division, print_function,
|
||
|
unicode_literals)
|
||
|
|
||
10 years ago
|
from click.testing import CliRunner
|
||
|
from rq import get_failed_queue
|
||
12 years ago
|
from rq.compat import is_python_version
|
||
10 years ago
|
from rq.job import Job
|
||
10 years ago
|
from rq.cli import main
|
||
|
from rq.scripts import read_config_file
|
||
10 years ago
|
|
||
|
from tests import RQTestCase
|
||
|
from tests.fixtures import div_by_zero
|
||
11 years ago
|
|
||
12 years ago
|
if is_python_version((2, 7), (3, 2)):
|
||
|
from unittest import TestCase
|
||
|
else:
|
||
|
from unittest2 import TestCase # noqa
|
||
12 years ago
|
|
||
12 years ago
|
|
||
10 years ago
|
class TestCommandLine(TestCase):
|
||
12 years ago
|
def test_config_file(self):
|
||
|
settings = read_config_file("tests.dummy_settings")
|
||
|
self.assertIn("REDIS_HOST", settings)
|
||
|
self.assertEqual(settings['REDIS_HOST'], "testhost.example.com")
|
||
10 years ago
|
|
||
|
|
||
|
class TestRQCli(RQTestCase):
|
||
|
"""Test rq_cli script"""
|
||
|
def setUp(self):
|
||
|
super(TestRQCli, self).setUp()
|
||
|
db_num = self.testconn.connection_pool.connection_kwargs['db']
|
||
|
self.redis_url = 'redis://127.0.0.1:6379/%d' % db_num
|
||
|
|
||
|
job = Job.create(func=div_by_zero, args=(1, 2, 3))
|
||
|
job.origin = 'fake'
|
||
|
job.save()
|
||
|
get_failed_queue().quarantine(job, Exception('Some fake error')) # noqa
|
||
|
|
||
|
def test_empty(self):
|
||
|
"""rq -u <url> empty -y"""
|
||
|
runner = CliRunner()
|
||
10 years ago
|
result = runner.invoke(main, ['empty', '-u', self.redis_url, 'failed'])
|
||
10 years ago
|
self.assertEqual(result.exit_code, 0)
|
||
10 years ago
|
self.assertEqual(result.output.strip(), '1 jobs removed from failed queue')
|
||
10 years ago
|
|
||
|
def test_requeue(self):
|
||
|
"""rq -u <url> requeue"""
|
||
|
runner = CliRunner()
|
||
10 years ago
|
result = runner.invoke(main, ['requeue', '-u', self.redis_url, '--all'])
|
||
10 years ago
|
self.assertEqual(result.exit_code, 0)
|
||
10 years ago
|
self.assertEqual(result.output.strip(), 'Requeueing 1 jobs from failed queue')
|
||
10 years ago
|
|
||
|
def test_info(self):
|
||
|
"""rq -u <url> info -i 0"""
|
||
|
runner = CliRunner()
|
||
10 years ago
|
result = runner.invoke(main, ['info', '-u', self.redis_url])
|
||
10 years ago
|
self.assertEqual(result.exit_code, 0)
|
||
|
self.assertIn('1 queues, 1 jobs total', result.output)
|