Skip to content

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

Split fixtures for Tax and Checkout module (#16842)

Filip Owczareka7e503c04015
diff --git a/conftest.py b/conftest.py
index d3c1ce6dc5..091b1c8d03 100644
--- a/conftest.py
+++ b/conftest.py
@@ -27,15 +27,14 @@ pytest_plugins = [
"saleor.discount.tests.test_utils.fixtures",
"saleor.plugins.tests.fixtures",
"saleor.graphql.tests.fixtures",
- "saleor.graphql.channel.tests.fixtures",
- "saleor.graphql.channel.tests.benchmark.fixtures",
"saleor.graphql.checkout.tests.benchmark.fixtures",
"saleor.graphql.account.tests.benchmark.fixtures",
"saleor.graphql.order.tests.benchmark.fixtures",
"saleor.graphql.giftcard.tests.benchmark.fixtures",
"saleor.graphql.webhook.tests.benchmark.fixtures",
- "saleor.tax.tests.fixtures",
"saleor.webhook.tests.subscription_webhooks.fixtures",
+ "saleor.tax.tests.fixtures",
+ "saleor.channel.tests.fixtures",
]
diff --git a/saleor/channel/tests/fixtures/__init__.py b/saleor/channel/tests/fixtures/__init__.py
new file mode 100644
index 0000000000..25d19d9517
--- /dev/null
+++ b/saleor/channel/tests/fixtures/__init__.py
@@ -0,0 +1 @@
+from .channel import * # noqa: F403
diff --git a/saleor/graphql/channel/tests/fixtures.py b/saleor/channel/tests/fixtures/channel.py
similarity index 55%
rename from saleor/graphql/channel/tests/fixtures.py
rename to saleor/channel/tests/fixtures/channel.py
index 5b163432d9..a8c502081f 100644
--- a/saleor/graphql/channel/tests/fixtures.py
+++ b/saleor/channel/tests/fixtures/channel.py
@@ -3,26 +3,9 @@ from django.conf import settings
from ....channel import AllocationStrategy
from ....channel.models import Channel
-from ....tax import TaxCalculationStrategy
-from ....tax.models import TaxConfiguration
-
-
-def _create_channel_tax_configuration(channel):
- # Use TAX_APP strategy, to enable calculations with plugins by default.
- tax_configuration = TaxConfiguration.objects.create(
- channel=channel,
- metadata={"key": "value"},
- private_metadata={"key": "value"},
- tax_calculation_strategy=TaxCalculationStrategy.TAX_APP,
- )
- tax_configuration.country_exceptions.create(
- country="PL",
- tax_calculation_strategy=TaxCalculationStrategy.TAX_APP,
- )
- tax_configuration.country_exceptions.create(
- country="DE",
- tax_calculation_strategy=TaxCalculationStrategy.TAX_APP,
- )
+from ....graphql.channel.tests.benchmark import CHANNEL_COUNT_IN_BENCHMARKS
+from ....tax.tests.fixtures.utils import create_channel_tax_configuration
+from ....warehouse.models import Warehouse
@pytest.fixture
@@ -36,7 +19,7 @@ def channel_USD(db):
is_active=True,
allocation_strategy=AllocationStrategy.PRIORITIZE_HIGH_STOCK,
)
- _create_channel_tax_configuration(channel)
+ create_channel_tax_configuration(channel)
return channel
@@ -50,7 +33,7 @@ def other_channel_USD(db):
is_active=True,
allocation_strategy=AllocationStrategy.PRIORITIZE_HIGH_STOCK,
)
- _create_channel_tax_configuration(channel)
+ create_channel_tax_configuration(channel)
return channel
@@ -64,7 +47,7 @@ def channel_PLN(db):
is_active=True,
allocation_strategy=AllocationStrategy.PRIORITIZE_HIGH_STOCK,
)
- _create_channel_tax_configuration(channel)
+ create_channel_tax_configuration(channel)
return channel
@@ -78,5 +61,33 @@ def channel_JPY(db):
is_active=True,
allocation_strategy=AllocationStrategy.PRIORITIZE_HIGH_STOCK,
)
- _create_channel_tax_configuration(channel)
+ create_channel_tax_configuration(channel)
return channel
+
+
+def channels_for_benchmark(address):
+ warehouses = [
+ Warehouse(
+ address=address,
+ name=f"Example Warehouse {i}",
+ slug=f"example-warehouse-{i}",
+ )
+ for i in range(CHANNEL_COUNT_IN_BENCHMARKS)
+ ]
+ created_warehouses = Warehouse.objects.bulk_create(warehouses)
+
+ channels = [
+ Channel(
+ name=f"channel {i}",
+ slug=f"channel-{i}",
+ )
+ for i in range(CHANNEL_COUNT_IN_BENCHMARKS)
+ ]
+ created_channels = Channel.objects.bulk_create(channels)
+
+ for channel, warehouse in zip(created_channels, created_warehouses):
+ channel.warehouses.add(warehouse)
+
+ return created_channels
diff --git a/saleor/graphql/channel/tests/benchmark/__init__.py b/saleor/graphql/channel/tests/benchmark/__init__.py
index e69de29bb2..8a5a916d34 100644
--- a/saleor/graphql/channel/tests/benchmark/__init__.py
+++ b/saleor/graphql/channel/tests/benchmark/__init__.py
@@ -0,0 +1 @@
+CHANNEL_COUNT_IN_BENCHMARKS = 10
diff --git a/saleor/graphql/channel/tests/benchmark/fixtures.py b/saleor/graphql/channel/tests/benchmark/fixtures.py
deleted file mode 100644
index fd96738aa9..0000000000
--- a/saleor/graphql/channel/tests/benchmark/fixtures.py
+++ /dev/null
@@ -1,34 +0,0 @@
-import pytest
-
-from .....channel.models import Channel
-from .....warehouse.models import Warehouse
-
-CHANNEL_COUNT_IN_BENCHMARKS = 10
-
-
-def channels_for_benchmark(address):
- warehouses = [
- Warehouse(
- address=address,
- name=f"Example Warehouse {i}",
- slug=f"example-warehouse-{i}",
- )
- for i in range(CHANNEL_COUNT_IN_BENCHMARKS)
- ]
- created_warehouses = Warehouse.objects.bulk_create(warehouses)
-
- channels = [
- Channel(
- name=f"channel {i}",
- slug=f"channel-{i}",
- )
- for i in range(CHANNEL_COUNT_IN_BENCHMARKS)
- ]
- created_channels = Channel.objects.bulk_create(channels)
-
- for channel, warehouse in zip(created_channels, created_warehouses):
- channel.warehouses.add(warehouse)
-
- return created_channels
diff --git a/saleor/tax/tests/fixtures/__init__.py b/saleor/tax/tests/fixtures/__init__.py
new file mode 100644
index 0000000000..4791315cba
--- /dev/null
+++ b/saleor/tax/tests/fixtures/__init__.py
@@ -0,0 +1 @@
+from .tax_class import * # noqa: F403
diff --git a/saleor/tax/tests/fixtures.py b/saleor/tax/tests/fixtures/tax_class.py
similarity index 96%
rename from saleor/tax/tests/fixtures.py
rename to saleor/tax/tests/fixtures/tax_class.py
index e695087aee..5f45f14557 100644
--- a/saleor/tax/tests/fixtures.py
+++ b/saleor/tax/tests/fixtures/tax_class.py
@@ -1,13 +1,13 @@
import pytest
from django_countries import countries
-from ...plugins.avatax import (
+from ....plugins.avatax import (
DEFAULT_TAX_CODE,
META_CODE_KEY,
META_DESCRIPTION_KEY,
TAX_CODE_NON_TAXABLE_PRODUCT,
)
-from ..models import TaxClass, TaxClassCountryRate
+from ...models import TaxClass, TaxClassCountryRate
@pytest.fixture(autouse=True)
diff --git a/saleor/tax/tests/fixtures/utils.py b/saleor/tax/tests/fixtures/utils.py
new file mode 100644
index 0000000000..37006a1ca8
--- /dev/null
+++ b/saleor/tax/tests/fixtures/utils.py
@@ -0,0 +1,20 @@
+from ....tax import TaxCalculationStrategy
+from ....tax.models import TaxConfiguration
+
+
+def create_channel_tax_configuration(channel):
+ # Use TAX_APP strategy, to enable calculations with plugins by default.
+ tax_configuration = TaxConfiguration.objects.create(
+ channel=channel,
+ metadata={"key": "value"},
+ private_metadata={"key": "value"},
+ tax_calculation_strategy=TaxCalculationStrategy.TAX_APP,
+ )
+ tax_configuration.country_exceptions.create(
+ country="PL",
+ tax_calculation_strategy=TaxCalculationStrategy.TAX_APP,
+ )
+ tax_configuration.country_exceptions.create(
+ country="DE",
+ tax_calculation_strategy=TaxCalculationStrategy.TAX_APP,
+ )