repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
saleor
saleor/discount/interface.py
.py
from dataclasses import dataclass from decimal import Decimal from typing import TYPE_CHECKING, NamedTuple, Optional from . import DiscountType, DiscountValueType from .models import PromotionRule, Voucher if TYPE_CHECKING: from ..product.models import ( ProductVariantChannelListing, VariantChanne...
135
4,318
saleor
saleor/discount/tasks.py
.py
import datetime from collections import Counter, defaultdict from typing import TYPE_CHECKING import graphene from celery.utils.log import get_task_logger from django.conf import settings from django.db.models import Exists, F, OuterRef, Q, QuerySet from ..celeryconf import app from ..core.db.connection import allow_...
394
14,653
saleor
saleor/discount/events.py
.py
import graphene from ..account.models import User from ..app.models import App from . import PromotionEvents from .models import Promotion, PromotionEvent, PromotionRule def _promotion_base_event( promotion: Promotion, user: User | None, app: App | None, type: str, ): return PromotionEvent.object...
103
2,518
saleor
saleor/discount/tests/test_tasks.py
.py
import datetime from decimal import Decimal from unittest.mock import ANY, patch import graphene import pytest from django.db.models import Exists, OuterRef from django.utils import timezone from freezegun import freeze_time from ...order.models import Order from ...product.models import ProductChannelListing, Produc...
477
17,387
saleor
saleor/discount/tests/test_discounts.py
.py
import datetime from decimal import Decimal import graphene import pytest from django.utils import timezone from prices import Money, TaxedMoney from ...checkout.fetch import CheckoutLineInfo from ...discount.interface import VariantPromotionRuleInfo from ...order import OrderStatus from .. import DiscountType, Disco...
804
23,466
saleor
saleor/discount/tests/test_rounding_issue.py
.py
from decimal import Decimal import pytest from ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines from ...checkout.tests.utils import add_variant_to_checkout from ...discount.models import PromotionRule from ...plugins.manager import get_plugins_manager from ...product.models import Product, ProductVa...
114
4,246
saleor
saleor/discount/tests/test_utils/test_copy_unit_discount_data_to_order_line.py
.py
from decimal import Decimal import graphene from ....order.fetch import fetch_draft_order_lines_info from ... import DiscountType, DiscountValueType from ...models import PromotionRule from ...utils.order import update_unit_discount_data_on_order_lines_info def test_copy_unit_discount_data_to_order_line_multiple_di...
97
3,285
saleor
saleor/discount/tests/test_utils/test_get_customer_email_for_voucher_usage.py
.py
from ...utils.voucher import get_customer_email_for_voucher_usage def test_get_customer_email_for_voucher_usage_for_checkout_info_without_user_data( checkout_info, customer_user ): # given checkout_info.user = None checkout_info.checkout.email = None checkout_info.checkout.user = None # when ...
132
3,112
saleor
saleor/discount/tests/test_utils/test_create_voucher_discount_object_for_order.py
.py
from decimal import Decimal import graphene from ....core.prices import Money, quantize_price from ....core.taxes import zero_money from ....order import OrderStatus from ....order.calculations import fetch_order_prices_if_expired from ... import DiscountType, DiscountValueType, VoucherType from ...models import Orde...
1,086
41,443
saleor
saleor/discount/tests/test_utils/test_fetch_promotion_rules_for_checkout.py
.py
from decimal import Decimal from ... import RewardType, RewardValueType from ...models import PromotionRule from ...utils.promotion import fetch_promotion_rules_for_checkout_or_order def test_fetch_promotion_rules_for_checkout( checkout, checkout_for_cc, order_promotion_rule ): # given rule = order_promo...
119
3,246
saleor
saleor/discount/tests/test_utils/test_mark_promotion_rules_as_dirty.py
.py
import datetime from decimal import Decimal from unittest.mock import patch import graphene from ... import RewardValueType from ...models import Promotion, PromotionRule from ...utils.promotion import mark_catalogue_promotion_rules_as_dirty @patch("saleor.discount.utils.promotion.PromotionRule.objects.filter") def...
94
2,761
saleor
saleor/discount/tests/test_utils/test_update_voucher_discount_object_for_order.py
.py
from decimal import Decimal import pytest from prices import Money from ....core.prices import quantize_price from ....core.taxes import zero_money from ....order import OrderStatus from ....order.calculations import fetch_order_prices_if_expired from ... import DiscountType, DiscountValueType, VoucherType from ...mo...
1,221
47,678
saleor
saleor/discount/tests/test_utils/test_fetch_promotion_rules_for_order.py
.py
from decimal import Decimal from ... import RewardType, RewardValueType from ...models import PromotionRule from ...utils.promotion import fetch_promotion_rules_for_checkout_or_order def test_fetch_promotion_rules_for_order(order, order_line_JPY, order_promotion_rule): # given rule = order_promotion_rule ...
97
2,852
saleor
saleor/discount/tests/test_utils/test_calculate_discounted_price_for_promotions.py
.py
from decimal import Decimal import graphene from ... import PromotionRuleInfo, RewardValueType from ...models import Promotion, PromotionRule from ...utils.promotion import calculate_discounted_price_for_promotions def test_variant_discounts_multiple_promotions(product, channel_USD): # given variant = produ...
169
5,333
saleor
saleor/discount/tests/test_utils/test_create_or_update_discount_objects_from_promotion_for_order.py
.py
from decimal import Decimal import graphene from ....order.fetch import fetch_draft_order_lines_info from ....product.models import ( ProductVariantChannelListing, VariantChannelListingPromotionRule, ) from ....warehouse.models import Stock from ... import DiscountType, DiscountValueType, RewardType, RewardVa...
545
19,752
saleor
saleor/discount/tests/test_utils/test_mark_active_promotion_rules_as_dirty.py
.py
import datetime from decimal import Decimal from unittest.mock import patch import graphene from ... import RewardValueType from ...models import Promotion, PromotionRule from ...utils.promotion import mark_active_catalogue_promotion_rules_as_dirty @patch("saleor.discount.utils.promotion.PromotionRule.channels.thro...
136
4,212
saleor
saleor/discount/tests/test_utils/test_update_rule_variant_relation.py
.py
from decimal import Decimal import graphene from ... import RewardValueType from ...models import PromotionRule from ...utils.promotion import update_rule_variant_relation def test_update_rule_variant_relation( catalogue_promotion_without_rules, channel_USD, product_variant_list ): # given promotion = c...
53
1,821
saleor
saleor/discount/tests/test_utils/test_get_variants_to_promotions_map.py
.py
from decimal import Decimal import graphene from ....product.models import ProductVariant from ....product.utils.variants import fetch_variants_for_promotion_rules from ... import PromotionRuleInfo, RewardValueType from ...models import Promotion, PromotionRule from ...utils.promotion import get_variants_to_promotion...
158
5,015
saleor
saleor/discount/tests/test_utils/test_create_or_update_discount_objects_from_promotion_for_checkout.py
.py
import datetime from decimal import Decimal from unittest.mock import patch import graphene import pytest from django.utils import timezone from freezegun import freeze_time from prices import Money, TaxedMoney from ....checkout.base_calculations import base_checkout_total from ....checkout.fetch import fetch_checkou...
2,393
80,619
saleor
saleor/discount/tests/fixtures/benchmark.py
.py
from decimal import Decimal import graphene import pytest from ....discount import RewardValueType from ....discount.models import ( Promotion, PromotionRule, PromotionRuleTranslation, PromotionTranslation, ) @pytest.fixture def promotion_list_for_benchmark(channel_USD, channel_PLN, product_list): ...
107
3,286
saleor
saleor/discount/tests/fixtures/promotion.py
.py
import datetime from decimal import Decimal import graphene import pytest from django.utils import timezone from ....product.utils.variants import fetch_variants_for_promotion_rules from ....tests.utils import dummy_editorjs from ... import PromotionType, RewardType, RewardValueType from ...models import Promotion, P...
336
11,641
saleor
saleor/discount/tests/fixtures/promotion_rule.py
.py
from decimal import Decimal import graphene import pytest from ....tests.utils import dummy_editorjs from ... import RewardType, RewardValueType from ...interface import VariantPromotionRuleInfo from ...models import PromotionRule @pytest.fixture def promotion_rule(channel_USD, catalogue_promotion, product): ru...
98
3,279
saleor
saleor/discount/tests/fixtures/voucher.py
.py
import pytest from django_countries import countries from prices import Money from ... import DiscountValueType, VoucherType from ...models import Voucher, VoucherChannelListing, VoucherCode, VoucherCustomer @pytest.fixture def voucher_without_channel(db): voucher = Voucher.objects.create() VoucherCode.objec...
222
6,502
saleor
saleor/discount/utils/shared.py
.py
from collections import defaultdict from decimal import Decimal from typing import TYPE_CHECKING, Optional, Union import graphene from ...graphql.core.utils import to_global_id_or_none from .. import DiscountType from ..models import ( CheckoutDiscount, CheckoutLineDiscount, OrderDiscount, OrderLineDi...
134
4,957
saleor
saleor/discount/utils/promotion.py
.py
import datetime from collections import defaultdict from collections.abc import Callable, Iterable, Iterator from dataclasses import asdict from decimal import Decimal from itertools import chain from typing import TYPE_CHECKING, NamedTuple, Union, cast from uuid import UUID import graphene from django.conf import set...
972
33,810
saleor
saleor/discount/utils/order.py
.py
from collections.abc import Iterable from decimal import Decimal from typing import TYPE_CHECKING from uuid import UUID from django.conf import settings from django.db import transaction from django.db.models import prefetch_related_objects from prices import TaxedMoney from ...channel.models import Channel from ...c...
422
15,220
saleor
saleor/discount/utils/checkout.py
.py
import datetime from typing import TYPE_CHECKING from django.conf import settings from django.db import transaction from ...checkout.base_calculations import ( base_checkout_delivery_price, base_checkout_subtotal, ) from ...checkout.models import Checkout from ...core.db.connection import allow_writer from .....
329
11,737
saleor
saleor/discount/utils/voucher.py
.py
from collections.abc import Iterable, Sequence from dataclasses import asdict, dataclass from decimal import Decimal from typing import TYPE_CHECKING, Optional, Union, cast from uuid import UUID from django.db.models import Case, Exists, F, IntegerField, OuterRef, Value, When from django.utils import timezone from pri...
720
25,689
saleor
saleor/discount/utils/manual_discount.py
.py
from decimal import ROUND_HALF_UP, Decimal from functools import partial from typing import TypeVar from prices import Money, TaxedMoney, fixed_discount, percentage_discount from ...core.prices import quantize_price from ...core.taxes import zero_money from .. import DiscountValueType from ..models import OrderDiscou...
56
1,872
saleor
saleor/checkout/complete_checkout.py
.py
import datetime import logging from collections.abc import Iterable from decimal import Decimal from typing import TYPE_CHECKING, Any, Optional, cast from uuid import UUID import graphene from django.conf import settings from django.contrib.sites.models import Site from django.core.exceptions import ValidationError fr...
2,035
71,492
saleor
saleor/checkout/delivery_context.py
.py
from dataclasses import dataclass from decimal import Decimal from typing import TYPE_CHECKING, Any, Optional, Union from uuid import UUID from django.conf import settings from django.db import transaction from django.db.models import Q from django.utils import timezone from prices import Money from promise import Pro...
812
29,411
saleor
saleor/checkout/utils.py
.py
"""Checkout-related utility functions.""" from collections.abc import Iterable from decimal import Decimal from typing import TYPE_CHECKING, Optional, cast from uuid import UUID import graphene from django.conf import settings from django.core.exceptions import ValidationError from django.db import transaction from d...
1,069
37,396
saleor
saleor/checkout/lock_objects.py
.py
from django.db.models import QuerySet from .models import Checkout, CheckoutLine def checkout_qs_select_for_update() -> QuerySet[Checkout]: return Checkout.objects.order_by("pk").select_for_update(of=["self"]) def checkout_lines_qs_select_for_update() -> QuerySet[CheckoutLine]: return CheckoutLine.objects....
12
366
saleor
saleor/checkout/error_codes.py
.py
from enum import Enum class CheckoutErrorCode(Enum): BILLING_ADDRESS_NOT_SET = "billing_address_not_set" CHECKOUT_NOT_FULLY_PAID = "checkout_not_fully_paid" GRAPHQL_ERROR = "graphql_error" PRODUCT_NOT_PUBLISHED = "product_not_published" PRODUCT_UNAVAILABLE_FOR_PURCHASE = "product_unavailable_for_p...
72
3,019
saleor
saleor/checkout/models.py
.py
"""Checkout-related ORM models.""" import datetime from decimal import Decimal from operator import attrgetter from typing import TYPE_CHECKING, Optional from uuid import uuid4 from django.conf import settings from django.contrib.postgres.indexes import BTreeIndex, GinIndex from django.contrib.postgres.search import ...
540
19,449
saleor
saleor/checkout/fetch.py
.py
from collections.abc import Iterable from dataclasses import dataclass, field from decimal import Decimal from functools import cached_property from typing import TYPE_CHECKING, Optional from uuid import UUID from django.conf import settings from prices import Money from ..core.prices import quantize_price from ..cor...
388
13,848
saleor
saleor/checkout/__init__.py
.py
import logging logger = logging.getLogger(__name__) class AddressType: BILLING = "billing" SHIPPING = "shipping" CHOICES = [ (BILLING, "Billing"), (SHIPPING, "Shipping"), ] class CheckoutChargeStatus: """Determine the current charge status for the checkout. The checkout is...
70
2,164
saleor
saleor/checkout/calculations.py
.py
import logging from collections.abc import Iterable from decimal import Decimal from typing import TYPE_CHECKING, Union, cast from django.conf import settings from django.db import transaction from django.utils import timezone from prices import Money, TaxedMoney from promise import Promise from ..core.db.connection ...
907
31,937
saleor
saleor/checkout/payment_utils.py
.py
"""Checkout-related utility functions.""" from collections.abc import Iterable from django.conf import settings from django.db.models import Exists, Q from prices import Money from ..core.db.connection import allow_writer from ..core.taxes import zero_money from ..payment.models import TransactionItem from . import ...
136
5,113
saleor
saleor/checkout/problems.py
.py
import datetime from collections import defaultdict from collections.abc import Iterable from dataclasses import dataclass from ..graphql.core.context import ChannelContext from ..product.models import ProductChannelListing, ProductVariant from ..warehouse.models import Stock from .fetch import CheckoutInfo, CheckoutL...
230
6,831
saleor
saleor/checkout/checkout_cleaner.py
.py
import datetime from collections.abc import Iterable from typing import TYPE_CHECKING import graphene from django.core.exceptions import ValidationError from ..core.exceptions import GiftCardNotApplicable from ..core.taxes import TaxError from ..giftcard.models import GiftCard from ..payment import gateway from ..pay...
211
7,697
saleor
saleor/checkout/tasks.py
.py
import datetime import logging from decimal import Decimal import graphene from celery.utils.log import get_task_logger from django.conf import settings from django.core.exceptions import ValidationError from django.db import transaction from django.db.models import Exists, F, OuterRef, Q, QuerySet, Subquery from djan...
370
13,645
saleor
saleor/checkout/base_calculations.py
.py
"""Contains functions which are base for calculating checkout properties. It's recommended to use functions from calculations.py module to take in account plugin manager. Functions from this module return price without taxes (Money instead of TaxedMoney). If you don't need pre-taxed prices use functions from calculati...
328
11,249
saleor
saleor/checkout/actions.py
.py
from decimal import Decimal from typing import TYPE_CHECKING, Optional from ..core.taxes import zero_money from ..core.utils.events import ( call_event, ) from ..payment.models import TransactionItem from ..webhook.event_types import WebhookEventAsyncType from ..webhook.utils import get_webhooks_for_multiple_event...
225
7,763
saleor
saleor/checkout/webhooks/exclude_shipping.py
.py
import json import logging from typing import TYPE_CHECKING, Union from promise import Promise from ...core.db.connection import allow_writer from ...core.utils.json_serializer import CustomJsonEncoder from ...shipping.interface import ExcludedShippingMethod, ShippingMethodData from ...shipping.webhooks.shared import...
77
2,448
saleor
saleor/checkout/webhooks/calculate_taxes.py
.py
import logging from typing import TYPE_CHECKING, Any, Union import graphene from promise import Promise from ...app.models import App from ...core.db.connection import allow_writer from ...core.prices import quantize_price from ...core.taxes import TaxData from ...discount.utils.voucher import is_order_level_voucher ...
189
6,195
saleor
saleor/checkout/webhooks/list_shipping_methods.py
.py
import logging from typing import TYPE_CHECKING, Any, Union from django.conf import settings from promise import Promise from pydantic import ValidationError from ...shipping.interface import ShippingMethodData from ...webhook.event_types import WebhookEventSyncType from ...webhook.payloads import generate_checkout_p...
92
3,397
saleor
saleor/checkout/search/loaders.py
.py
from itertools import chain from typing import TYPE_CHECKING, NamedTuple from uuid import UUID from ...graphql.account.dataloaders import AddressByIdLoader, UserByUserIdLoader from ...graphql.checkout.dataloaders.models import ( CheckoutLinesByCheckoutTokenLoader, TransactionItemsByCheckoutIDLoader, ) from ......
177
6,472
saleor
saleor/checkout/search/indexing.py
.py
from typing import TYPE_CHECKING import graphene from django.conf import settings from django.db import transaction from django.db.models import Value from ...account.search import ( generate_address_search_vector_value, generate_email_vector, ) from ...core.context import with_promise_context from ...core.db...
218
7,302
saleor
saleor/checkout/tests/test_tasks.py
.py
import datetime import logging from decimal import Decimal from unittest import mock from uuid import UUID import graphene import pytest from django.utils import timezone from freezegun import freeze_time from ...channel.models import Channel from ...order import OrderEvents from ...order.models import Order from ......
1,648
53,892
saleor
saleor/checkout/tests/utils.py
.py
from decimal import Decimal from typing import Optional from django.utils import timezone from ...core.exceptions import ProductNotPublished from ...product import models as product_models from ...warehouse.availability import check_stock_and_preorder_quantity from ..fetch import CheckoutInfo from ..models import Che...
129
4,225
saleor
saleor/checkout/tests/test_order_from_checkout.py
.py
from decimal import Decimal from unittest import mock from unittest.mock import patch import pytest from django.core.exceptions import ValidationError from django.test import override_settings from prices import Money, TaxedMoney from promise import Promise from ...channel import MarkAsPaidStrategy from ...checkout.m...
1,073
35,548
saleor
saleor/checkout/tests/test_base_calculations.py
.py
from decimal import Decimal from prices import Money, TaxedMoney from ...discount import DiscountValueType, RewardValueType, VoucherType from ...discount.models import PromotionRule from ...plugins.manager import get_plugins_manager from ...tax.utils import calculate_tax_rate from ..base_calculations import ( bas...
853
30,350
saleor
saleor/checkout/tests/test_checkout.py
.py
import datetime from decimal import Decimal from unittest.mock import Mock, patch import graphene import pytest from django.utils import timezone from django_countries.fields import Country from freezegun import freeze_time from prices import Money, TaxedMoney from ...account.models import Address from ...core.taxes ...
1,964
63,609
saleor
saleor/checkout/tests/test_associate_checkout_with_account.py
.py
import pytest from saleor.channel import MarkAsPaidStrategy from saleor.checkout.complete_checkout import complete_checkout from ...plugins.manager import get_plugins_manager from ..fetch import fetch_checkout_info, fetch_checkout_lines @pytest.mark.django_db @pytest.mark.parametrize( "paid_strategy", [ ...
119
3,316
saleor
saleor/checkout/tests/test_fetch.py
.py
from decimal import Decimal import pytest from prices import Money from ...product.models import ProductChannelListing, ProductVariantChannelListing from ..fetch import ( CheckoutLineInfo, fetch_checkout_lines, ) def test_checkout_line_info_undiscounted_unit_price(checkout_with_item_on_promotion): # giv...
360
11,317
saleor
saleor/checkout/tests/test_delivery_context.py
.py
import datetime from decimal import Decimal from unittest import mock import graphene from django.utils import timezone from freezegun import freeze_time from prices import Money from promise import Promise from ...shipping.interface import ExcludedShippingMethod, ShippingMethodData from ...shipping.models import Shi...
1,732
57,668
saleor
saleor/checkout/tests/test_search_loaders.py
.py
from decimal import Decimal from ...payment.models import Payment, TransactionItem from ..search.loaders import load_checkout_data def test_load_checkout_data(checkout_with_item, customer_user, address, address_usa): # given checkout_with_item.user = customer_user checkout_with_item.billing_address = add...
88
2,414
saleor
saleor/checkout/tests/test_cart.py
.py
import datetime import pytest from django.utils import timezone from measurement.measures import Weight from prices import Money, TaxedMoney from ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines from ...plugins.manager import get_plugins_manager from ...product.models import Category from .. import ...
291
9,727
saleor
saleor/checkout/tests/test_delivery_assignent_to_checkout.py
.py
from decimal import Decimal from ..delivery_context import ( assign_collection_point_to_checkout, assign_shipping_method_to_checkout, remove_delivery_method_from_checkout, ) def test_remove_delivery_method_from_checkout_with_cc( checkout_with_delivery_method_for_cc, ): # given expected_update...
247
8,025
saleor
saleor/checkout/tests/test_migrations_tasks.py
.py
from decimal import Decimal from unittest import mock from ..migrations.tasks.saleor3_21 import ( BILLING_FIELD, SHIPPING_FIELD, fix_shared_address_instances_task, ) from ..migrations.tasks.saleor3_23 import propagate_checkout_deliveries_task from ..models import Checkout, CheckoutDelivery def test_fix_s...
326
11,058
saleor
saleor/checkout/tests/test_checkout_complete.py
.py
import datetime from decimal import Decimal from unittest import mock import pytest from django.core.exceptions import ValidationError from django.test import override_settings from django.utils import timezone from prices import TaxedMoney from ...account import CustomerEvents from ...account.models import CustomerE...
2,863
97,352
saleor
saleor/checkout/tests/test_checkout_cleaner.py
.py
import pytest from ...core.exceptions import GiftCardNotApplicable from ..checkout_cleaner import _validate_gift_cards def test_validate_gift_cards_rejects_mismatched_assignment( checkout_with_gift_card, customer_user, staff_user ): # given checkout = checkout_with_gift_card checkout.user = staff_use...
38
1,188
saleor
saleor/checkout/tests/test_search_indexing.py
.py
from decimal import Decimal from unittest.mock import patch import graphene import pytest from ...payment.models import Payment, TransactionEvent, TransactionItem from ...plugins.manager import get_plugins_manager from ...tests import race_condition from ..fetch import fetch_checkout_info from ..models import Checkou...
730
20,995
saleor
saleor/checkout/tests/test_calculations.py
.py
from decimal import Decimal from typing import Literal from unittest.mock import Mock, patch import pytest from django.db.models import F from django.test import override_settings from django.utils import timezone from freezegun import freeze_time from graphene import Node from prices import Money, TaxedMoney from pro...
1,544
52,118
saleor
saleor/checkout/tests/test_payment_utils.py
.py
from decimal import Decimal import pytest from .. import CheckoutChargeStatus from ..payment_utils import update_checkout_payment_statuses @pytest.mark.parametrize( ("checkout_total", "charged_value", "has_lines", "expected_charge_status"), [ (Decimal(-1), Decimal(-1), False, CheckoutChargeStatus.NO...
55
2,026
saleor
saleor/checkout/tests/test_utils.py
.py
from decimal import Decimal import graphene import pytest from prices import Money, TaxedMoney from ...discount import DiscountType, DiscountValueType from ...tax.calculations import get_taxed_undiscounted_price from ..utils import checkout_info_for_logs BASE = Money("35.00", "USD") @pytest.mark.parametrize( (...
92
2,940
saleor
saleor/checkout/tests/test_actions.py
.py
import datetime from decimal import Decimal from unittest.mock import ANY, patch import pytest from django.test import override_settings from django.utils import timezone from freezegun import freeze_time from ...core.models import EventDelivery from ...plugins.manager import get_plugins_manager from ...webhook.event...
1,741
61,532
saleor
saleor/checkout/tests/webhooks/test_calculate_taxes.py
.py
import json from unittest import mock from unittest.mock import ANY import pytest from promise import Promise from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines from ....checkout.webhooks import calculate_taxes as checkout_calculate_taxes from ....core import EventDeliveryStatus from ....core.mo...
258
8,847
saleor
saleor/checkout/tests/webhooks/test_exclude_shipping.py
.py
import json import uuid from decimal import Decimal from unittest import mock import graphene import pytest from measurement.measures import Weight from prices import Money from promise import Promise from ....graphql.core.utils import to_global_id_or_none from ....graphql.tests.utils import get_graphql_content from ...
449
13,824
saleor
saleor/checkout/tests/webhooks/test_list_shipping_methods.py
.py
from unittest import mock from ....webhook.response_schemas.utils.annotations import logger as annotations_logger from ...webhooks.list_shipping_methods import ( _parse_list_shipping_methods_response, list_shipping_methods_for_checkout, ) @mock.patch("saleor.webhook.transport.synchronous.transport.send_webho...
145
3,749
saleor
saleor/checkout/tests/webhooks/static_payloads/test_calculate_taxes.py
.py
import json from decimal import Decimal from unittest.mock import Mock, patch import graphene import pytest from prices import Money from .....core.prices import quantize_price from .....discount import DiscountType, RewardValueType from .....discount.models import CheckoutDiscount, CheckoutLineDiscount, PromotionRul...
877
32,664
saleor
saleor/checkout/tests/webhooks/static_payloads/test_exclude_shipping.py
.py
import json from decimal import Decimal import graphene from measurement.measures import Weight from prices import Money from .....shipping.interface import ShippingMethodData from ....webhooks.exclude_shipping import ( _generate_excluded_shipping_methods_for_checkout_payload, ) def test_generate_excluded_shipp...
73
2,127
saleor
saleor/checkout/tests/webhooks/subscriptions/test_calculate_taxes.py
.py
import json from unittest.mock import ANY import pytest from freezegun import freeze_time from .....discount.models import PromotionRule from .....graphql.core.utils import to_global_id_or_none from .....tax import TaxableObjectDiscountType from .....webhook.event_types import WebhookEventSyncType from .....webhook.m...
576
18,206
saleor
saleor/checkout/tests/webhooks/subscriptions/test_exclude_shipping.py
.py
import json import graphene import pytest from .....shipping.interface import ShippingMethodData from .....shipping.models import ShippingMethod from .....shipping.utils import convert_to_shipping_method_data from .....webhook.event_types import WebhookEventSyncType from .....webhook.transport.asynchronous.transport ...
257
7,146
saleor
saleor/checkout/tests/webhooks/subscriptions/test_list_shipping_methods.py
.py
import json import graphene import pytest from .....shipping.interface import ShippingMethodData from .....shipping.models import ShippingMethod from .....shipping.utils import convert_to_shipping_method_data from .....webhook.event_types import WebhookEventSyncType from .....webhook.transport.asynchronous.transport ...
114
3,323
saleor
saleor/checkout/tests/fixtures/checkout_with_transaction.py
.py
from decimal import Decimal import pytest from ....payment.models import TransactionItem @pytest.fixture def checkout_with_item_and_transaction_item(checkout_with_item): TransactionItem.objects.create( name="Credit card", psp_reference="PSP ref", available_actions=["refund"], cur...
19
447
saleor
saleor/checkout/tests/fixtures/checkout_line.py
.py
import datetime import pytest from django.utils import timezone from ....plugins.manager import get_plugins_manager from ....warehouse.models import PreorderReservation, Reservation from ...fetch import fetch_checkout_info from ..utils import add_variant_to_checkout @pytest.fixture def checkout_line(checkout_with_i...
115
3,213
saleor
saleor/checkout/tests/fixtures/benchmark.py
.py
import pytest from prices import Money, TaxedMoney from ....checkout.models import Checkout CHECKOUT_COUNT_IN_BENCHMARKS = 10 @pytest.fixture def checkouts_for_benchmarks( channel_USD, channel_PLN, address, users_for_order_benchmarks, variant_with_image, shipping_method, ): checkouts = [...
30
782
saleor
saleor/checkout/tests/fixtures/checkout_line_info.py
.py
import pytest from ...fetch import fetch_checkout_lines @pytest.fixture def checkout_lines_info(checkout_with_items, categories, published_collections): lines = checkout_with_items.lines.all() category1, category2 = categories product1 = lines[0].variant.product product1.category = category1 pro...
45
1,271
saleor
saleor/checkout/tests/fixtures/checkout_with_prices.py
.py
import datetime from decimal import Decimal import pytest from django.utils import timezone from ....plugins.manager import get_plugins_manager from ... import base_calculations from ...fetch import fetch_checkout_info, fetch_checkout_lines from ...models import CheckoutLine @pytest.fixture def checkout_with_prices...
157
5,269
saleor
saleor/checkout/tests/fixtures/checkout.py
.py
import datetime from decimal import Decimal import pytest from django.utils import timezone from ....plugins.manager import get_plugins_manager from ....product.models import ProductVariantChannelListing from ...fetch import fetch_checkout_info, fetch_checkout_lines from ...models import Checkout, CheckoutDelivery, C...
717
22,163
saleor
saleor/checkout/tests/fixtures/checkout_with_discount.py
.py
from decimal import Decimal import graphene import pytest from prices import Money from ....discount import DiscountType, DiscountValueType, RewardType, RewardValueType from ....discount.models import CheckoutDiscount, CheckoutLineDiscount, Promotion from ....plugins.manager import get_plugins_manager from ....produc...
245
7,802
saleor
saleor/checkout/tests/fixtures/checkout_with_payment.py
.py
import pytest from ....payment import ChargeStatus, TransactionKind from ....payment.models import Payment from ....plugins.manager import get_plugins_manager from ... import calculations from ...fetch import fetch_checkout_info, fetch_checkout_lines from ..utils import add_variant_to_checkout @pytest.fixture def ch...
133
3,958
saleor
saleor/checkout/tests/fixtures/checkout_info.py
.py
import pytest from ....plugins.manager import get_plugins_manager from ...fetch import CheckoutInfo, fetch_checkout_info, fetch_checkout_lines @pytest.fixture def checkout_info(checkout_lines_info): manager = get_plugins_manager(allow_replica=False) checkout = checkout_lines_info[0].line.checkout checkou...
35
1,098
saleor
saleor/webhook/utils.py
.py
from collections import defaultdict from collections.abc import Iterable from typing import TYPE_CHECKING, Optional from django.conf import settings from django.db.models import Q from django.db.models.expressions import Exists, OuterRef from ..app.models import App from .event_types import WebhookEventAsyncType, Web...
223
7,966
saleor
saleor/webhook/error_codes.py
.py
from enum import Enum class WebhookErrorCode(Enum): GRAPHQL_ERROR = "graphql_error" INVALID = "invalid" NOT_FOUND = "not_found" REQUIRED = "required" UNIQUE = "unique" DELETE_FAILED = "delete_failed" SYNTAX = "syntax" MISSING_SUBSCRIPTION = "missing_subscription" UNABLE_TO_PARSE = ...
42
1,283
saleor
saleor/webhook/models.py
.py
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.indexes import GinIndex from django.db import models from ..app.models import App from ..app.validators import AppURLValidator from ..core.utils.json_serializer import CustomJsonEncoder from .const import MAX_FILTERABLE_CHANNEL_SLUGS_LI...
76
2,623
saleor
saleor/webhook/__init__.py
.py
from ..core.telemetry import saleor_attributes, tracer def traced_payload_generator(func): def wrapper(*args, **kwargs): operation = f"{func.__name__}" with tracer.start_as_current_span(operation) as span: span.set_attribute(saleor_attributes.COMPONENT, "payloads") return f...
12
361
saleor
saleor/webhook/serializers.py
.py
import datetime from collections import defaultdict from decimal import Decimal from typing import TYPE_CHECKING, Any import graphene from prices import Money from ..attribute import AttributeEntityType, AttributeInputType from ..checkout.fetch import fetch_checkout_lines from ..core.prices import quantize_price from...
195
6,845
saleor
saleor/webhook/payload_helpers.py
.py
from typing import TYPE_CHECKING, Any, Optional import graphene from django.utils import timezone from graphene.utils.str_converters import to_camel_case from .. import __version__ from ..account.models import User if TYPE_CHECKING: from ..plugins.base_plugin import RequestorOrLazyObject def generate_requestor...
39
1,092
saleor
saleor/webhook/payloads.py
.py
import json import uuid from collections import defaultdict from collections.abc import Iterable from dataclasses import asdict from decimal import Decimal from typing import TYPE_CHECKING, Any, Optional, Union import graphene from django.contrib.sites.models import Site from django.db.models import F, QuerySet, Sum ...
1,302
42,548
saleor
saleor/webhook/payload_serializers.py
.py
from collections import OrderedDict from collections.abc import Iterable from typing import Any import graphene from django.core.serializers.json import Serializer as JSONSerializer from django.core.serializers.python import Serializer as PythonBaseSerializer from django.utils.functional import SimpleLazyObject clas...
106
4,583
saleor
saleor/webhook/event_types.py
.py
from typing import Any from ..permission.enums import ( AccountPermissions, AppPermission, BasePermissionEnum, ChannelPermissions, CheckoutPermissions, CustomerTypePermissions, DiscountPermissions, GiftcardPermissions, MenuPermissions, OrderPermissions, PagePermissions, ...
1,047
38,722
saleor
saleor/webhook/deprecated_event_types.py
.py
class WebhookEventType: ANY = "any_events" ORDER_CREATED = "order_created" ORDER_CONFIRMED = "order_confirmed" ORDER_FULLY_PAID = "order_fully_paid" ORDER_UPDATED = "order_updated" ORDER_CANCELLED = "order_cancelled" FULFILLMENT_CANCELED = "fulfillment_canceled" ORDER_FULFILLED = "order_...
166
7,393
saleor
saleor/webhook/validators.py
.py
from django.core.exceptions import ValidationError HEADERS_NUMBER_LIMIT = 5 HEADERS_LENGTH_LIMIT = 998 KEY_CHARS_ALLOWED = ( "!\"#$%&'()*+,-./0123456789;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ) VALUE_CHARS_ALLOWED = ( "!\"#$%&'()*+,-./0123456789;:<=>?@ABCDEFGHIJKLMNOPQRSTU...
52
1,827
saleor
saleor/webhook/const.py
.py
WEBHOOK_CACHE_DEFAULT_TTL: int = 5 * 60 # 5 minutes SYNC_WEBHOOK_FAILURE_CACHE_TTL: int = 1 # 1 second SYNC_WEBHOOK_FAILURE_SENTINEL = ( "WEBHOOK_FAILURE" # Arbitrary value to indicate webhook failure in cache ) APP_ID_PREFIX = "app" MAX_FILTERABLE_CHANNEL_SLUGS_LIMIT = 500
9
283
saleor
saleor/webhook/circuit_breaker/storage.py
.py
import logging import time import uuid from django.core.cache import cache from redis import RedisError from ...graphql.app.enums import CircuitBreakerState logger = logging.getLogger(__name__) class Storage: def set_app_state(self, app_id: int, state: CircuitBreakerState, changed_at: int): pass d...
123
4,045
saleor
saleor/webhook/circuit_breaker/breaker_board.py
.py
import logging import time from typing import TYPE_CHECKING from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.utils.module_loading import import_string from promise import Promise from ...core.telemetry import ( MetricType, Scope, Unit, meter, sal...
247
9,727
saleor
saleor/webhook/transport/utils.py
.py
import dataclasses import datetime import hashlib import json import logging from collections.abc import Callable from contextlib import contextmanager from dataclasses import dataclass from enum import Enum from time import time from typing import Optional from urllib.parse import unquote, urlparse, urlunparse from uu...
812
26,803