aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/payments
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-16 17:12:15 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-16 17:12:15 +0100
commit86bb29b4d378314bd906248e08198c1952d2f0a4 (patch)
tree005bb24dfa6a0e5d911d6cfdda9d469828a387a1 /pyblackbird_cc/payments
parent0d3ae1492e1a88db69437cd277b7cf11c4e6274a (diff)
Upgrade to bootstrap 5.3
Diffstat (limited to 'pyblackbird_cc/payments')
-rw-r--r--pyblackbird_cc/payments/models.py2
-rw-r--r--pyblackbird_cc/payments/tests/conftest.py6
-rw-r--r--pyblackbird_cc/payments/tests/test_models.py1
-rw-r--r--pyblackbird_cc/payments/tests/test_views.py11
-rw-r--r--pyblackbird_cc/payments/urls.py11
-rw-r--r--pyblackbird_cc/payments/views.py5
6 files changed, 31 insertions, 5 deletions
diff --git a/pyblackbird_cc/payments/models.py b/pyblackbird_cc/payments/models.py
index b947a22..a7cb8a7 100644
--- a/pyblackbird_cc/payments/models.py
+++ b/pyblackbird_cc/payments/models.py
@@ -25,7 +25,7 @@ class ShoppingCart(models.Model):
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
- return f"Shopping Cart for {self.user.username}"
+ return f"Shopping cart for {self.user.email}"
def add_resource(self, resource: Resource):
if CartItem.objects.filter(cart=self, resource=resource).exists():
diff --git a/pyblackbird_cc/payments/tests/conftest.py b/pyblackbird_cc/payments/tests/conftest.py
new file mode 100644
index 0000000..7919170
--- /dev/null
+++ b/pyblackbird_cc/payments/tests/conftest.py
@@ -0,0 +1,6 @@
+import pytest
+
+
+@pytest.fixture
+def user_data():
+ return {"email": "testuser@example.com", "password": "testpassword123"}
diff --git a/pyblackbird_cc/payments/tests/test_models.py b/pyblackbird_cc/payments/tests/test_models.py
index 39e874f..5f67e01 100644
--- a/pyblackbird_cc/payments/tests/test_models.py
+++ b/pyblackbird_cc/payments/tests/test_models.py
@@ -75,6 +75,7 @@ def test_shopping_cart_is_created_when_user_is_created(user_data):
user_signed_up.send(sender=user.__class__, request=request, user=user)
shopping_cart = ShoppingCart.objects.get(user=user)
assert shopping_cart is not None
+ assert str(shopping_cart) == "Shopping cart for {}".format(user.email)
# When the user adds a `Resource` to their cart, create a new `CartItem` instance and associate it with the user's `ShoppingCart` and the selected `Resource`.
diff --git a/pyblackbird_cc/payments/tests/test_views.py b/pyblackbird_cc/payments/tests/test_views.py
new file mode 100644
index 0000000..e80a2d9
--- /dev/null
+++ b/pyblackbird_cc/payments/tests/test_views.py
@@ -0,0 +1,11 @@
+import pytest
+from django.urls import reverse
+
+
+@pytest.mark.django_db
+def test_cart_view(client, user):
+ url = reverse("payments:cart_detail")
+ client.force_login(user)
+ response = client.get(url)
+ assert response.status_code == 200
+ assert "My basket" in str(response.content)
diff --git a/pyblackbird_cc/payments/urls.py b/pyblackbird_cc/payments/urls.py
index 4fdc758..7f10a9b 100644
--- a/pyblackbird_cc/payments/urls.py
+++ b/pyblackbird_cc/payments/urls.py
@@ -7,12 +7,15 @@ from .views import SuccessView
app_name = "payments"
urlpatterns = [
- # path("checkout/", views.checkout, name="checkout"),
- # path("cart/", views.cart_detail, name="cart_detail"),
+ path("checkout/", views.checkout, name="checkout"),
+ path("cart/", views.cart_detail, name="cart_detail"),
path("success/", SuccessView.as_view(), name="success"),
path("cancel/", CancelView.as_view(), name="cancel"),
- path("create-checkout-session/<int:pk>/", views.CreateCheckoutSessionView.as_view(),
- name="create-checkout-session"),
+ path(
+ "create-checkout-session/<int:pk>/",
+ views.CreateCheckoutSessionView.as_view(),
+ name="create-checkout-session",
+ ),
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 d02a2ab..36f1d84 100644
--- a/pyblackbird_cc/payments/views.py
+++ b/pyblackbird_cc/payments/views.py
@@ -17,6 +17,11 @@ from .models import ShoppingCart
stripe.api_key = settings.STRIPE_SECRET_KEY
+def cart(request):
+ cart = ShoppingCart.objects.get(user=request.user)
+ return render(request, "cart_detail.html", {"cart": cart})
+
+
class CreateCheckoutSessionView(View):
def post(self, request, *args, **kwargs):
price = Price.objects.get(id=self.kwargs["pk"])