Esempio n. 1
0
    def test_proxy(self):
        from fanboi2.tasks import ResultProxy

        class DummyDummyAsyncResult(DummyAsyncResult):
            def dummy(self):
                return "dummy"

        proxy = ResultProxy(DummyDummyAsyncResult('demo', 'success'))
        self.assertEqual(proxy.dummy(), "dummy")
Esempio n. 2
0
    def test_proxy(self):
        from fanboi2.tasks import ResultProxy

        class DummyDummyAsyncResult(DummyAsyncResult):
            def dummy(self):
                return "dummy"

        proxy = ResultProxy(DummyDummyAsyncResult('demo', 'success'))
        self.assertEqual(proxy.dummy(), "dummy")
Esempio n. 3
0
def task_get(request, task=None):
    """Retrieve a task processing status for the given task id.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: fanboi2.tasks.ResultProxy
    """
    if task is None:
        task = celery.AsyncResult(request.matchdict['task'])
    response = ResultProxy(task)
    if response.success():
        if isinstance(response.object, BaseError):
            raise response.object
    return response
Esempio n. 4
0
def task_get(request, task=None):
    """Retrieve a task processing status for the given task id.

    :param request: A :class:`pyramid.request.Request` object.

    :type request: pyramid.request.Request
    :rtype: fanboi2.tasks.ResultProxy
    """
    if task is None:
        task = celery.AsyncResult(request.matchdict['task'])
    response = ResultProxy(task)
    if response.success():
        if isinstance(response.object, BaseError):
            raise response.object
    return response
Esempio n. 5
0
 def test_object_failure(self):
     from fanboi2.tasks import ResultProxy
     from fanboi2.errors import BaseError, StatusRejectedError
     response = ['failure', 'status_rejected', 'locked']
     proxy = ResultProxy(DummyAsyncResult('demo', 'success', response))
     self.assertIsInstance(proxy.object, BaseError)
     self.assertIsInstance(proxy.object, StatusRejectedError)
     self.assertEqual(proxy.object.status, 'locked')
Esempio n. 6
0
 def test_result_proxy(self):
     from fanboi2.tasks import ResultProxy
     request = self._makeRequest()
     config = self._makeConfig(request, self._makeRegistry())
     config.add_route('api_task', '/task/{task}/')
     result_proxy = ResultProxy(DummyAsyncResult('demo', 'pending'))
     response = self._makeOne(result_proxy, request=request)
     self.assertEqual(response['type'], 'task')
     self.assertEqual(response['status'], 'pending')
     self.assertEqual(response['id'], 'demo')
     self.assertEqual(response['path'], '/task/demo/')
     self.assertNotIn('data', response)
Esempio n. 7
0
 def test_result_proxy_success(self):
     from fanboi2.tasks import ResultProxy
     board = self._makeBoard(title='Foobar', slug='foo')
     request = self._makeRequest()
     config = self._makeConfig(request, self._makeRegistry())
     config.add_route('api_task', '/task/{task}/')
     config.add_route('api_board', '/board/{board}/')
     result = ['board', board.id]
     result_proxy = ResultProxy(DummyAsyncResult('demo', 'success', result))
     response = self._makeOne(result_proxy, request=request)
     self.assertEqual(response['type'], 'task')
     self.assertEqual(response['status'], 'success')
     self.assertEqual(response['id'], 'demo')
     self.assertEqual(response['path'], '/task/demo/')
     self.assertIn('data', response)
Esempio n. 8
0
 def test_success_non_success(self):
     from fanboi2.tasks import ResultProxy
     proxy = ResultProxy(DummyAsyncResult('demo', 'pending'))
     self.assertFalse(proxy.success())
Esempio n. 9
0
 def test_success(self):
     from fanboi2.tasks import ResultProxy
     proxy = ResultProxy(DummyAsyncResult('demo', 'success'))
     self.assertTrue(proxy.success())
Esempio n. 10
0
 def test_object(self):
     from fanboi2.tasks import ResultProxy
     board = self._makeBoard(title='Foobar', slug='foobar')
     response = ['board', board.id]
     proxy = ResultProxy(DummyAsyncResult('demo', 'success', response))
     self.assertEqual(proxy.object, board)
Esempio n. 11
0
 def test_success_non_success(self):
     from fanboi2.tasks import ResultProxy
     proxy = ResultProxy(DummyAsyncResult('demo', 'pending'))
     self.assertFalse(proxy.success())
Esempio n. 12
0
 def test_success(self):
     from fanboi2.tasks import ResultProxy
     proxy = ResultProxy(DummyAsyncResult('demo', 'success'))
     self.assertTrue(proxy.success())