Esempio n. 1
0
def test_prefix_settings_invalid():
    foo_proxy = SettingsProxy('foo', {'a': 1, 'b': 2})
    bar_proxy = SettingsProxy('bar', {'x': 3, 'y': 4})
    proxy = PrefixSettingsProxy({'foo': foo_proxy, 'bar': bar_proxy})
    pytest.raises(ValueError, proxy.get, 'x')
    pytest.raises(ValueError, proxy.get, 'x_y')
    pytest.raises(ValueError, proxy.set, 'x', 'test')
    pytest.raises(ValueError, proxy.set, 'x_y', 'test')
Esempio n. 2
0
    def _process(self):
        proxy = PrefixSettingsProxy({'core': core_settings, 'social': social_settings})
        form = SettingsForm(obj=FormDefaults(**proxy.get_all()))
        if form.validate_on_submit():
            proxy.set_multi(form.data)
            flash(_('Settings have been saved'), 'success')
            return redirect(url_for('.settings'))

        cephalopod_url, cephalopod_data = self._get_cephalopod_data()
        show_migration_message = cephalopod_settings.get('show_migration_message')
        return WPSettings.render_template('admin/settings.html', 'settings',
                                          form=form,
                                          core_settings=core_settings.get_all(),
                                          social_settings=social_settings.get_all(),
                                          cephalopod_url=cephalopod_url,
                                          cephalopod_data=cephalopod_data,
                                          show_migration_message=show_migration_message)
Esempio n. 3
0
    def _process(self):
        proxy = PrefixSettingsProxy({'core': core_settings, 'social': social_settings})
        form = SettingsForm(obj=FormDefaults(**proxy.get_all()))
        if form.validate_on_submit():
            proxy.set_multi(form.data)
            flash(_('Settings have been saved'), 'success')
            return redirect(url_for('.settings'))

        cephalopod_url, cephalopod_data = self._get_cephalopod_data()
        show_migration_message = cephalopod_settings.get('show_migration_message')
        return WPSettings.render_template('admin/settings.html', 'settings',
                                          form=form,
                                          core_settings=core_settings.get_all(),
                                          social_settings=social_settings.get_all(),
                                          cephalopod_url=cephalopod_url,
                                          cephalopod_data=cephalopod_data,
                                          show_migration_message=show_migration_message)
Esempio n. 4
0
def test_prefix_settings(dummy_event, with_arg):
    kw = {'arg': dummy_event} if with_arg else {'arg': None}
    cls = EventSettingsProxy if with_arg else SettingsProxy
    foo_proxy = cls('foo', {'a': 1, 'b': 2})
    bar_proxy = cls('bar', {'x': None, 'y': 4})
    proxy = PrefixSettingsProxy({
        'foo': foo_proxy,
        'bar': bar_proxy
    },
                                has_arg=with_arg)
    proxy.set('bar_x', 3, **kw)
    assert proxy.get_all(**kw) == {
        'foo_a': 1,
        'foo_b': 2,
        'bar_x': 3,
        'bar_y': 4
    }
    assert proxy.get_all(no_defaults=True, **kw) == {'bar_x': 3}
    assert proxy.get('foo_a', **kw) == 1
    assert proxy.get('bar_y', 'test', **kw) == 'test'
    proxy.set_multi({'foo_a': 11, 'bar_x': 33}, **kw)
    assert proxy.get('foo_a', **kw) == 11
    assert proxy.get('bar_x', **kw) == 33
    proxy.delete('foo_a', 'bar_x', **kw)
    assert proxy.get('foo_a', **kw) == 1
    assert proxy.get('bar_x', **kw) is None
    proxy.set_multi({'foo_a': 11, 'bar_x': 33}, **kw)
    proxy.delete_all(**kw)
    assert proxy.get_all(no_defaults=True, **kw) == {}
Esempio n. 5
0
def test_prefix_settings(dummy_event, with_arg):
    kw = {'arg': dummy_event} if with_arg else {'arg': None}
    cls = EventSettingsProxy if with_arg else SettingsProxy
    foo_proxy = cls('foo', {'a': 1, 'b': 2})
    bar_proxy = cls('bar', {'x': None, 'y': 4})
    proxy = PrefixSettingsProxy({'foo': foo_proxy, 'bar': bar_proxy}, has_arg=with_arg)
    proxy.set('bar_x', 3, **kw)
    assert proxy.get_all(**kw) == {'foo_a': 1, 'foo_b': 2, 'bar_x': 3, 'bar_y': 4}
    assert proxy.get_all(no_defaults=True, **kw) == {'bar_x': 3}
    assert proxy.get('foo_a', **kw) == 1
    assert proxy.get('bar_y', 'test', **kw) == 'test'
    proxy.set_multi({'foo_a': 11, 'bar_x': 33}, **kw)
    assert proxy.get('foo_a', **kw) == 11
    assert proxy.get('bar_x', **kw) == 33
    proxy.delete('foo_a', 'bar_x', **kw)
    assert proxy.get('foo_a', **kw) == 1
    assert proxy.get('bar_x', **kw) is None
    proxy.set_multi({'foo_a': 11, 'bar_x': 33}, **kw)
    proxy.delete_all(**kw)
    assert proxy.get_all(no_defaults=True, **kw) == {}