Пример #1
0
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'))
Пример #2
0
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'))
Пример #3
0
 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'}
Пример #4
0
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})
Пример #5
0
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})
Пример #6
0
 def setUp(self):
     self.job = FunctionJob(fetch_on_miss=False)
Пример #7
0
 def test_init_kwargs(self):
     assert FunctionJob().get_constructor_kwargs() == {'lifetime': 600}
     assert FunctionJob(lifetime=30).get_constructor_kwargs() == {
         'lifetime': 30
     }
Пример #8
0
 def test_fetch_decorated(self):
     assert FunctionJob().fetch('tests.test_jobs:decorated_dummy_function',
                                'foo') == ('JOB-EXECUTED:foo')
Пример #9
0
 def test_prepare_args(self):
     job = FunctionJob()
     assert job.prepare_args(dummy_function,
                             'foo') == ('tests.test_jobs:dummy_function',
                                        'foo')
Пример #10
0
 def test_init_defaults(self):
     job = FunctionJob()
     assert job.lifetime == 600
     assert job.fetch_on_miss is True
     assert job.task_options == {}
Пример #11
0
 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)
Пример #13
0
 def setUp(self):
     self.job = FunctionJob(fetch_on_miss=False)