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.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/pyblackbird_cc/payments/tests/test_models.py b/pyblackbird_cc/payments/tests/test_models.py
new file mode 100644
index 0000000..342ff14
--- /dev/null
+++ b/pyblackbird_cc/payments/tests/test_models.py
@@ -0,0 +1,41 @@
+import pytest
+from allauth.account.signals import user_signed_up
+from django.contrib.auth import get_user_model
+from django.test import RequestFactory
+
+from pyblackbird_cc.payments.models import SubscriptionPlan, Subscription
+
+User = get_user_model()
+
+@pytest.fixture
+def user_data():
+ return {
+ 'email': 'testuser@example.com',
+ 'password': 'testpassword123'
+ }
+
+@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)
+ # 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 = Subscription.objects.filter(user=user).first()
+ 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 \ No newline at end of file