Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Return properly when no config for plugin

Mira Szewczykc134eebbfcb2
diff --git a/saleor/dashboard/payment/forms.py b/saleor/dashboard/payment/forms.py
index 897f16ba2e..5a706eecd3 100644
--- a/saleor/dashboard/payment/forms.py
+++ b/saleor/dashboard/payment/forms.py
@@ -40,7 +40,7 @@ class GatewayConfigurationForm(forms.ModelForm):
parsed_fields = {}
structure = current_configuration.configuration
if structure is None:
- raise Exception
+ return {}
for elem in structure:
slug = slugify(elem["name"])
self.fields[slug] = create_custom_form_field(elem)
diff --git a/tests/dashboard/test_payment.py b/tests/dashboard/test_payment.py
index 288730a9f3..0c4b660722 100644
--- a/tests/dashboard/test_payment.py
+++ b/tests/dashboard/test_payment.py
@@ -119,6 +119,13 @@ def test_config_char_field_returned_value(config_char_structure):
}
+def test_gateway_config_returns_empty_dict_when_no_config(plugin_configuration):
+ plugin_configuration.configuration = None
+ plugin_configuration.save()
+ form = GatewayConfigurationForm(BraintreeGatewayPlugin)
+ assert form._prepare_fields_for_given_config(plugin_configuration) == {}
+
+
def test_payment_index_display_only_available_gateways(staff_client):
url = reverse("dashboard:payments-index")
response = staff_client.get(url)