Beispiel #1
0
def test_wrong_settings(db_session, dummy_request):
    add_settings(TestWrongSettingsDict)

    root = get_root()
    view = SettingsView(root, dummy_request)
    assert type(view) == SettingsView

    with pytest.raises(NameError):
        view.view()
def populate_settings():  # pragma: no cover

    def get_types():
        foo = get_settings()['kotti.available_types']
        bar = [(str(i)[8:-2], str(i)[8:-2]) for i in foo]
        return bar

    class DisqusShortnameSchemaNode(SchemaNode):
        name = 'disqus_shortname'
        title = _(u'Disqus shortname')
        description = _(u'The shortname with which you registered your site. '
                        u'Required for the commenting system to work!')
        missing = ''
        default = ''

    class DisqusBaseUrlSchemaNode(SchemaNode):
        name = 'disqus_base_url'
        title = _(u'Base URL')
        description = _(u'Base URL for Disqus commenting system. Useful if '
                        u'you move your site to another URL but want to keep '
                        u'comments. Defaults to current application URL.')
        missing = ''
        default = ''

    class DisqusAvailableTypesSchemaNode(SchemaNode):
        extra_types = get_settings()['kotti_disqus.extra_types'].split()

        name = 'disqus_available_types'
        title = _(u'Available types')
        description = _(u'Select the types on which you want to enable '
                        u'comments.')
        if extra_types:
            description = _(u"Select the types on which you want to enable "
                            u"comments. There are some types enabled via "
                            u"'kotti_disqus.extra_types' that cannot be "
                            u"disabled.")
        missing = []
        default = extra_types
        widget = CheckboxChoiceWidget(values=get_types())

    class KottiDisqusSettingsSchema(MappingSchema):
        disqus_shortname = DisqusShortnameSchemaNode(String())
        disqus_base_url = DisqusBaseUrlSchemaNode(String())
        disqus_available_types = DisqusAvailableTypesSchemaNode(Set())

    KottiDisqusSettings = {
        'name': 'kotti_disqus_settings',
        'title': _(u'Disqus settings'),
        'description': _(u"Settings for kotti_disqus"),
        'success_message': _(u"Successfully saved Disqus settings."),
        'schema_factory': KottiDisqusSettingsSchema,
    }

    add_settings(KottiDisqusSettings)
Beispiel #3
0
def test_settingtab_with_schema(db_session, dummy_request):
    add_settings(TestSettingsSchema)
    root = get_root()
    view = SettingsView(root, dummy_request)
    assert type(view) == SettingsView

    rendered = view.view()
    assert "settings_form_views" in rendered

    name = "test_settings_schema"
    for ren in rendered["settings_form_views"]:
        if name is not None and name == ren["view"].name:
            view = ren

    assert view["view"].title == "Testsettings Schema"
    assert view["form"].startswith("<form")
    se = 'name="kotti_settings-teststringsetting" value="hello world"'
    assert se in view["form"]
    se = 'name="kotti_settings-testrageintsetting" value="5"'
    assert se in view["form"]
Beispiel #4
0
def test_settingtab_with_dict(db_session, dummy_request):
    add_settings(TestSettingsDict)

    root = get_root()
    view = SettingsView(root, dummy_request)
    assert type(view) == SettingsView

    rendered = view.view()
    assert "settings_form_views" in rendered

    name = "test_settings_dict"
    for ren in rendered["settings_form_views"]:
        if name is not None and name == ren["view"].name:
            view = ren

    assert view["view"].title == "Testsettings Dict"
    assert view["form"].startswith("<form")
    assert 'name="kotti_settings-testsetting_1"' in view["form"]
    assert 'value="my first string"' in view["form"]
    assert 'name="kotti_settings-testsetting_2"' in view["form"]
    assert 'value="23"' in view["form"]
Beispiel #5
0
def test_events_subscriber(db_session, settings_events, root, dummy_request):
    global VALUE
    from kotti_settings.util import add_settings
    test_settings = {
        'name': 'test-event-setting',
        'title': "Some settings.",
        'settings': [
            {'type': 'String',
             'name': 'evt_test_setting',
             'title': 'evt test setting', },
        ]
    }
    add_settings(test_settings)

    dummy_request.POST['__formid__'] = 'form_id'
    with patch('kotti_settings.form.SettingsFormView.form_id',
               new_callable=PropertyMock) as mock_meth:
        mock_meth.return_value = 'form_id'
        view = SettingsFormView(root, dummy_request)
        view.save_success({})
        assert VALUE == 'bar'
Beispiel #6
0
def test_get_setting(db_session, root):
    from kotti_settings.util import add_settings
    from kotti_settings.util import get_setting
    test_settings = {
        'name': 'test-get-setting',
        'title': "Some test settings.",
        'settings': [
            {'type': 'String',
             'name': 'first_test_setting',
             'title': 'first test setting',
             'default': 'first test string', },
            {'type': 'Integer',
             'name': 'second_test_setting',
             'title': 'second test setting',
             'default': 5, },
        ]
    }
    add_settings(test_settings)

    first = get_setting('first_test_setting')
    assert first == 'first test string'
    second = get_setting('kotti_settings-second_test_setting')
    assert second == 5
Beispiel #7
0
def test_add_settings_with_missing_attributes(db_session):
    from kotti_settings.util import add_settings

    TestSettings = {
        'description': "Some settings in a dict.",
        'name': 'a name',
        'success_message': u"Successfully saved test settings.",
        'settings': [
            {'type': 'String',
             'description': 'a test setting',
             'default': 'my first string', },
        ]
    }
    with pytest.raises(ValueError) as excinfo:
        add_settings(TestSettings)
    assert str(excinfo.value) == 'A setting has to have a name.'

    TestSettings['settings'][0]['name'] = 'testsetting'
    with pytest.raises(ValueError) as excinfo:
        add_settings(TestSettings)
    assert str(excinfo.value) == 'A setting has to have a title.'

    TestSettings['settings'][0]['title'] = 'test title'
    assert add_settings(TestSettings) == None
Beispiel #8
0
def populate():
    add_settings(NavigationSettingsLeft)
    add_settings(NavigationSettingsRight)
    add_settings(NavigationSettingsTop)
    add_settings(NavigationSettingsAboveContent)
    add_settings(NavigationSettingsBelowContent)
    add_settings(NavigationSettingsBeforeBodyEnd)

    if get_setting(u'left_display_type'):
        assign_slot(u'navigation-widget', 'left')
    if get_setting(u'right_display_type'):
        assign_slot(u'navigation-widget', 'right')
    if get_setting(u'abovecontent_display_type'):
        assign_slot(u'navigation-widget', 'abovecontent')
    if get_setting(u'belowcontent_display_type'):
        assign_slot(u'navigation-widget', 'belowcontent')
    if get_setting(u'beforebodyend_display_type'):
        assign_slot(u'navigation-widget', 'beforebodyend')
Beispiel #9
0
def populate():
    add_settings(TagcloudSettings)
    slot = get_setting('slot', u'left')
    assign_slot('tagcloud-widget', slot)
Beispiel #10
0
def populate():
    add_settings(ContactFormSettings)
Beispiel #11
0
def populate_settings():
    add_settings(KottiBlogSettings)
Beispiel #12
0
def populate():
    add_settings(contenpreview_settings)
Beispiel #13
0
def populate():
    add_settings(GridSettings)
    slot = get_setting(u'slot', u'belowcontent')
    assign_slot('grid-widget', slot)
Beispiel #14
0
def _add_browser_settings():
    add_settings(TestSettingsSchemaBrowser)
    add_settings(TestSettingsDict)
Beispiel #15
0
def populate_settings():
    add_settings(KottiSocialbuttonsSettings)
Beispiel #16
0
def populate_settings():
    add_settings(KottiBlogToolSettings)
Beispiel #17
0
def populate_settings():
    add_settings(KottiSocialbuttonsSettings)