def test_postprocessor(monkeypatch): """ Test a postprocessor which turns a redis url into a Django compatible cache url. """ redis_url = 'redis://:[email protected]:6379/0' monkeypatch.setenv('redis_url', redis_url) expected = { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': '127.0.0.1:6379:0', 'OPTIONS': { 'PASSWORD': '******' } } def django_redis(url): return { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': '{}:{}:{}'.format(url.hostname, url.port, url.path.strip('/')), 'OPTIONS': { 'PASSWORD': url.password } } assert_type_value(dict, expected, env.url('redis_url', postprocessor=django_redis))
def test_postprocessor(monkeypatch): """ Test a postprocessor which turns a redis url into a Django compatible cache url. """ redis_url = 'redis://:[email protected]:6379/0' monkeypatch.setenv('redis_url', redis_url) expected = {'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': '127.0.0.1:6379:0', 'OPTIONS': {'PASSWORD': '******'}} def django_redis(url): return { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': '{}:{}:{}'.format(url.hostname, url.port, url.path.strip('/')), 'OPTIONS': {'PASSWORD': url.password}} assert_type_value(dict, expected, env.url('redis_url', postprocessor=django_redis))
def test_url(): url = urlparse.urlparse('https://example.com/path?query=1') assert_type_value(url.__class__, url, env.url('URL'))