Ejemplo n.º 1
0
def test_list_cart(api_rf, filled_cart):
    request = api_rf.get('/shop/api/cart')
    request.customer = filled_cart.customer
    response = CartViewSet.as_view({'get': 'list'})(request)
    assert response.status_code == 200
    assert response.data['num_items'] == 1
    assert response.data['total_quantity'] == 2
    assert response.data['subtotal'] == str(filled_cart.subtotal)
    assert response.data['total'] == str(filled_cart.total)
Ejemplo n.º 2
0
def test_include_tax_modifier(api_rf, filled_cart):
    request = api_rf.get('/shop/api/cart')
    request.customer = filled_cart.customer

    response = CartViewSet.as_view({'get': 'list'})(request)
    assert response.status_code == 200
    assert response.data['subtotal'] == str(filled_cart.subtotal)
    tax_rate = 1 + app_settings.SHOP_VALUE_ADDED_TAX / 100
    assert response.data['total'] == str(filled_cart.subtotal * tax_rate)
Ejemplo n.º 3
0
def test_remove_item(api_rf, filled_cart):
    product = filled_cart.items.all()[0].product
    request = api_rf.delete(reverse('shop:cart-list'))
    request.customer = filled_cart.customer
    response = CartViewSet.as_view({'delete': 'destroy'})(request, pk=product.id)
    assert response.status_code == 200
    filled_cart.refresh_from_db()
    assert filled_cart.num_items == 0
    assert filled_cart.items.count() == 0
Ejemplo n.º 4
0
def test_change_quantity(api_rf, filled_cart):
    product = filled_cart.items.all()[0].product
    data = {'quantity': 3, 'product': product.id}
    request = api_rf.put('/shop/api/cart', data)
    request.customer = filled_cart.customer
    response = CartViewSet.as_view({'put': 'update'})(request, pk=product.id)
    assert response.status_code == 200
    filled_cart.refresh_from_db()
    assert filled_cart.num_items == 1
    assert filled_cart.items.all()[0].quantity == 3
Ejemplo n.º 5
0
def test_add_watch_item(api_rf, watch_list):
    product = watch_list.items.all()[0].product
    data = {'quantity': 1, 'product': product.id}
    request = api_rf.put('/shop/api/cart', data)
    request.customer = watch_list.customer
    response = CartViewSet.as_view({'put': 'update'})(request, pk=product.id)
    assert response.status_code == 200
    watch_list.refresh_from_db()
    assert watch_list.num_items == 1
    assert watch_list.items.all()[0].quantity == 1
Ejemplo n.º 6
0
def test_too_greedy(session, api_rf, filled_cart):
    product = filled_cart.items.all()[0].product
    data = {'quantity': 10, 'product': product.id}
    request = api_rf.put('/shop/api/cart', data)
    request.customer = filled_cart.customer
    request.session = session
    request._messages = default_storage(request)
    response = CartViewSet.as_view({'put': 'update'})(request, pk=product.id)
    assert response.status_code == 200
    filled_cart.refresh_from_db()
    assert filled_cart.num_items == 1
    assert filled_cart.items.all()[0].quantity == 5  # not 10, as requested
Ejemplo n.º 7
0
def test_unowned_cart(customer_factory, api_rf, filled_cart):
    request = api_rf.get('/shop/api/cart')
    request.customer = customer_factory()
    response = CartViewSet.as_view({'get': 'list'})(request)
    assert response.data['num_items'] == 0