class TestDecorator(TestCase): def setUp(self): self.job = FunctionJob(fetch_on_miss=False) def test_wrapping_argless_function(self): self.assertIsNone(self.job.get(fetch)) self.assertEqual((1, 2, 3), self.job.get(fetch)) def test_wrapping_function(self): self.assertIsNone(self.job.get(fetch_with_args, 'testing')) self.assertEqual(('testing', ), self.job.get(fetch_with_args, 'testing'))
class TestDecorator(TestCase): def setUp(self): self.job = FunctionJob(fetch_on_miss=False) def test_wrapping_argless_function(self): self.assertIsNone(self.job.get(fetch)) self.assertEqual((1, 2, 3), self.job.get(fetch)) def test_wrapping_function(self): self.assertIsNone(self.job.get(fetch_with_args, 'testing')) self.assertEqual(('testing',), self.job.get(fetch_with_args, 'testing'))
def test_init(self): job = FunctionJob(lifetime=30, fetch_on_miss=False, task_options={'foo': 'bar'}) assert job.lifetime == 30 assert job.fetch_on_miss is False assert job.task_options == {'foo': 'bar'}
def index(request): if 'name' in request.GET: name = request.GET['name'] if 'qs' in request.GET: items = QuerySetFilterJob(models.DummyModel, 10, False).get( name=name) else: items = jobs.KeyedJob().get(name=request.GET['name']) elif 'function' in request.GET: job = FunctionJob() job.fetch_on_miss = False if 'q' in request.GET: items = job.get(fetch_with_arg, request.GET['q']) else: items = job.get(fetch) elif 'decorator' in request.GET: items = decorated('3') else: items = jobs.VanillaJob().get() return render(request, 'index.html', {'items': items})
def index(request): if 'name' in request.GET: name = request.GET['name'] if 'qs' in request.GET: items = QuerySetFilterJob(models.DummyModel, 10, False).get(name=name) else: items = jobs.KeyedJob().get(name=request.GET['name']) elif 'function' in request.GET: job = FunctionJob() job.fetch_on_miss = False if 'q' in request.GET: items = job.get(fetch_with_arg, request.GET['q']) else: items = job.get(fetch) elif 'decorator' in request.GET: items = decorated('3') else: items = jobs.VanillaJob().get() return render(request, 'index.html', {'items': items})
def setUp(self): self.job = FunctionJob(fetch_on_miss=False)
def test_init_kwargs(self): assert FunctionJob().get_constructor_kwargs() == {'lifetime': 600} assert FunctionJob(lifetime=30).get_constructor_kwargs() == { 'lifetime': 30 }
def test_fetch_decorated(self): assert FunctionJob().fetch('tests.test_jobs:decorated_dummy_function', 'foo') == ('JOB-EXECUTED:foo')
def test_prepare_args(self): job = FunctionJob() assert job.prepare_args(dummy_function, 'foo') == ('tests.test_jobs:dummy_function', 'foo')
def test_init_defaults(self): job = FunctionJob() assert job.lifetime == 600 assert job.fetch_on_miss is True assert job.task_options == {}
def test_prepare_args(self): job = FunctionJob() assert job.prepare_args(dummy_function, 'foo') == ( 'tests.test_jobs:dummy_function', 'foo')
def test_passing_lifetime(self): job = FunctionJob(300) self.assertEqual(300, job.lifetime)