Пример #1
0
def test_form_properly_save_plugin_config(form_data, plugin_configuration):
    assert plugin_configuration.active
    form = GatewayConfigurationForm(BraintreeGatewayPlugin, form_data)
    assert form.is_valid()
    form.save()
    plugin_configuration.refresh_from_db()
    assert plugin_configuration.active is False
    assert isinstance(
        get_config_value("Use sandbox", plugin_configuration.configuration), bool
    )
Пример #2
0
def test_update_config_items_keeps_bool_value(plugin_configuration):
    data_to_update = [
        {"name": "Username", "value": "*****@*****.**"},
        {"name": "Use sandbox", "value": False},
    ]
    plugin_sample = PluginSample()
    qs = PluginConfiguration.objects.all()
    configuration = PluginSample.get_plugin_configuration(qs)
    plugin_sample._update_config_items(data_to_update, configuration.configuration)
    configuration.save()
    configuration.refresh_from_db()
    assert get_config_value("Use sandbox", configuration.configuration) is False
def test_plugin_update_saves_boolean_as_boolean(
    staff_api_client_can_manage_plugins, settings
):
    settings.PLUGINS = ["tests.extensions.sample_plugins.PluginSample"]
    manager = get_extensions_manager()
    plugin = manager.get_plugin_configuration(plugin_name="PluginSample")
    use_sandbox = get_config_value("Use sandbox", plugin.configuration)
    plugin_id = graphene.Node.to_global_id("Plugin", plugin.pk)
    variables = {
        "id": plugin_id,
        "active": plugin.active,
        "configuration": [{"name": "Use sandbox", "value": True}],
    }
    response = staff_api_client_can_manage_plugins.post_graphql(
        PLUGIN_UPDATE_MUTATION, variables
    )
    content = get_graphql_content(response)
    assert len(content["data"]["pluginUpdate"]["errors"]) == 0
    plugin.refresh_from_db()
    use_sandbox_new_value = get_config_value("Use sandbox", plugin.configuration)
    assert type(use_sandbox) == type(use_sandbox_new_value)
Пример #4
0
def test_update_config_items_keeps_bool_value(plugin_configuration, settings):
    settings.PLUGINS = ["tests.extensions.sample_plugins.PluginSample"]
    data_to_update = [
        {
            "name": "Username",
            "value": "*****@*****.**"
        },
        {
            "name": "Use sandbox",
            "value": False
        },
    ]
    manager = get_extensions_manager()
    plugin_sample = manager.get_plugin(PluginSample.PLUGIN_NAME)
    plugin_sample._update_config_items(data_to_update,
                                       plugin_sample.configuration)

    assert get_config_value("Use sandbox",
                            plugin_sample.configuration) is False
Пример #5
0
def test_update_config_items_convert_to_bool_value():
    data_to_update = [
        {
            "name": "Username",
            "value": "*****@*****.**"
        },
        {
            "name": "Use sandbox",
            "value": "false"
        },
    ]
    plugin_sample = PluginSample(
        configuration=PluginSample.DEFAULT_CONFIGURATION,
        active=PluginSample.DEFAULT_ACTIVE,
    )
    plugin_sample._update_config_items(data_to_update,
                                       plugin_sample.configuration)

    assert get_config_value("Use sandbox",
                            plugin_sample.configuration) is False