示例#1
0
def test_A_simplejson():
    with mock.reset_modules('thorn.utils.json'):
        from thorn.utils import json
        obj = Mock(name='obj')
        encode = Mock(name='encode')
        assert json.dumps(obj, encode=encode) is encode.return_value
        encode.assert_called_with(obj, cls=json.JsonEncoder)
示例#2
0
 def test_no_implementations(self):
     with mock.mask_modules('pylibmc', 'memcache'):
         with mock.reset_modules('celery.backends.cache'):
             from celery.backends import cache
             cache._imp = [None]
             with pytest.raises(ImproperlyConfigured):
                 cache.get_best_memcache()
示例#3
0
 def test_cached(self):
     with self.mock_pylibmc():
         with mock.reset_modules('celery.backends.cache'):
             from celery.backends import cache
             cache._imp = [None]
             cache.get_best_memcache()[0](behaviors={'foo': 'bar'})
             assert cache._imp[0]
             cache.get_best_memcache()[0]()
示例#4
0
 def test_memcache(self):
     with self.mock_memcache():
         with mock.reset_modules('celery.backends.cache'):
             with mock.mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 assert (cache.get_best_memcache()[0]().__module__ ==
                         'memcache')
示例#5
0
 def test_pylibmc_bytes_key(self):
     with mock.reset_modules('celery.backends.cache'):
         with self.mock_pylibmc():
             from celery.backends import cache
             cache._imp = [None]
             task_id, result = str_to_bytes(uuid()), 42
             b = cache.CacheBackend(backend='memcache', app=self.app)
             b.store_result(task_id, result, state=states.SUCCESS)
             assert b.get_result(task_id) == result