Exemple #1
0
def test_cart_contents_with_adjustment(client, cart):
    # set up cart contents
    i = factories.MyLineItemFactory(cart=cart)

    # add some more line items not attached to the cart
    factories.MyLineItemFactory()
    factories.MyLineItemFactory()

    # add an adjustment
    a = factories.CartDiscountFactory(cart=cart)

    # add more adjustments not attached to the cart
    factories.CartDiscountFactory()
    factories.CartDiscountFactory()

    resp = client.get('/_cart/')
    data = loads(resp.content.decode('utf-8'))
    discount = (-cart.get_subtotal() * (Decimal(a.percentage) / 100)).quantize(
        Decimal('.01'), rounding=ROUND_DOWN)
    assert data['adjustments'] == [{
        'type': 'CartDiscount',
        'url': '/_cart/adjustment/{}/'.format(i.id),
        'data': {
            'percentage': a.percentage,
        },
        'total': str(discount),
    }]
    assert data['grand_total'] == str((i.product.unit_price * i.quantity) +
                                      discount)
Exemple #2
0
def test_cart_contents_with_adjustment(client, cart):
    # set up cart contents
    i = factories.MyLineItemFactory(cart=cart)

    # add some more line items not attached to the cart
    factories.MyLineItemFactory()
    factories.MyLineItemFactory()

    # add an adjustment
    a = factories.CartDiscountFactory(cart=cart)

    # add more adjustments not attached to the cart
    factories.CartDiscountFactory()
    factories.CartDiscountFactory()

    resp = client.get("/_cart/")
    data = loads(resp.content.decode("utf-8"))
    discount = (-cart.get_subtotal() * (Decimal(a.percentage) / 100)).quantize(
        Decimal(".01"), rounding=ROUND_DOWN
    )
    assert data["adjustments"] == [
        {
            "type": "CartDiscount",
            "url": "/_cart/adjustment/{}/".format(i.id),
            "data": {"percentage": a.percentage},
            "total": str(discount),
        }
    ]
    assert data["grand_total"] == str((i.product.unit_price * i.quantity) + discount)
Exemple #3
0
def test_delete_unowned_adjustment(client, other_cart):
    a = sfactories.CartDiscountFactory(cart=other_cart)

    url = '/_cart/adjustment/{}/'.format(a.id)
    resp = client.delete(url)
    assert resp.status_code == 404
    a.refresh_from_db()
Exemple #4
0
def test_delete_adjustment(client, cart):
    a = sfactories.CartDiscountFactory(cart=cart)

    url = '/_cart/adjustment/{}/'.format(a.id)
    resp = client.delete(url)
    assert resp.status_code == 204
    with pytest.raises(smodels.CartDiscount.DoesNotExist):
        a.refresh_from_db()
Exemple #5
0
def fill_cart(cart):
    factories.MyLineItemFactory(cart=cart)
    factories.MyLineItemFactory(cart=cart)
    factories.CartDiscountFactory(cart=cart, percentage=10)
    cart.delivery_address = factories.AustralianDeliveryAddressFactory()
    cart.payment_method = smodels.PipeCard.objects.create(card_id="Visa4242")
    if not cart.user:
        cart.email = Faker().safe_email()
    cart.save()
Exemple #6
0
def test_view_adjustment(client, cart):
    a = sfactories.CartDiscountFactory(cart=cart)

    url = '/_cart/adjustment/{}/'.format(a.id)
    resp = client.get(url)
    data = loads(resp.content.decode('utf-8'))
    assert data == {
        'type': 'CartDiscount',
        'data': {
            'percentage': a.percentage,
        },
        'total': '0.00',
        'url': '/_cart/adjustment/{}/'.format(a.id),
    }
Exemple #7
0
def test_view_adjustment(client, cart):
    a = sfactories.CartDiscountFactory(cart=cart)

    url = "/_cart/adjustment/{}/".format(a.id)
    resp = client.get(url)
    data = loads(resp.content.decode("utf-8"))
    assert data == {
        "type": "CartDiscount",
        "data": {
            "percentage": a.percentage
        },
        "total": "0.00",
        "url": "/_cart/adjustment/{}/".format(a.id),
    }
Exemple #8
0
def test_view_unowned_adjustment(other_cart, client):
    a = sfactories.CartDiscountFactory(cart=other_cart)

    url = '/_cart/adjustment/{}/'.format(a.id)
    resp = client.get(url)
    assert resp.status_code == 404