Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move helper function to separate file
Mira Szewczyke4e6a49a182e
diff --git a/saleor/extensions/__init__.py b/saleor/extensions/__init__.pyindex 2ff4b876ae..a85f314694 100644--- a/saleor/extensions/__init__.py+++ b/saleor/extensions/__init__.py@@ -1,10 +1,12 @@import importlib-from typing import List+from typing import Dict, List, NewType, Unionfrom django.utils.translation import pgettext_lazyfrom .checks import check_extensions # NOQA: F401+ConfigurationType = NewType("ConfigurationType", Dict[str, Union[str, bool]])+def discover_plugins_modules(plugins: List[str]):plugins_modules = []diff --git a/tests/api/test_extensions.py b/tests/api/test_extensions.pyindex ea86ddf8ea..1fed1f2f7b 100644--- a/tests/api/test_extensions.py+++ b/tests/api/test_extensions.py@@ -6,6 +6,7 @@ from saleor.extensions.base_plugin import BasePluginfrom saleor.extensions.manager import get_extensions_managerfrom saleor.extensions.models import PluginConfigurationfrom tests.api.utils import get_graphql_content+from tests.extensions.helpers import get_config_valueclass PluginSample(BasePlugin):@@ -38,27 +39,9 @@ class PluginSample(BasePlugin):"description": "Test plugin description","active": True,"configuration": [- {- "name": "Username",- "value": "admin",- "type": ConfigurationTypeField.STRING,- "help_text": "Username input field",- "label": "Username",- },- {- "name": "Password",- "value": "123",- "type": ConfigurationTypeField.STRING,- "help_text": "Password input field",- "label": "Password",- },- {- "name": "Use sandbox",- "value": False,- "type": ConfigurationTypeField.BOOLEAN,- "help_text": "Use sandbox",- "label": "Use sandbox",- },+ {"name": "Username", "value": "admin"},+ {"name": "Password", "value": "123"},+ {"name": "Use sandbox", "value": False},],}return PluginConfiguration.objects.create(**defaults)@@ -100,6 +83,7 @@ def test_query_plugin_configurations(assert len(plugins) == 1plugin = plugins[0]["node"]plugin_configuration = PluginConfiguration.objects.get()+ confiugration_structure = PluginSample.CONFIG_STRUCTUREassert plugin["name"] == plugin_configuration.nameassert plugin["active"] == plugin_configuration.active@@ -110,11 +94,11 @@ def test_query_plugin_configurations(configuration_item["name"]== plugin_configuration.configuration[index]["name"])- assert (- configuration_item["type"]- == plugin_configuration.configuration[index]["type"].upper()- )- if configuration_item["type"] == ConfigurationTypeField.CHOICES:++ if (+ confiugration_structure[configuration_item["name"]]["type"]+ == ConfigurationTypeField.STRING+ ):assert (configuration_item["value"]== plugin_configuration.configuration[index]["value"]@@ -124,14 +108,6 @@ def test_query_plugin_configurations(configuration_item["value"]== str(plugin_configuration.configuration[index]["value"]).lower())- assert (- configuration_item["helpText"]- == plugin_configuration.configuration[index]["help_text"]- )- assert (- configuration_item["label"]- == plugin_configuration.configuration[index]["label"]- )def test_query_plugin_configuration(@@ -169,16 +145,7 @@ def test_query_plugin_configuration(configuration_item = plugin["configuration"][0]assert configuration_item["name"] == plugin_configuration.configuration[0]["name"]- assert (- configuration_item["type"]- == plugin_configuration.configuration[0]["type"].upper()- )assert configuration_item["value"] == plugin_configuration.configuration[0]["value"]- assert (- configuration_item["helpText"]- == plugin_configuration.configuration[0]["help_text"]- )- assert configuration_item["label"] == plugin_configuration.configuration[0]["label"]PLUGIN_UPDATE_MUTATION = """@@ -243,22 +210,10 @@ def test_plugin_configuration_update(first_configuration_item = plugin.configuration[0]assert first_configuration_item["name"] == updated_configuration_item["name"]assert first_configuration_item["value"] == updated_configuration_item["value"]- assert first_configuration_item["type"] == old_configuration[0]["type"]- assert first_configuration_item["help_text"] == old_configuration[0]["help_text"]- assert first_configuration_item["label"] == old_configuration[0]["label"]second_configuration_item = plugin.configuration[1]assert second_configuration_item["name"] == old_configuration[1]["name"]assert second_configuration_item["value"] == old_configuration[1]["value"]- assert second_configuration_item["type"] == old_configuration[1]["type"]- assert second_configuration_item["help_text"] == old_configuration[1]["help_text"]- assert second_configuration_item["label"] == old_configuration[1]["label"]---def get_config_value(field_name, configuration):- for elem in configuration:- if elem["name"] == field_name:- return elem["value"]def test_plugin_update_saves_boolean_as_boolean(diff --git a/tests/dashboard/test_payment.py b/tests/dashboard/test_payment.pyindex 06c9e8122e..7a205c84c2 100644--- a/tests/dashboard/test_payment.py+++ b/tests/dashboard/test_payment.py@@ -8,6 +8,7 @@ from saleor.dashboard.payment.forms import ()from saleor.extensions.models import PluginConfigurationfrom saleor.payment.gateways.braintree.plugin import BraintreeGatewayPlugin+from tests.extensions.helpers import get_config_value@pytest.fixture@@ -189,12 +190,6 @@ def test_gateway_configuration_form_json_field_set_to_false(field_name, form_datassert cleaned_data[field_name]["value"] is False-def get_config_value(field_name, configuration):- for elem in configuration:- if elem["name"] == field_name:- return elem["value"]--def test_form_properly_save_plugin_config(form_data, plugin_configuration):assert plugin_configuration.activeform = GatewayConfigurationForm(BraintreeGatewayPlugin, form_data)diff --git a/tests/extensions/helpers.py b/tests/extensions/helpers.pynew file mode 100644index 0000000000..e03462fa26--- /dev/null+++ b/tests/extensions/helpers.py@@ -0,0 +1,12 @@+from typing import TYPE_CHECKING, Union++if TYPE_CHECKING:+ from saleor.extensions import ConfigurationType+++def get_config_value(+ field_name: str, configuration: "ConfigurationType"+) -> Union[str, bool]:+ for elem in configuration:+ if elem["name"] == field_name:+ return elem["value"]diff --git a/tests/extensions/plugins/test_plugins.py b/tests/extensions/plugins/test_plugins.pyindex 857064b783..e47de9d982 100644--- a/tests/extensions/plugins/test_plugins.py+++ b/tests/extensions/plugins/test_plugins.py@@ -3,6 +3,7 @@ import pytestfrom saleor.extensions import ConfigurationTypeFieldfrom saleor.extensions.base_plugin import BasePluginfrom saleor.extensions.models import PluginConfiguration+from tests.extensions.helpers import get_config_valueclass PluginSample(BasePlugin):@@ -47,12 +48,6 @@ def settings_plugins(settings):]-def get_config_value(field_name, configuration):- for elem in configuration:- if elem["name"] == field_name:- return elem["value"]--def test_update_config_items_keeps_bool_value():data_to_update = [{"name": "Username", "value": "[email protected]"},