def setUp(self): from google.appengine.api import memcache memcache.flush_all() s = LazySettings(settings_module='kay.tests.live_settings_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) live_settings.set("setting.1", "on") live_settings.set("setting.2", "off")
def test_items(self): items = live_settings.items() self.assertTrue(('setting.1', 'on') in items) self.assertTrue(('setting.2', 'off') in items) live_settings.set("test.value", "on", expire=120) items = live_settings.items() test_items = [('setting.1', 'on'), ('setting.2', 'off'), ('test.value', 'on')] for item in test_items: self.assertTrue(item in items)
def test_keys(self): keys = live_settings.keys() self.assertEqual(keys, ['setting.1','setting.2']) value = live_settings.set("test.value", "on", expire=120) keys = live_settings.keys() self.assertEqual(keys, ['setting.1','setting.2', 'test.value'])
def test_keys(self): keys = live_settings.keys() self.assertEqual(keys, ['setting.1', 'setting.2']) value = live_settings.set("test.value", "on", expire=120) keys = live_settings.keys() self.assertEqual(keys, ['setting.1', 'setting.2', 'test.value'])
def admin(request): nsform = None namespace = '' if 'namespace' in request.args: nsform = KayNamespaceForm() if nsform.validate(request.args): namespace = nsform['namespace'] or '' nsform = nsform.as_widget() object_list = list(KayLiveSetting.all(namespace=namespace)) forms = dict( map(lambda s: (s.key().name(), KayLiveSettingForm(instance=s, initial={ "key_name": s.key().name(), "namespace": namespace, })), object_list) ) if (request.method == "POST"): key_name = request.form.get('key_name') if key_name: form = forms.get(key_name, None) if not form: form = KayLiveSettingForm() if form.validate(request.form): if 'delete' in request.form: _set_flash_msg(request, _("Deleted the setting '%(key)s'" % { 'key': key_name, })) live_settings.delete(form['key_name'], namespace=namespace) if key_name in forms: del forms[key_name] else: _set_flash_msg(request, _("Updated the setting '%(key)s'" % { 'key': key_name, })) forms[key_name] = form form.instance = live_settings.set( form['key_name'], form['value'], namespace=namespace, ) return redirect( "%s?%s" % ( url_for('live_settings/admin'), url_encode(request.args), ), ) new_form = KayLiveSettingForm() return render_to_response('live_settings/admin.html', { 'flash_msg': _get_flash_msg(request), 'to_local_timezone': to_local_timezone, # ensure we have this function 'nsform': nsform, 'namespace': namespace, 'form_list': map(lambda f: (f.instance, f.as_widget()), forms.values()), 'new_form': new_form.as_widget(), })
def test_set(self): value = live_settings.set("test.value", "on", expire=120) self.assertEqual(value.value, "on") self.assertEqual(value.ttl, 120)
def admin(request): nsform = None namespace = '' if 'namespace' in request.args: nsform = KayNamespaceForm() if nsform.validate(request.args): namespace = nsform['namespace'] or '' nsform = nsform.as_widget() object_list = list(KayLiveSetting.all(namespace=namespace)) forms = dict( map( lambda s: (s.key().name(), KayLiveSettingForm(instance=s, initial={ "key_name": s.key().name(), "namespace": namespace, })), object_list)) if (request.method == "POST"): key_name = request.form.get('key_name') if key_name: form = forms.get(key_name, None) if not form: form = KayLiveSettingForm() if form.validate(request.form): if 'delete' in request.form: _set_flash_msg( request, _("Deleted the setting '%(key)s'" % { 'key': key_name, })) live_settings.delete(form['key_name'], namespace=namespace) if key_name in forms: del forms[key_name] else: _set_flash_msg( request, _("Updated the setting '%(key)s'" % { 'key': key_name, })) forms[key_name] = form form.instance = live_settings.set( form['key_name'], form['value'], namespace=namespace, ) return redirect( "%s?%s" % ( url_for('live_settings/admin'), url_encode(request.args), ), ) new_form = KayLiveSettingForm() return render_to_response( 'live_settings/admin.html', { 'flash_msg': _get_flash_msg(request), 'to_local_timezone': to_local_timezone, # ensure we have this function 'nsform': nsform, 'namespace': namespace, 'form_list': map(lambda f: (f.instance, f.as_widget()), forms.values()), 'new_form': new_form.as_widget(), })