diff options
author | Matthew Lemon <y@yulqen.org> | 2024-09-14 15:54:21 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-09-14 15:54:21 +0100 |
commit | f312ec6d4a577e71d76cf85632a198b0c1913703 (patch) | |
tree | eccd268d4432c32b9fee6665e0bbba87967b6fef /pyblackbird_cc/payments/tests/test_models.py | |
parent | d2abe12612108b94135dcb0701614dc216fb92d2 (diff) |
wip: adding shopping card functionality
Diffstat (limited to 'pyblackbird_cc/payments/tests/test_models.py')
-rw-r--r-- | pyblackbird_cc/payments/tests/test_models.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/pyblackbird_cc/payments/tests/test_models.py b/pyblackbird_cc/payments/tests/test_models.py index 65e7484..fd26fea 100644 --- a/pyblackbird_cc/payments/tests/test_models.py +++ b/pyblackbird_cc/payments/tests/test_models.py @@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model from django.db import IntegrityError from django.test import RequestFactory -from pyblackbird_cc.payments.models import Subscription +from pyblackbird_cc.payments.models import ShoppingCart, Subscription from pyblackbird_cc.payments.models import SubscriptionPlan User = get_user_model() @@ -64,3 +64,25 @@ def test_user_signup_assigns_free_subscription(user_data): # Additional assertions can be added here to check other properties # of the SubscriptionPlan or Subscription as needed + + +@pytest.mark.django_db +def test_shopping_cart_is_created_when_user_is_created(user_data): + user = User.objects.create_user(**user_data) # type: ignore + request = RequestFactory().get("/") + user_signed_up.send(sender=user.__class__, request=request, user=user) + shopping_cart = ShoppingCart.objects.get(user=user) + assert shopping_cart is not None + + +# 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`. + + +@pytest.mark.django_db +def test_cart_item_is_created_when_resource_is_added_to_cart(user_data, resource): + user = User.objects.create_user(**user_data) # type: ignore + request = RequestFactory().get("/") + user_signed_up.send(sender=user.__class__, request=request, user=user) + users_cart = ShoppingCart.objects.get(user=user) + users_cart.add_resource(resource) + assert users_cart.items.count() == 1 # type: ignore |