From 09eae37b2388a1e599e04954032e433aabc026fb Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 30 Sep 2015 00:30:43 +0200 Subject: [PATCH] Fix test_cache_url_value for newer django-cache-url MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the following failure: ERROR: test_cache_url_value (tests.test_values.ValueTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "…/django-configurations/configurations/values.py", line 158, in to_python return self._caster(value) File "…/django-configurations/.tox/py34-dj18/lib/python3.4/site-packages/django_cache_url.py", line 98, in parse config['LOCATION'] = "%s:%s:%s" % (url.hostname, url.port, db) File "…/pyenv/3.4.3/lib/python3.4/urllib/parse.py", line 156, in port port = int(port, 10) ValueError: invalid literal for int() with base 10: 'port' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "…/django-configurations/tests/test_values.py", line 415, in test_cache_url_value value = CacheURLValue(cache_url) File "…/django-configurations/configurations/values.py", line 420, in __init__ self.default = self.to_python(self.default) File "…/django-configurations/configurations/values.py", line 423, in to_python value = super(DictBackendMixin, self).to_python(value) File "…/django-configurations/configurations/values.py", line 160, in to_python raise ValueError(self.message.format(value)) ValueError: Cannot interpret cache URL value 'redis://user@host:port/1' ---------------------------------------------------------------------- Ran 63 tests in 1.132s FAILED (errors=1) --- tests/test_values.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_values.py b/tests/test_values.py index 482799a..04987cc 100644 --- a/tests/test_values.py +++ b/tests/test_values.py @@ -407,20 +407,26 @@ class ValueTests(TestCase): def test_cache_url_value(self): cache_setting = { 'default': { - 'BACKEND': 'redis_cache.cache.RedisCache', - 'KEY_PREFIX': '', - 'LOCATION': 'host:port:1' + 'BACKEND': 'django_redis.cache.RedisCache', + 'LOCATION': 'host:6379:1' } } - cache_url = 'redis://user@host:port/1' + cache_url = 'redis://user@host:6379/1' value = CacheURLValue(cache_url) self.assertEqual(value.default, cache_setting) value = CacheURLValue() self.assertEqual(value.default, {}) - with env(CACHE_URL='redis://user@host:port/1'): + with env(CACHE_URL='redis://user@host:6379/1'): self.assertEqual(value.setup('CACHE_URL'), cache_setting) with env(CACHE_URL='wrong://user@host:port/1'): - self.assertRaises(KeyError, value.setup, 'TEST') + with self.assertRaises(Exception) as cm: + value.setup('TEST') + self.assertEqual(cm.exception.args[0], 'Unknown backend: "wrong"') + with env(CACHE_URL='redis://user@host:port/1'): + with self.assertRaises(ValueError) as cm: + value.setup('TEST') + self.assertEqual(cm.exception.args[0], + "Cannot interpret cache URL value 'redis://user@host:port/1'") def test_search_url_value(self): value = SearchURLValue()