Exemplo n.º 1
0
def plugin_configuration(db):
    plugin_configuration = PluginConfiguration.objects.create(
        **AvataxPlugin._get_default_configuration()
    )
    config = [
        {"name": "Username or account", "value": "2000134479"},
        {"name": "Password or license", "value": "697932CFCBDE505B"},
    ]
    AvataxPlugin._update_config_items(config, plugin_configuration.configuration)
    plugin_configuration.active = True
    plugin_configuration.save()
    return plugin_configuration
Exemplo n.º 2
0
def test_plugin_uses_configuration_from_db(
    plugin_configuration,
    monkeypatch,
    address_usa,
    site_settings,
    address,
    checkout_with_item,
    shipping_zone,
    discount_info,
    settings,
):
    settings.PLUGINS = ["saleor.extensions.plugins.avatax.plugin.AvataxPlugin"]
    configuration = plugin_configuration(username="******",
                                         password="******",
                                         sandbox=False)
    manager = get_extensions_manager()

    monkeypatch.setattr(
        "saleor.extensions.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
        lambda _: {"PC040156": "desc"},
    )
    site_settings.company_address = address_usa
    site_settings.save()

    checkout_with_item.shipping_address = address
    checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()
    checkout_with_item.save()
    discounts = [discount_info]

    manager.preprocess_order_creation(checkout_with_item, discounts)

    field_to_update = [
        {
            "name": "Username or account",
            "value": "New value"
        },
        {
            "name": "Password or license",
            "value": "Wrong pass"
        },
    ]
    AvataxPlugin._update_config_items(field_to_update,
                                      configuration.configuration)
    configuration.save()

    manager = get_extensions_manager()
    with pytest.raises(TaxError):
        manager.preprocess_order_creation(checkout_with_item, discounts)
Exemplo n.º 3
0
def plugin_configuration(db):
    default_configuration = AvataxPlugin._get_default_configuration()
    for elem in default_configuration["configuration"]:
        if elem["name"] == "Use sandbox":
            elem["value"] = False
    plugin_configuration = PluginConfiguration.objects.create(
        **default_configuration)
    config = [
        {
            "name": "Username or account",
            "value": "2000134479"
        },
        {
            "name": "Password or license",
            "value": "697932CFCBDE505B"
        },
    ]
    AvataxPlugin._update_config_items(config,
                                      plugin_configuration.configuration)
    plugin_configuration.active = True
    plugin_configuration.save()
    return plugin_configuration