diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-09 17:21:11 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-09 17:21:11 +0100 |
commit | 677c935fdc3b083a9940a1b2f280cb1ccdbc03bd (patch) | |
tree | d9ecde9f2b9dc7db923438120b9031dc2b9b6301 | |
parent | 082d6a7ee8bece150c04840474b18aa791f6300d (diff) |
wip: working on tests for adding resource to a cart
-rw-r--r-- | pyblackbird_cc/payments/tests/test_views.py | 5 | ||||
-rw-r--r-- | pyblackbird_cc/payments/urls.py | 4 | ||||
-rw-r--r-- | pyblackbird_cc/payments/views.py | 12 | ||||
-rw-r--r-- | pyblackbird_cc/templates/resources/resource_detail.html | 8 |
4 files changed, 16 insertions, 13 deletions
diff --git a/pyblackbird_cc/payments/tests/test_views.py b/pyblackbird_cc/payments/tests/test_views.py index e80a2d9..0b469b5 100644 --- a/pyblackbird_cc/payments/tests/test_views.py +++ b/pyblackbird_cc/payments/tests/test_views.py @@ -9,3 +9,8 @@ def test_cart_view(client, user): response = client.get(url) assert response.status_code == 200 assert "My basket" in str(response.content) + + +@pytest.mark.django_db +def test_add_resource_to_cart(resource, user): + url = reverse("payments:add_to_cart", args=[resource.pk]) diff --git a/pyblackbird_cc/payments/urls.py b/pyblackbird_cc/payments/urls.py index 7f10a9b..d294aab 100644 --- a/pyblackbird_cc/payments/urls.py +++ b/pyblackbird_cc/payments/urls.py @@ -1,8 +1,7 @@ from django.urls import path from . import views -from .views import CancelView -from .views import SuccessView +from .views import CancelView, SuccessView app_name = "payments" @@ -16,6 +15,7 @@ urlpatterns = [ views.CreateCheckoutSessionView.as_view(), name="create-checkout-session", ), + path("add-to-card/<int:pk>", views.add_to_cart, name="add_to_cart"), path("landing/", views.ProductLandingPageView.as_view(), name="landing"), # path("webhook/", views.webhook, name="webhook"), ] diff --git a/pyblackbird_cc/payments/views.py b/pyblackbird_cc/payments/views.py index 40c2380..6863869 100644 --- a/pyblackbird_cc/payments/views.py +++ b/pyblackbird_cc/payments/views.py @@ -1,18 +1,13 @@ import stripe from django.conf import settings from django.contrib.auth.decorators import login_required -from django.shortcuts import get_object_or_404 -from django.shortcuts import redirect -from django.shortcuts import render +from django.shortcuts import get_object_or_404, redirect, render from django.views import View from django.views.generic import TemplateView - from pyblackbird_cc.resources.models import Resource +from pyblackbird_cc.users.models import User -from .models import CartItem -from .models import Price -from .models import Product -from .models import ShoppingCart +from .models import CartItem, Price, Product, ShoppingCart stripe.api_key = settings.STRIPE_SECRET_KEY @@ -93,3 +88,4 @@ def checkout(request): return render(request, "cart/checkout_success.html") return render(request, "cart/checkout.html", {"cart": cart, "total": total}) + pass diff --git a/pyblackbird_cc/templates/resources/resource_detail.html b/pyblackbird_cc/templates/resources/resource_detail.html index f287575..48d7efb 100644 --- a/pyblackbird_cc/templates/resources/resource_detail.html +++ b/pyblackbird_cc/templates/resources/resource_detail.html @@ -48,9 +48,11 @@ </div> <div class="row align-items-end"> <div class="my-4 d-flex justify-content-center"> - <button class="btn btn-primary w-100"> - Add to cart - </button> + <form action="{% url 'resource:add_to_cart' %}" method="get" accept-charset="utf-8"> + <button class="btn btn-primary w-100"> + Add to cart + </button> + </form> </div> </div> </div> |