test_call.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from __future__ import absolute_import, unicode_literals
  2. from datetime import datetime
  3. import pytest
  4. from case import patch
  5. from kombu.utils.json import dumps
  6. from celery.bin.call import call
  7. from celery.five import WhateverIO
  8. class test_call:
  9. def setup(self):
  10. @self.app.task(shared=False)
  11. def add(x, y):
  12. return x + y
  13. self.add = add
  14. @patch('celery.app.base.Celery.send_task')
  15. def test_run(self, send_task):
  16. a = call(app=self.app, stderr=WhateverIO(), stdout=WhateverIO())
  17. a.run(self.add.name)
  18. send_task.assert_called()
  19. a.run(self.add.name,
  20. args=dumps([4, 4]),
  21. kwargs=dumps({'x': 2, 'y': 2}))
  22. assert send_task.call_args[1]['args'], [4 == 4]
  23. assert send_task.call_args[1]['kwargs'] == {'x': 2, 'y': 2}
  24. a.run(self.add.name, expires=10, countdown=10)
  25. assert send_task.call_args[1]['expires'] == 10
  26. assert send_task.call_args[1]['countdown'] == 10
  27. now = datetime.now()
  28. iso = now.isoformat()
  29. a.run(self.add.name, expires=iso)
  30. assert send_task.call_args[1]['expires'] == now
  31. with pytest.raises(ValueError):
  32. a.run(self.add.name, expires='foobaribazibar')