diff options
Diffstat (limited to 'pyblackbird_cc/payments/tests/test_models.py')
-rw-r--r-- | pyblackbird_cc/payments/tests/test_models.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pyblackbird_cc/payments/tests/test_models.py b/pyblackbird_cc/payments/tests/test_models.py index fd26fea..4dab6e3 100644 --- a/pyblackbird_cc/payments/tests/test_models.py +++ b/pyblackbird_cc/payments/tests/test_models.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ValidationError import pytest from allauth.account.signals import user_signed_up from django.contrib.auth import get_user_model @@ -86,3 +87,28 @@ def test_cart_item_is_created_when_resource_is_added_to_cart(user_data, resource users_cart = ShoppingCart.objects.get(user=user) users_cart.add_resource(resource) assert users_cart.items.count() == 1 # type: ignore + + +@pytest.mark.django_db +def test_cannot_add_the_same_resource_to_cart_twice(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 + with pytest.raises(ValidationError): + users_cart.add_resource(resource) + + +@pytest.mark.django_db +def test_can_add_multiple_different_items_to_cart(user_data, resources): + 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(resources[0]) + users_cart.add_resource(resources[1]) + users_cart.add_resource(resources[2]) + users_cart.add_resource(resources[3]) + assert users_cart.items.count() == 4 # type: ignore |