Exemplo n.º 1
0
def test_loading_inactive_cart(mocker, inactive_cart):
    create_cart = mocker.patch("carts.services.CartToolkit._create_new_cart")
    test_cart = CartToolkit.load_cart(user=inactive_cart.user,
                                      cart_id=inactive_cart.id)

    create_cart.assert_called_once()
    assert test_cart != inactive_cart
Exemplo n.º 2
0
def get_cart_courses_count_api(request, *args, **kwargs):
    data = request.GET
    cart_id = int(data.get("cart_id")) if data.get("cart_id") is not None else None
    user = request.user
    cart = CartToolkit.load_cart(user=user, cart_id=cart_id)
    return Response({
        "cart_courses_count": cart.get_courses_count(), 
        "cart_id": cart.id,
    }, status=200)
Exemplo n.º 3
0
 def get_cart_lists_by_user_and_ids(cls, user: User, ids: dict, *args,
                                    **kwargs) -> dict:
     cart = CartToolkit.load_cart(user=user, cart_id=ids["cart_id"])
     saved_for_later = SavedForLaterToolkit.load_saved_for_later(
         user=user, saved_for_later_id=ids["saved_for_later_id"])
     if user.is_authenticated:
         wishlist = WishlistToolkit.load_wishlist(user=user)
     else:
         wishlist = None
     return {
         "cart": cart,
         "saved_for_later": saved_for_later,
         "wishlist": wishlist,
     }
Exemplo n.º 4
0
def check_on_course_already_in_cart_api(request, *args, **kwargs):
    try:
        data = request.GET
        cart_id = int(data.get("cart_id")) if data.get("cart_id") is not None else None
        course_slug = data["course_slug"]
    except KeyError:
        logger.error("Request object doesn't have a slug field")
        return Response({"error": CartErrorMessages.REQUEST_FIELDS_ERROR.value}, status=400)
    
    user = request.user
    cart = CartToolkit.load_cart(user=user, cart_id=cart_id)
    try:
        course_already_in_cart = CartToolkit.check_on_course_in_cart(cart=cart, course_slug=course_slug)
    except Course.DoesNotExist:
        return Response({"error": CourseErrorMessages.COURSE_DOES_NOT_EXIST_ERROR.value}, status=400)
    return Response({"course_already_in_cart": course_already_in_cart}, status=200)
Exemplo n.º 5
0
def test_cart_loading_with_user_and_id_for_same_cart(cart):
    test_cart = CartToolkit.load_cart(user=cart.user, cart_id=cart.id)

    assert test_cart == cart
Exemplo n.º 6
0
def test_loading_active_and_inactive_cart_with_same_user_with_proper_id(
        cart, inactive_cart):
    test_cart = CartToolkit.load_cart(user=inactive_cart.user, cart_id=cart.id)

    assert test_cart == cart
Exemplo n.º 7
0
def test_cart_loading_updating_totals(mocker, cart):
    cart_update_totals = mocker.patch("carts.models.Cart.update_totals")
    test_cart = CartToolkit.load_cart(user=cart.user)

    cart_update_totals.assert_called_once()
Exemplo n.º 8
0
def test_cart_loading_without_arguments(mocker):
    create_cart = mocker.patch("carts.services.CartToolkit._create_new_cart")
    test_cart = CartToolkit.load_cart()

    create_cart.assert_called_once()
Exemplo n.º 9
0
def test_cart_loading_for_user_without_existing_cart(mocker, user):
    create_cart = mocker.patch("carts.services.CartToolkit._create_new_cart")
    test_cart = CartToolkit.load_cart(user=user)

    create_cart.assert_called_once()
Exemplo n.º 10
0
def test_cart_loading_with_user_and_different_cart_id(cart, another_cart):
    test_cart = CartToolkit.load_cart(user=cart.user, cart_id=another_cart.id)

    assert test_cart == cart
Exemplo n.º 11
0
def test_cart_loading_with_id(cart):
    test_cart = CartToolkit.load_cart(cart_id=cart.id)

    assert test_cart == cart
Exemplo n.º 12
0
def test_cart_loading_with_user(cart):
    test_cart = CartToolkit.load_cart(user=cart.user)

    assert test_cart == cart
Exemplo n.º 13
0
def get_cart_info_api(request, *args, **kwargs):
    user = request.user
    ids = CartListsToolkit.get_cart_lists_ids_from_request(request)
    cart = CartToolkit.load_cart(user=user, cart_id=ids["cart_id"])
    serializer = CartOnlyInfoSerializer(instance=cart)
    return Response(serializer.data, status=200)