예제 #1
0
def test_get_category_variants_and_prices(default_category, product_in_stock,
                                          request_cart_with_item):
    result = list(
        utils.get_category_variants_and_prices(request_cart_with_item,
                                               default_category))
    variant = product_in_stock.variants.get()
    assert result[0][0] == variant
예제 #2
0
def test_get_category_variants_and_prices_product_with_many_categories(
        cart, default_category, product_in_stock):
    # Test: don't duplicate percentage voucher
    # when product is in more than one category with discount
    category = Category.objects.create(name='Foobar',
                                       slug='foo',
                                       parent=default_category)
    product_in_stock.price = Decimal('10.00')
    product_in_stock.save()
    product_in_stock.categories.add(category)
    variant = product_in_stock.variants.first()
    cart.add(variant, check_quantity=False)

    discounted_products = list(
        get_category_variants_and_prices(cart, default_category))
    assert len(discounted_products) == 1

    voucher = Voucher.objects.create(
        category=default_category,
        type=VoucherType.CATEGORY,
        discount_value='10.0',
        code='foobar',
        discount_value_type=DiscountValueType.PERCENTAGE)
    checkout_mock = Mock(spec=Checkout, cart=cart)
    discount = voucher.get_discount_for_checkout(checkout_mock)
    # 10% of 10.00 is 1.00
    assert discount.amount == Price('1.00', currency=discount.amount.currency)
예제 #3
0
def test_get_category_variants_and_prices(default_category, product_in_stock,
                                          request_cart_with_item):
    variant = product_in_stock.variants.get()
    top_category = Category.objects.create(name='foo', slug='bar')
    product_in_stock.categories.add(top_category)
    default_category.parent = top_category
    default_category.save()
    result = list(utils.get_category_variants_and_prices(request_cart_with_item,
                                                         top_category))
    assert result[0][0] == variant
예제 #4
0
def test_get_category_variants_and_prices(
        default_category, product_in_stock, request_cart_with_item):
    variant = product_in_stock.variants.get()
    top_category = Category.objects.create(name='foo', slug='bar')
    product_in_stock.categories.add(top_category)
    default_category.parent = top_category
    default_category.save()
    result = list(utils.get_category_variants_and_prices(
        request_cart_with_item, top_category))
    assert result[0][0] == variant
예제 #5
0
def test_get_category_variants_and_prices_product_with_many_categories(cart, default_category,
                                                                       product_in_stock):
    # Test: don't duplicate percentage voucher
    # when product is in more than one category with discount
    category = Category.objects.create(name='Foobar', slug='foo', parent=default_category)
    product_in_stock.price = Decimal('10.00')
    product_in_stock.save()
    product_in_stock.categories.add(category)
    variant = product_in_stock.variants.first()
    cart.add(variant, check_quantity=False)

    discounted_products = list(get_category_variants_and_prices(cart, default_category))
    assert len(discounted_products) == 1

    voucher = Voucher.objects.create(category=default_category, type=Voucher.CATEGORY_TYPE,
                                     discount_value='10.0', code='foobar',
                                     discount_value_type=Voucher.DISCOUNT_VALUE_PERCENTAGE)
    checkout_mock = Mock(spec=Checkout, cart=cart)
    discount = voucher.get_discount_for_checkout(checkout_mock)
    assert discount.amount == Price('1.00', currency=discount.amount.currency)  # 10% for 10 is 1
예제 #6
0
파일: test_cart.py 프로젝트: patrys/saleor
def test_get_category_variants_and_prices(
        default_category, product_in_stock, request_cart_with_item):
    result = list(utils.get_category_variants_and_prices(
        request_cart_with_item, default_category))
    variant = product_in_stock.variants.get()
    assert result[0][0] == variant