test_methods.py 840 B

12345678910111213141516171819202122232425262728293031323334
  1. from __future__ import absolute_import
  2. from celery.contrib.methods import task_method, task
  3. from celery.tests.case import AppCase, patch
  4. class test_task_method(AppCase):
  5. def test_task_method(self):
  6. class X(object):
  7. def __init__(self):
  8. self.state = 0
  9. @self.app.task(shared=False, filter=task_method)
  10. def add(self, x):
  11. self.state += x
  12. x = X()
  13. x.add(2)
  14. self.assertEqual(x.state, 2)
  15. x.add(4)
  16. self.assertEqual(x.state, 6)
  17. self.assertTrue(X.add)
  18. self.assertIs(x.add.__self__, x)
  19. def test_task(self):
  20. with patch('celery.contrib.methods.current_app') as curapp:
  21. fun = object()
  22. task(fun, x=1)
  23. curapp.task.assert_called_with(fun, x=1, filter=task_method)