Add a 5 min trial period to subscriptions for test purposes iff
ADD_TRIAL_PERIOD_TO_SUBSCRIPTION is set to true
This commit is contained in:
parent
9b798b4376
commit
9b3e292598
5 changed files with 17 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
# from django.test import TestCase
|
# from django.test import TestCase
|
||||||
|
import datetime
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from unittest import skipIf
|
||||||
|
|
||||||
import stripe
|
import stripe
|
||||||
from celery.result import AsyncResult
|
from celery.result import AsyncResult
|
||||||
|
@ -8,7 +9,6 @@ from django.conf import settings
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from model_mommy import mommy
|
from model_mommy import mommy
|
||||||
from unittest import skipIf
|
|
||||||
|
|
||||||
from datacenterlight.models import VMTemplate
|
from datacenterlight.models import VMTemplate
|
||||||
from datacenterlight.tasks import create_vm_task
|
from datacenterlight.tasks import create_vm_task
|
||||||
|
@ -119,7 +119,8 @@ class CeleryTaskTestCase(TestCase):
|
||||||
subscription_result = self.stripe_utils.subscribe_customer_to_plan(
|
subscription_result = self.stripe_utils.subscribe_customer_to_plan(
|
||||||
stripe_customer.stripe_id,
|
stripe_customer.stripe_id,
|
||||||
[{"plan": stripe_plan.get(
|
[{"plan": stripe_plan.get(
|
||||||
'response_object').stripe_plan_id}])
|
'response_object').stripe_plan_id}],
|
||||||
|
int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None)
|
||||||
stripe_subscription_obj = subscription_result.get('response_object')
|
stripe_subscription_obj = subscription_result.get('response_object')
|
||||||
# Check if the subscription was approved and is active
|
# Check if the subscription was approved and is active
|
||||||
if stripe_subscription_obj is None \
|
if stripe_subscription_obj is None \
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -785,7 +786,9 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
subscription_result = stripe_utils.subscribe_customer_to_plan(
|
subscription_result = stripe_utils.subscribe_customer_to_plan(
|
||||||
stripe_api_cus_id,
|
stripe_api_cus_id,
|
||||||
[{"plan": stripe_plan.get(
|
[{"plan": stripe_plan.get(
|
||||||
'response_object').stripe_plan_id}])
|
'response_object').stripe_plan_id}],
|
||||||
|
int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None
|
||||||
|
)
|
||||||
stripe_subscription_obj = subscription_result.get('response_object')
|
stripe_subscription_obj = subscription_result.get('response_object')
|
||||||
# Check if the subscription was approved and is active
|
# Check if the subscription was approved and is active
|
||||||
if (stripe_subscription_obj is None
|
if (stripe_subscription_obj is None
|
||||||
|
|
|
@ -724,6 +724,7 @@ X_FRAME_OPTIONS = ('SAMEORIGIN' if X_FRAME_OPTIONS_ALLOW_FROM_URI is None else
|
||||||
INVOICE_WEBHOOK_SECRET = env('INVOICE_WEBHOOK_SECRET')
|
INVOICE_WEBHOOK_SECRET = env('INVOICE_WEBHOOK_SECRET')
|
||||||
|
|
||||||
DEBUG = bool_env('DEBUG')
|
DEBUG = bool_env('DEBUG')
|
||||||
|
ADD_TRIAL_PERIOD_TO_SUBSCRIPTION = bool_env('ADD_TRIAL_PERIOD_TO_SUBSCRIPTION')
|
||||||
|
|
||||||
READ_VM_REALM = env('READ_VM_REALM')
|
READ_VM_REALM = env('READ_VM_REALM')
|
||||||
AUTH_NAME = env('AUTH_NAME')
|
AUTH_NAME = env('AUTH_NAME')
|
||||||
|
|
|
@ -1034,7 +1034,8 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView):
|
||||||
subscription_result = stripe_utils.subscribe_customer_to_plan(
|
subscription_result = stripe_utils.subscribe_customer_to_plan(
|
||||||
stripe_api_cus_id,
|
stripe_api_cus_id,
|
||||||
[{"plan": stripe_plan.get(
|
[{"plan": stripe_plan.get(
|
||||||
'response_object').stripe_plan_id}])
|
'response_object').stripe_plan_id}],
|
||||||
|
int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None)
|
||||||
stripe_subscription_obj = subscription_result.get('response_object')
|
stripe_subscription_obj = subscription_result.get('response_object')
|
||||||
# Check if the subscription was approved and is active
|
# Check if the subscription was approved and is active
|
||||||
if (stripe_subscription_obj is None or
|
if (stripe_subscription_obj is None or
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from unittest import skipIf
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import stripe
|
import stripe
|
||||||
|
@ -8,7 +10,6 @@ from django.conf import settings
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.test import Client
|
from django.test import Client
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from unittest import skipIf
|
|
||||||
from model_mommy import mommy
|
from model_mommy import mommy
|
||||||
|
|
||||||
from datacenterlight.models import StripePlan
|
from datacenterlight.models import StripePlan
|
||||||
|
@ -231,7 +232,8 @@ class StripePlanTestCase(TestStripeCustomerDescription):
|
||||||
result = self.stripe_utils.subscribe_customer_to_plan(
|
result = self.stripe_utils.subscribe_customer_to_plan(
|
||||||
stripe_customer.stripe_id,
|
stripe_customer.stripe_id,
|
||||||
[{"plan": stripe_plan.get(
|
[{"plan": stripe_plan.get(
|
||||||
'response_object').stripe_plan_id}])
|
'response_object').stripe_plan_id}],
|
||||||
|
int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None)
|
||||||
self.assertIsInstance(result.get('response_object'),
|
self.assertIsInstance(result.get('response_object'),
|
||||||
stripe.Subscription)
|
stripe.Subscription)
|
||||||
self.assertIsNone(result.get('error'))
|
self.assertIsNone(result.get('error'))
|
||||||
|
@ -247,7 +249,8 @@ class StripePlanTestCase(TestStripeCustomerDescription):
|
||||||
result = self.stripe_utils.subscribe_customer_to_plan(
|
result = self.stripe_utils.subscribe_customer_to_plan(
|
||||||
stripe_customer.stripe_id,
|
stripe_customer.stripe_id,
|
||||||
[{"plan": stripe_plan.get(
|
[{"plan": stripe_plan.get(
|
||||||
'response_object').stripe_plan_id}])
|
'response_object').stripe_plan_id}],
|
||||||
|
int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None)
|
||||||
self.assertIsNone(result.get('response_object'), None)
|
self.assertIsNone(result.get('response_object'), None)
|
||||||
self.assertIsNotNone(result.get('error'))
|
self.assertIsNotNone(result.get('error'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue