mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-23 09:18:11 +08:00
Added management commands to tests
* added --run-once option to the management commands for testing
This commit is contained in:
@@ -7,7 +7,16 @@ class Command(BaseCommand):
|
||||
# Translators: help text for qcluster management command
|
||||
help = _("Starts a Django Q Cluster.")
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--run-once',
|
||||
action='store_true',
|
||||
dest='run_once',
|
||||
default=False,
|
||||
help='Run once and then stop.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
q = Cluster()
|
||||
q.start()
|
||||
if options.get('run_once', False):
|
||||
q.stop()
|
||||
|
||||
|
||||
@@ -2,14 +2,19 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from django_q.monitor import monitor
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
# Translators: help text for qmonitor management command
|
||||
help = _("Monitors Q Cluster activity")
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--run-once',
|
||||
action='store_true',
|
||||
dest='run_once',
|
||||
default=False,
|
||||
help='Run once and then exit.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
monitor()
|
||||
|
||||
|
||||
monitor(run_once=options.get('run_once', False))
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_qcluster():
|
||||
call_command('qcluster', '--run-once')
|
||||
|
||||
|
||||
def test_qmonitor():
|
||||
call_command('qmonitor', '--run-once')
|
||||
Reference in New Issue
Block a user