Permalink
Browse files

HUE-787 [Desktop] Config dump view uses raw values instead of type ca…

…sed values in template.

BoundConfig object can now return 'raw' config values via 'get_raw' method.
Config object get_value method can return both type cased values and original config values.
Added Test case to test 'WHITELIST', which is regex, and ensure the 'WHITELIST' config is in response as a string.
  • Loading branch information...
abec committed Aug 10, 2012
1 parent 220f252 commit e2cc325853cfb68d422493f501181d93e0ecfb00
View
@@ -72,3 +72,6 @@ desktop/logs
# Maven's target directory
target
+
+# Reviewboard config file
+.reviewboardrc
@@ -130,7 +130,12 @@ def _get_data_and_presence(self):
def get(self):
"""Get the data, or its default value."""
data, present = self._get_data_and_presence()
- return self.config.get_value(data, present=present, prefix=self.prefix)
+ return self.config.get_value(data, present=present, prefix=self.prefix, coerce_type=True)
+
+ def get_raw(self):
+ """Get raw config value. This maybe a non-string or non-iterable object."""
+ data, present = self._get_data_and_presence()
+ return self.config.get_value(data, present=present, prefix=self.prefix, coerce_type=False)
def set_for_testing(self, data=None, present=True):
"""
@@ -225,7 +230,7 @@ def bind(self, conf, prefix):
"""
return BoundConfig(config=self, bind_to=conf, grab_key=self.key, prefix=prefix)
- def get_value(self, val, present, prefix=None):
+ def get_value(self, val, present, prefix=None, coerce_type=True):
"""
Return the value for this configuration variable from the
currently loaded configuration.
@@ -240,7 +245,10 @@ def get_value(self, val, present, prefix=None):
raw_val = val
else:
raw_val = self.default
- return self._coerce_type(raw_val, prefix)
+ if coerce_type:
+ return self._coerce_type(raw_val, prefix)
+ else:
+ return raw_val
def validate(self, source):
"""
@@ -90,7 +90,7 @@ ${layout.menubar(section='dump_config')}
${recurse(v, depth + 1)}
% endfor
% else:
- <p>${str(config_obj.get())}</p>
+ <p>${str(config_obj.get_raw())}</p>
<p class="dump_config_help"><i>${config_obj.config.help or _('No help available.')}</i></p>
<p class="dump_config_default">${_('Default:')} <i>${config_obj.config.default}</i></p>
% endif
@@ -31,6 +31,7 @@
import time
from desktop.lib.django_util import TruncatingModel, PopupException
import desktop.views as views
+import proxy.conf
def setup_test_environment():
"""
@@ -93,6 +94,14 @@ def test_dump_config():
clear()
+ CANARY = "(localhost|127\.0\.0\.1):(50030|50070|50060|50075)"
+ clear = proxy.conf.WHITELIST.set_for_testing(CANARY)
+
+ response1 = c.get('/dump_config')
+ assert_true(CANARY in response1.content)
+
+ clear()
+
def test_prefs():
c = make_logged_in_client()

0 comments on commit e2cc325

Please sign in to comment.