From 5a3f875baa9419b4a48363fc2357cfaabfc47c36 Mon Sep 17 00:00:00 2001 From: Ilan Date: Thu, 16 Jul 2015 15:17:15 +0200 Subject: [PATCH] Added management commands to tests * added --run-once option to the management commands for testing --- django_q/management/commands/qcluster.py | 9 +++++++++ django_q/management/commands/qmonitor.py | 13 +++++++++---- django_q/tests/test_commands.py | 11 +++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 django_q/tests/test_commands.py diff --git a/django_q/management/commands/qcluster.py b/django_q/management/commands/qcluster.py index a1ac799..0e4e821 100644 --- a/django_q/management/commands/qcluster.py +++ b/django_q/management/commands/qcluster.py @@ -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() diff --git a/django_q/management/commands/qmonitor.py b/django_q/management/commands/qmonitor.py index 998271d..def5065 100644 --- a/django_q/management/commands/qmonitor.py +++ b/django_q/management/commands/qmonitor.py @@ -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)) diff --git a/django_q/tests/test_commands.py b/django_q/tests/test_commands.py new file mode 100644 index 0000000..3b517a7 --- /dev/null +++ b/django_q/tests/test_commands.py @@ -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')