def test_cart_add_all(rf, regular_user): cart = _save_cart_with_products(rf, regular_user) request = apply_request_middleware(rf.post("/"), customer=get_person_contact(regular_user), user=regular_user) assert not request.basket.product_count, "cart is empty" response = CartAddAllProductsView.as_view()(request, pk=cart.pk) assert response.status_code == 200 assert request.basket.product_count, "products added to cart"
def test_cart_add_all_with_errors(rf, regular_user): cart = _save_cart_with_products(rf, regular_user) for product in cart.products.all(): product.deleted = True product.save() request = apply_request_middleware(rf.post("/"), customer=get_person_contact(regular_user), user=regular_user) assert not request.basket.product_count, "cart is empty" response = CartAddAllProductsView.as_view()(request, pk=cart.pk) data = json.loads(response.content.decode("utf8")) assert response.status_code == 200 assert not request.basket.product_count, "no products added to cart" assert len(data["errors"]) > 0