Ejemplo n.º 1
0
def test_checkout_shipping_address_with_storage(
        address_objects, shipping, monkeypatch):
    monkeypatch.setattr(
        'saleor.checkout.core.Address.objects', address_objects)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['shipping_address'] = {'id': 1}
    assert checkout.shipping_address == shipping
Ejemplo n.º 2
0
def test_checkout_shipping_does_not_exists(monkeypatch):
    queryset = Mock(get=Mock(side_effect=ShippingMethodCountry.DoesNotExist))
    monkeypatch.setattr(
        'saleor.checkout.core.ShippingMethodCountry.objects', queryset)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['shipping_method_country_id'] = 1
    assert checkout.shipping_method is None
Ejemplo n.º 3
0
def test_checkout_shipping_method(shipping_address, shipping_method, value, monkeypatch):
    queryset = Mock(get=Mock(return_value=shipping_method))
    monkeypatch.setattr(Checkout, 'shipping_address', shipping_address)
    monkeypatch.setattr('saleor.checkout.core.ShippingMethodCountry.objects', queryset)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['shipping_method_country_id'] = 1
    assert checkout.shipping_method == value
Ejemplo n.º 4
0
def test_checkout_shipping_method_setter():
    shipping_method = Mock(id=1)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    assert checkout.modified is False
    checkout.shipping_method = shipping_method
    assert checkout.modified is True
    assert checkout.storage['shipping_method_country_id'] == 1
Ejemplo n.º 5
0
def test_checkout_shipping_address_setter():
    address = Address(first_name='Jan', last_name='Kowalski')
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.shipping_address = address
    assert checkout.storage['shipping_address'] == {
        'city': u'', 'city_area': u'', 'company_name': u'', 'country': '', 'phone': u'',
        'country_area': u'', 'first_name': 'Jan', 'id': None, 'last_name': 'Kowalski',
        'postal_code': u'', 'street_address_1': u'', 'street_address_2': u''}
Ejemplo n.º 6
0
def test_note_in_created_order(request_cart, customer_user, billing_address):
    customer_user.default_billing_address = billing_address
    checkout = Checkout(request_cart, customer_user, 'tracking_code')
    checkout.note = ''
    order = checkout.create_order()
    assert not order.notes.all()
    checkout.note = 'test_note'
    order = checkout.create_order()
    assert order.notes.values()[0].get('content') == 'test_note'
Ejemplo n.º 7
0
def test_index_view(cart, status_code, url, rf):
    checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
    request = rf.get('checkout:index')
    request.user = checkout.user
    request.session = {STORAGE_SESSION_KEY: checkout.for_storage()}
    request.discounts = []
    response = views.index_view(request, checkout, checkout.cart)
    assert response.status_code == status_code
    assert response.url == url
Ejemplo n.º 8
0
def test_checkout_shipping_method_setter():
    shipping_method = Mock(id=1)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    assert checkout.modified is False
    assert checkout._shipping_method is None
    checkout.shipping_method = shipping_method
    assert checkout._shipping_method == shipping_method
    assert checkout.modified is True
    assert checkout.storage['shipping_method_country_id'] == 1
Ejemplo n.º 9
0
def test_checkout_shipping_address_setter():
    address = Address(first_name='Jan', last_name='Kowalski')
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    assert checkout._shipping_address is None
    checkout.shipping_address = address
    assert checkout._shipping_address == address
    assert checkout.storage['shipping_address'] == {
        'city': '', 'city_area': '', 'company_name': '', 'country': '', 'phone': '',
        'country_area': '', 'first_name': 'Jan', 'id': None, 'last_name': 'Kowalski',
        'postal_code': '', 'street_address_1': '', 'street_address_2': ''}
Ejemplo n.º 10
0
def test_checkout_create_order_insufficient_stock(request_cart, customer_user,
                                                  product):
    product_type = product.product_type
    product_type.is_shipping_required = False
    product_type.save()
    variant = product.variants.get()
    request_cart.add(variant, quantity=10, check_quantity=False)
    checkout = Checkout(request_cart, customer_user, 'tracking_code')
    with pytest.raises(InsufficientStock):
        checkout.create_order()
Ejemplo n.º 11
0
def test_checkout_create_order_insufficient_stock(
        request_cart, customer_user, product):
    product_type = product.product_type
    product_type.is_shipping_required = False
    product_type.save()
    variant = product.variants.get()
    request_cart.add(variant, quantity=10, check_quantity=False)
    checkout = Checkout(request_cart, customer_user, 'tracking_code')
    with pytest.raises(InsufficientStock):
        checkout.create_order()
Ejemplo n.º 12
0
def test_index_view(cart, status_code, url, rf, monkeypatch):
    checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
    request = rf.get('checkout:index')
    request.user = checkout.user
    request.session = {STORAGE_SESSION_KEY: checkout.for_storage()}
    request.discounts = []
    monkeypatch.setattr(
        'saleor.cart.utils.get_cart_from_request', lambda req, qs: cart)
    response = views.index_view(request)
    assert response.status_code == status_code
    assert response.url == url
Ejemplo n.º 13
0
def test_index_view(cart, status_code, url, rf, monkeypatch):
    checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
    request = rf.get('checkout:index')
    request.user = checkout.user
    request.session = {STORAGE_SESSION_KEY: checkout.for_storage()}
    request.discounts = []
    monkeypatch.setattr(
        'saleor.cart.utils.get_cart_from_request', lambda req, qs: cart)
    response = views.index_view(request)
    assert response.status_code == status_code
    assert response.url == url
Ejemplo n.º 14
0
def test_checkout_shipping_method(
        shipping_address, shipping_method, value, monkeypatch):
    queryset = Mock(get=Mock(return_value=shipping_method))
    monkeypatch.setattr(Checkout, 'shipping_address', shipping_address)
    monkeypatch.setattr(
        'saleor.checkout.core.ShippingMethodCountry.objects', queryset)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['shipping_method_country_id'] = 1
    assert checkout._shipping_method is None
    assert checkout.shipping_method == value
    assert checkout._shipping_method == value
Ejemplo n.º 15
0
def test_checkout_create_order_insufficient_stock(
        request_cart, customer_user, product_in_stock, billing_address,
        shipping_method):
    product_class = product_in_stock.product_class
    product_class.is_shipping_required = False
    product_class.save()
    customer_user.default_billing_address = billing_address
    customer_user.save()
    variant = product_in_stock.variants.get()
    request_cart.add(variant, quantity=10, check_quantity=False)
    checkout = Checkout(request_cart, customer_user, 'tracking_code')
    with pytest.raises(InsufficientStock):
        checkout.create_order()
Ejemplo n.º 16
0
def test_checkout_deliveries_with_shipping_method(monkeypatch):
    shipping_cost = Money(3, currency=settings.DEFAULT_CURRENCY)
    items_cost = Money(5, currency=settings.DEFAULT_CURRENCY)
    cost_with_shipping = items_cost + shipping_cost

    items_price = TaxedMoney(net=items_cost, gross=items_cost)
    partition = Mock(is_shipping_required=MagicMock(return_value=True),
                     get_total=Mock(return_value=items_price),
                     get_price_per_item=Mock(return_value=items_price))

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]),
                currency=settings.DEFAULT_CURRENCY)

    shipping_price = TaxedMoney(net=shipping_cost, gross=shipping_cost)
    shipping_method_mock = Mock(get_total_price=Mock(
        return_value=shipping_price))
    monkeypatch.setattr(Checkout, 'shipping_method', shipping_method_mock)

    checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
    deliveries = list(checkout.deliveries)

    assert deliveries[0][1] == shipping_price
    assert deliveries[0][2] == TaxedMoney(net=cost_with_shipping,
                                          gross=cost_with_shipping)
    assert deliveries[0][0][0][0] == partition
Ejemplo n.º 17
0
def test_checkout_deliveries_with_shipping_method(monkeypatch):
    shipping_cost = 5
    items_cost = 5

    partition = Mock(
        is_shipping_required=MagicMock(return_value=True),
        get_total=Mock(return_value=Price(items_cost, currency=settings.DEFAULT_CURRENCY)),
        get_price_per_item=Mock(return_value=Price(items_cost, currency=settings.DEFAULT_CURRENCY)))

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]),
                currency=settings.DEFAULT_CURRENCY)

    shipping_method_mock = Mock(get_total=Mock(return_value=Price(shipping_cost, currency=settings.DEFAULT_CURRENCY)))
    monkeypatch.setattr(Checkout, 'shipping_method', shipping_method_mock)

    checkout = Checkout(
        cart, AnonymousUser(), 'tracking_code')

    deliveries = list(checkout.deliveries)
    assert deliveries[0][1] == Price(shipping_cost, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][2] == Price(items_cost + shipping_cost, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][0][0][0] == partition
Ejemplo n.º 18
0
def test_view_get_taxed_total_with_shipping(
        tax_rates_countries, product_in_stock, checkout: Checkout,
        tax_price_factory, multiple_shipping_methods, request_checkout):

    variant = product_in_stock.variants.get()
    checkout.cart.add(variant, 1)

    with request_checkout:
        for shipping_method in multiple_shipping_methods:
            for country, tax_rate in tax_rates_countries.items():
                checkout.shipping_method = shipping_method

                cart_total = float(checkout.get_total().net)
                expected_total = cart_total * (1 + tax_rate)

                resp = tax_price_factory(country)

                assert resp['rate'] == tax_rate
                assert resp['gross'] == expected_total
Ejemplo n.º 19
0
def test_note_in_created_order(request_cart, customer_user, billing_address):
    customer_user.default_billing_address = billing_address
    checkout = Checkout(request_cart, customer_user, 'tracking_code')
    checkout.note = ''
    order = checkout.create_order()
    assert not order.notes.all()
    checkout.note = 'test_note'
    order = checkout.create_order()
    assert order.notes.values()[0].get('content') == 'test_note'
Ejemplo n.º 20
0
def test_checkout_deliveries():
    item_price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    partition = Mock(get_total=Mock(return_value=item_price),
                     get_price_per_item=Mock(return_value=item_price))

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]), currency='USD')
    checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
    deliveries = list(checkout.deliveries)
    assert deliveries[0][1] == TaxedMoney(net=Money(0, 'USD'),
                                          gross=Money(0, 'USD'))
    assert deliveries[0][2] == partition.get_total()
    assert deliveries[0][0][0][0] == partition
Ejemplo n.º 21
0
def test_checkout_deliveries():
    partition = Mock(
        get_total=Mock(return_value=Price(10, currency=settings.DEFAULT_CURRENCY)),
        get_price_per_item=Mock(return_value=Price(10, currency=settings.DEFAULT_CURRENCY)))

    def f():
        yield partition

    partition.__iter__ = Mock(return_value=f())
    cart = Mock(partition=Mock(return_value=[partition]),
                currency=settings.DEFAULT_CURRENCY)
    checkout = Checkout(
        cart, AnonymousUser(), 'tracking_code')
    deliveries = list(checkout.deliveries)
    assert deliveries[0][1] == Price(0, currency=settings.DEFAULT_CURRENCY)
    assert deliveries[0][2] == partition.get_total()
    assert deliveries[0][0][0][0] == partition
Ejemplo n.º 22
0
def checkout(request_cart, customer_user, billing_address, shipping_method):
    res = Checkout(request_cart, customer_user, 'tracking_code')
    customer_user.default_shipping_address = billing_address
    customer_user.default_billing_address = billing_address
    customer_user.save()
    return res
Ejemplo n.º 23
0
def checkout_with_items(request_cart_with_item, customer_user):
    checkout = Checkout(request_cart_with_item, customer_user, 'tracking_code')
    checkout.shipping_address = customer_user.default_shipping_address
    return checkout
Ejemplo n.º 24
0
def test_checkout_is_shipping_required():
    cart = Mock(is_shipping_required=Mock(return_value=True))
    checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
    assert checkout.is_shipping_required is True
Ejemplo n.º 25
0
def test_checkout_clear_storage():
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['new'] = 1
    checkout.clear_storage()
    assert checkout.storage is None
    assert checkout.modified is True
Ejemplo n.º 26
0
def checkout():
    return Checkout(Mock(), AnonymousUser(), None, None, 'tracking_code')
Ejemplo n.º 27
0
def test_checkout_discount(request_cart, sale, product_in_stock):
    variant = product_in_stock.variants.get()
    request_cart.add(variant, 1)
    checkout = Checkout(request_cart, AnonymousUser(), 'tracking_code')
    assert checkout.get_total() == Price(currency="USD", net=5)
Ejemplo n.º 28
0
def test_checkout_discount(request_cart, sale, product_in_stock):
    variant = product_in_stock.variants.get()
    request_cart.add(variant, 1)
    checkout = Checkout(request_cart, AnonymousUser(), 'tracking_code')
    assert checkout.get_total() == Price(currency="USD", net=5)
Ejemplo n.º 29
0
def test_checkout_billing_address(user, address):
    checkout = Checkout(Mock(), user, 'tracking_code')
    assert checkout.billing_address == address
Ejemplo n.º 30
0
def test_checkout_shipping_address_with_storage(address_objects, shipping, monkeypatch):
    monkeypatch.setattr('saleor.checkout.core.Address.objects', address_objects)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['shipping_address'] = {'id': 1}
    assert checkout.shipping_address == shipping
Ejemplo n.º 31
0
def test_checkout_version():
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    storage = checkout.for_storage()
    assert storage['version'] == Checkout.VERSION
Ejemplo n.º 32
0
def test_checkout_discount(request_cart, sale, product_in_stock):
    variant = product_in_stock.variants.get()
    request_cart.add(variant, 1)
    checkout = Checkout(request_cart, AnonymousUser(), 'tracking_code')
    assert checkout.get_total() == TaxedMoney(
        net=Money(5, 'USD'), gross=Money(5, 'USD'))
Ejemplo n.º 33
0
def test_checkout_clear_storage():
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['new'] = 1
    checkout.clear_storage()
    assert checkout.storage is None
    assert checkout.modified is True
Ejemplo n.º 34
0
def test_checkout_version():
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    storage = checkout.for_storage()
    assert storage['version'] == Checkout.VERSION
Ejemplo n.º 35
0
def test_note_form(note_value):
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    form = NoteForm({'note': note_value}, checkout=checkout)
    form.is_valid()
    form.set_checkout_note()
    assert checkout.note == note_value.strip()
Ejemplo n.º 36
0
def test_checkout_discount(request_cart, sale, product_in_stock):
    variant = product_in_stock.variants.get()
    request_cart.add(variant, 1)
    checkout = Checkout(request_cart, AnonymousUser(), 'tracking_code')
    assert checkout.get_total() == TaxedMoney(net=Money(5, currency="USD"),
                                              gross=Money(5, currency="USD"))
Ejemplo n.º 37
0
def test_checkout_version_with_from_storage(storage_data, expected_storage):
    checkout = Checkout.from_storage(
        storage_data, Mock(), AnonymousUser(), 'tracking_code')
    storage = checkout.for_storage()
    assert storage == expected_storage
Ejemplo n.º 38
0
def test_checkout_version_with_from_storage(storage_data, expected_storage):
    checkout = Checkout.from_storage(
        storage_data, Mock(), AnonymousUser(), 'tracking_code')
    storage = checkout.for_storage()
    assert storage == expected_storage
Ejemplo n.º 39
0
def test_checkout_shipping_does_not_exists(monkeypatch):
    queryset = Mock(get=Mock(side_effect=ShippingMethodCountry.DoesNotExist))
    monkeypatch.setattr('saleor.checkout.core.ShippingMethodCountry.objects', queryset)
    checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
    checkout.storage['shipping_method_country_id'] = 1
    assert checkout.shipping_method is None
Ejemplo n.º 40
0
def anonymous_checkout():
    return Checkout((), AnonymousUser(), 'tracking_code')
Ejemplo n.º 41
0
def test_checkout_shipping_address_with_anonymous_user(user, shipping):
    checkout = Checkout(Mock(), user, 'tracking_code')
    assert checkout._shipping_address is None
    assert checkout.shipping_address == shipping
    assert checkout._shipping_address == shipping