diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-15 21:01:31 +0100 |
commit | eeaddb27560d723ca7d61359744ceb2709fccd2d (patch) | |
tree | 04ddbc49ae7b73d5f5a9e1716d7227aecd3b9f85 /pyblackbird_cc/payments/tests | |
parent | 7a3044c859043837e6c7c95bb4894d04e9b2cbc2 (diff) |
Renamed from pyblackbird_cc to alphabetlearning - everywhere
Diffstat (limited to 'pyblackbird_cc/payments/tests')
-rw-r--r-- | pyblackbird_cc/payments/tests/__init__.py | 0 | ||||
-rw-r--r-- | pyblackbird_cc/payments/tests/conftest.py | 6 | ||||
-rw-r--r-- | pyblackbird_cc/payments/tests/test_models.py | 116 | ||||
-rw-r--r-- | pyblackbird_cc/payments/tests/test_views.py | 19 |
4 files changed, 0 insertions, 141 deletions
diff --git a/pyblackbird_cc/payments/tests/__init__.py b/pyblackbird_cc/payments/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/pyblackbird_cc/payments/tests/__init__.py +++ /dev/null diff --git a/pyblackbird_cc/payments/tests/conftest.py b/pyblackbird_cc/payments/tests/conftest.py deleted file mode 100644 index 7919170..0000000 --- a/pyblackbird_cc/payments/tests/conftest.py +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 5f67e01..0000000 --- a/pyblackbird_cc/payments/tests/test_models.py +++ /dev/null @@ -1,116 +0,0 @@ -import pytest -from allauth.account.signals import user_signed_up -from django.contrib.auth import get_user_model -from django.core.exceptions import ValidationError -from django.db import IntegrityError -from django.test import RequestFactory - -from pyblackbird_cc.payments.models import ShoppingCart -from pyblackbird_cc.payments.models import Subscription -from pyblackbird_cc.payments.models import SubscriptionPlan - -User = get_user_model() - - -@pytest.fixture -def user_data(): - return {"email": "testuser@example.com", "password": "testpassword123"} - - -@pytest.mark.django_db -def test_subscription_user_unique(): - # Ensure the free plan exists - free_plan, _ = SubscriptionPlan.objects.get_or_create( - name="Free Plan", - defaults={ - "price": 0, - "description": "Free plan description", - "allowed_downloads": 10, - }, - ) - - # Create a new user - user_data = {"email": "testuser@example.com", "password": "testpassword123"} - user = User.objects.create_user(**user_data) # type: ignore - - # Create a subscription for the user - Subscription.objects.create(user=user, plan=free_plan) - - # Try to create another subscription for the same user - with pytest.raises(IntegrityError): - Subscription.objects.create(user=user, plan=free_plan) - - -@pytest.mark.django_db -def test_user_signup_assigns_free_subscription(user_data): - # Ensure the free plan exists - free_plan, _ = SubscriptionPlan.objects.get_or_create( - name="Free Plan", - defaults={ - "price": 0, - "description": "Free plan description", - "allowed_downloads": 10, - }, - ) # Create a new user - user = User.objects.create_user(**user_data) # type: ignore - # Manually trigger the user_signed_up signal - request = RequestFactory().get("/") - user_signed_up.send(sender=user.__class__, request=request, user=user) - - # Check if a SubscriptionPlan was created for the user - subscription = user.subscription - assert subscription is not None - - # Check if the assigned plan is the free plan - assert subscription.plan == free_plan - - # 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 - 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`. - - -@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 - - -@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 diff --git a/pyblackbird_cc/payments/tests/test_views.py b/pyblackbird_cc/payments/tests/test_views.py deleted file mode 100644 index 7d0f8b5..0000000 --- a/pyblackbird_cc/payments/tests/test_views.py +++ /dev/null @@ -1,19 +0,0 @@ -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) - - -@pytest.mark.django_db -def test_add_resource_to_cart(client, resource, user): - url = reverse("payments:add_to_cart", kwargs={"resource_id": resource.id}) - client.force_login(user) - response = client.get(url) - assert response.status_code == 200 |