test_backends.py 1.3 KB

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