test_backends.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import absolute_import, unicode_literals
  2. import pytest
  3. from case import patch
  4. from celery.app import backends
  5. from celery.backends.amqp import AMQPBackend
  6. from celery.backends.cache import CacheBackend
  7. from celery.exceptions import ImproperlyConfigured
  8. class test_backends:
  9. @pytest.mark.parametrize('url,expect_cls', [
  10. ('amqp://', AMQPBackend),
  11. ('cache+memory://', CacheBackend),
  12. ])
  13. def test_get_backend_aliases(self, url, expect_cls, app):
  14. backend, url = backends.by_url(url, app.loader)
  15. assert isinstance(backend(app=app, url=url), expect_cls)
  16. def test_unknown_backend(self, app):
  17. with pytest.raises(ImportError):
  18. backends.by_name('fasodaopjeqijwqe', app.loader)
  19. def test_backend_by_url(self, app, url='redis://localhost/1'):
  20. from celery.backends.redis import RedisBackend
  21. backend, url_ = backends.by_url(url, app.loader)
  22. assert backend is RedisBackend
  23. assert url_ == url
  24. def test_sym_raises_ValuError(self, app):
  25. with patch('celery.app.backends.symbol_by_name') as sbn:
  26. sbn.side_effect = ValueError()
  27. with pytest.raises(ImproperlyConfigured):
  28. backends.by_name('xxx.xxx:foo', app.loader)
  29. def test_backend_can_not_be_module(self, app):
  30. with pytest.raises(ImproperlyConfigured):
  31. backends.by_name(pytest, app.loader)