1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
# -*- coding: utf-8 -*-
import sys
import six
from django.core.management import call_command
from django.test import TestCase
class RunJobTests(TestCase):
def setUp(self):
sys.stdout = six.StringIO()
sys.stderr = six.StringIO()
def test_runs(self):
# lame test...does it run?
call_command('runjob', 'cache_cleanup', verbosity=2)
self.assertIn("Executing job: cache_cleanup (app: None)", sys.stdout.getvalue())
def test_sample_job(self):
call_command('runjob', 'sample_job', verbosity=2)
self.assertIn("Executing job: sample_job (app: None)", sys.stdout.getvalue())
self.assertIn("executing empty sample job", sys.stdout.getvalue())
def test_list_jobs(self):
call_command('runjob', '-l', verbosity=2)
self.assertRegexpMatches(sys.stdout.getvalue(), "tests.testapp +- sample_job +- +- My sample job.\n")
def test_list_jobs_appconfig(self):
with self.modify_settings(INSTALLED_APPS={
'append': 'tests.testapp.apps.TestAppConfig',
'remove': 'tests.testapp',
}):
call_command('runjob', '-l', verbosity=2)
self.assertRegexpMatches(sys.stdout.getvalue(), "tests.testapp +- sample_job +- +- My sample job.\n")
def test_runs_appconfig(self):
with self.modify_settings(INSTALLED_APPS={
'append': 'tests.testapp.apps.TestAppConfig',
'remove': 'tests.testapp',
}):
call_command('runjob', 'sample_job', verbosity=2)
self.assertIn("Executing job: sample_job (app: None)", sys.stdout.getvalue())
self.assertIn("executing empty sample job", sys.stdout.getvalue())
|