diff options
author | Matthew Lemon <y@yulqen.org> | 2024-09-14 20:20:48 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-09-14 20:20:48 +0100 |
commit | 8a13e1543334f86803cd9909ba3fa5d4619074c0 (patch) | |
tree | 05498d5ddc76840d8168c98b979e21d854d25efa /pyblackbird_cc/payments/tests | |
parent | f312ec6d4a577e71d76cf85632a198b0c1913703 (diff) |
wip: testing adding resources to shopping cart
Diffstat (limited to 'pyblackbird_cc/payments/tests')
-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 |