def test_deleting_duplicates_excluding_cart(cart_lists_with_same_course): cart = cart_lists_with_same_course["cart"] course = cart.courses.first() CartListsToolkit.delete_duplicates_excluding_instance( course_slug=course.slug, instance=cart, **cart_lists_with_same_course) assert cart.courses.count() == 1 assert cart_lists_with_same_course["wishlist"].courses.count() == 0 assert cart_lists_with_same_course["saved_for_later"].courses.count() == 0 assert cart.courses.first() == course
def add_course_to_wishlist_api(request, *args, **kwargs): try: course_slug = request.POST["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 ids = CartListsToolkit.get_cart_lists_ids_from_request(request) cart_lists = CartListsSelector.get_cart_lists_by_user_and_ids(user=request.user, ids=ids) try: wishlist = WishlistToolkit.add_course_to_wishlist(wishlist=cart_lists["wishlist"], course_slug=course_slug) except Course.DoesNotExist: return Response({"error": CourseErrorMessages.COURSE_DOES_NOT_EXIST_ERROR.value}, status=400) CartListsToolkit.delete_duplicates_excluding_instance(course_slug=course_slug, instance=wishlist, **cart_lists) serializer = CartOnlyInfoSerializer(instance=cart_lists["cart"]) return Response(serializer.data, status=200)