aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/payments/tests/test_models.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyblackbird_cc/payments/tests/test_models.py')
-rw-r--r--pyblackbird_cc/payments/tests/test_models.py24
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