def setUp(self): with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True, ): Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II))
def handle(self, *args, **options): existed_ids = [] for plan in Plan.api_list(): stripe_id = plan.get('id') if Plan.objects.filter(stripe_id=stripe_id).exists(): print('Plan id=%s updated.' % stripe_id) else: print('Plan id=%s created.' % stripe_id) existed_ids.append(stripe_id) Plan.sync_from_stripe_data(plan)
def test_create_with_metadata(self, ApiCreateMock, ObjectsCreateMock): metadata = {'other_data': 'more_data'} Plan.create(metadata=metadata, arg1=1, arg2=2, amount=1, stripe_id=1) ApiCreateMock.assert_called_once_with(metadata=metadata, id=1, arg1=1, arg2=2, amount=100) ObjectsCreateMock.assert_called_once_with(stripe_id=1, arg1=1, arg2=2, amount=1)
def test_create_with_metadata(self, api_create_mock, object_create_mock): metadata = {"other_data": "more_data"} Plan.create(metadata=metadata, arg1=1, arg2=2, amount=1, id=1) api_create_mock.assert_called_once_with(metadata=metadata, id=1, arg1=1, arg2=2, amount=100) object_create_mock.assert_called_once_with(metadata=metadata, id=1, arg1=1, arg2=2, amount=1)
def test_upcoming_invoice_with_subscription_plan( self, product_retrieve_mock, invoice_upcoming_mock, subscription_retrieve_mock, plan_retrieve_mock, invoice_retrieve_mock, payment_intent_retrieve_mock, paymentmethod_card_retrieve_mock, charge_retrieve_mock, balance_transaction_retrieve_mock, ): # create invoice for latest_invoice in subscription to work. Invoice.sync_from_stripe_data(deepcopy(FAKE_INVOICE)) invoice = Invoice.upcoming(subscription_plan=Plan(id=FAKE_PLAN["id"])) self.assertIsNotNone(invoice) self.assertIsNone(invoice.id) self.assertIsNone(invoice.save()) subscription_retrieve_mock.assert_called_once_with( api_key=ANY, expand=ANY, id=FAKE_SUBSCRIPTION["id"], stripe_account=None) plan_retrieve_mock.assert_not_called() self.assertIsNotNone(invoice.plan) self.assertEqual(FAKE_PLAN["id"], invoice.plan.id)
def test_subscribe_plan_string(self, customer_retrieve_mock, subscription_create_mock, send_invoice_mock): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.customer.subscribe(plan=plan.stripe_id, charge_immediately=True) self.assertTrue(send_invoice_mock.called)
def test_has_active_subscription_with_unspecified_plan_with_multiple_subscriptions( self, customer_retrieve_mock, subscription_create_mock): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription_fake["current_period_end"] = datetime_to_unix( timezone.now() + timezone.timedelta(days=7)) subscription_fake_duplicate = deepcopy(FAKE_SUBSCRIPTION) subscription_fake_duplicate["current_period_end"] = datetime_to_unix( timezone.now() + timezone.timedelta(days=7)) subscription_fake_duplicate["id"] = "sub_6lsC8pt7IcF8jd" subscription_create_mock.side_effect = [ subscription_fake, subscription_fake_duplicate, ] self.customer.subscribe(plan=plan, charge_immediately=False) self.customer.subscribe(plan=plan, charge_immediately=False) self.assertEqual(2, self.customer.subscriptions.count()) with self.assertRaises(TypeError): self.customer.has_active_subscription()
def test_update_with_plan_model( self, customer_retrieve_mock, subscription_retrieve_mock, subscription_modify_mock, product_retrieve_mock, plan_retrieve_mock, ): subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription = Subscription.sync_from_stripe_data(subscription_fake) new_plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II)) self.assertEqual(FAKE_PLAN["id"], subscription.plan.id) # Update the Subscription's plan subscription_updated = deepcopy(FAKE_SUBSCRIPTION) subscription_updated["plan"] = deepcopy(FAKE_PLAN_II) subscription_modify_mock.return_value = subscription_updated new_subscription = subscription.update(plan=new_plan) self.assertEqual(FAKE_PLAN_II["id"], new_subscription.plan.id) self.assert_fks(subscription, expected_blank_fks=self.default_expected_blank_fks) self.assert_fks(new_plan, expected_blank_fks={})
def test_update_with_plan_model( self, customer_retrieve_mock, subscription_retrieve_mock, product_retrieve_mock, plan_retrieve_mock, ): subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription = Subscription.sync_from_stripe_data(subscription_fake) new_plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II)) self.assertEqual(FAKE_PLAN["id"], subscription.plan.id) new_subscription = subscription.update(plan=new_plan) self.assertEqual(FAKE_PLAN_II["id"], new_subscription.plan.id) self.assert_fks( subscription, expected_blank_fks={ "djstripe.Customer.coupon", "djstripe.Subscription.pending_setup_intent", }, ) self.assert_fks(new_plan, expected_blank_fks={})
def setUp(self): self.user = get_user_model().objects.create_user( username="******", email="*****@*****.**") self.customer = Customer.objects.create(subscriber=self.user, stripe_id=FAKE_CUSTOMER["id"], livemode=False) self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN))
def setUp(self): with patch("stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT)): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.site = AdminSite() self.plan_admin = PlanAdmin(Plan, self.site)
def post(self, request, *args, **kwargs): plans = Plan.objects.all() stripe_id = 1 try: if plans: stripe_id = plans.first().id + 1 plan_args = request.POST.dict() plan_args['stripe_id'] = stripe_id plan_args.pop('csrfmiddlewaretoken') plan_args['amount'] = int(plan_args['amount']) Plan.create(**plan_args) return redirect("users_plan_list") except stripe.error.InvalidRequestError as err: card_msg = err._message messages.error(self.request, _(card_msg)) return redirect("users_plan_create")
def test_has_active_subscription_with_unspecified_plan_with_multiple_subscriptions( self, product_retrieve_mock, customer_retrieve_mock, subscription_create_mock ): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.assert_fks(plan, expected_blank_fks={}) subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription_fake["current_period_end"] = datetime_to_unix( timezone.now() + timezone.timedelta(days=7) ) subscription_fake_duplicate = deepcopy(FAKE_SUBSCRIPTION) subscription_fake_duplicate["current_period_end"] = datetime_to_unix( timezone.now() + timezone.timedelta(days=7) ) subscription_fake_duplicate["id"] = "sub_6lsC8pt7IcF8jd" subscription_create_mock.side_effect = [ subscription_fake, subscription_fake_duplicate, ] self.customer.subscribe(plan=plan, charge_immediately=False) self.customer.subscribe(plan=plan, charge_immediately=False) self.assertEqual(2, self.customer.subscriptions.count()) with self.assertRaises(TypeError): self.customer.has_active_subscription()
def test_stripe_metered_plan(self, plan_retrieve_mock): plan_data = deepcopy(FAKE_PLAN_METERED) plan = Plan.sync_from_stripe_data(plan_data) self.assertEqual(plan.id, plan_data["id"]) self.assertEqual(plan.usage_type, PriceUsageType.metered) self.assertIsNotNone(plan.amount) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_stripe_plan(self, plan_retrieve_mock): stripe_plan = self.plan.api_retrieve() plan_retrieve_mock.assert_called_once_with(id=self.plan_data["id"], api_key=STRIPE_SECRET_KEY, expand=[]) plan = Plan.sync_from_stripe_data(stripe_plan) assert plan.amount_in_cents == plan.amount * 100 assert isinstance(plan.amount_in_cents, int)
def setUp(self): self.plan_data = deepcopy(FAKE_PLAN) with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True, ): self.plan = Plan.sync_from_stripe_data(self.plan_data)
def test_stripe_tier_plan(self, plan_retrieve_mock): tier_plan_data = deepcopy(FAKE_TIER_PLAN) plan = Plan.sync_from_stripe_data(tier_plan_data) self.assertEqual(plan.id, tier_plan_data["id"]) self.assertIsNone(plan.amount) self.assertIsNotNone(plan.tiers) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_stripe_metered_plan(self, plan_retrieve_mock): plan_data = deepcopy(FAKE_PLAN_METERED) plan = Plan.sync_from_stripe_data(plan_data) self.assertEqual(plan.id, plan_data["id"]) self.assertEqual(plan.usage_type, PlanUsageType.metered) self.assertIsNotNone(plan.amount) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def sync_plans(apps, schema_editor): # This is okay, since we're only doing a forward migration. from djstripe.models import Plan from djstripe.context_managers import stripe_temporary_api_version with stripe_temporary_api_version("2016-03-07"): if Plan.objects.count(): print("syncing plans. This may take a while.") for plan in tqdm(iterable=Plan.objects.all(), desc="Sync", unit=" plans"): try: Plan.sync_from_stripe_data(plan) except InvalidRequestError: tqdm.write("There was an error while syncing plan ({plan_id}).".format(transfer_id=plan.stripe_id)) print("Transfer sync complete.")
def setUp(self): with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True ): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.site = AdminSite() self.plan_admin = PlanAdmin(Plan, self.site)
def setUp(self): self.user = get_user_model().objects.create_user( username="******", email="*****@*****.**") self.customer = FAKE_CUSTOMER.create_for_user(self.user) with patch("stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT)): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN))
def setUp(self): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.url = reverse("djstripe:cancel_subscription") self.user = get_user_model().objects.create_user( username="******", email="*****@*****.**", password="******" ) self.assertTrue(self.client.login(username="******", password="******"))
def get_queryset(self): stripe.api_key = settings.STRIPE_LIVE_PUBLIC_KEY try: plan_list = stripe.Plan.list() plans = [ Plan.sync_from_stripe_data(pl) for pl in plan_list['data'] ] except stripe.error.PermissionError: plans = [] return plans
def setUp(self): self.user = get_user_model().objects.create_user( username="******", email="*****@*****.**" ) self.customer = FAKE_CUSTOMER.create_for_user(self.user) with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True ): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN))
def test_stripe_plan(self, plan_retrieve_mock): stripe_plan = self.plan.api_retrieve() plan_retrieve_mock.assert_called_once_with( id=self.plan_data["id"], api_key=STRIPE_SECRET_KEY, expand=[] ) plan = Plan.sync_from_stripe_data(stripe_plan) assert plan.amount_in_cents == plan.amount * 100 assert isinstance(plan.amount_in_cents, int) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_that_admin_save_does_create_new_object(self, plan_retrieve_mock, plan_create_mock): fake_form = self.FakeForm() plan_data = Plan._stripe_object_to_record(deepcopy(FAKE_PLAN_II)) fake_form.cleaned_data = plan_data self.plan_admin.save_model(request=self.FakeRequest(), obj=None, form=fake_form, change=False) # Would throw DoesNotExist if it didn't work Plan.objects.get(stripe_id=plan_data["stripe_id"])
def test_stripe_plan(self, plan_retrieve_mock): stripe_plan = self.plan.api_retrieve() plan_retrieve_mock.assert_called_once_with( id=self.plan_data["id"], api_key=settings.STRIPE_SECRET_KEY, expand=None ) plan = Plan.sync_from_stripe_data(stripe_plan) assert plan.amount_in_cents == plan.amount * 100 assert isinstance(plan.amount_in_cents, int)
def test_update_with_plan_model(self, customer_retrieve_mock, subscription_retrieve_mock, plan_retrieve_mock): subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription = Subscription.sync_from_stripe_data(subscription_fake) new_plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II)) self.assertEqual(FAKE_PLAN["id"], subscription.plan.stripe_id) new_subscription = subscription.update(plan=new_plan) self.assertEqual(FAKE_PLAN_II["id"], new_subscription.plan.stripe_id)
def test_has_active_subscription_with_plan_string(self, customer_retrieve_mock, subscription_create_mock): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription_fake["current_period_end"] = datetime_to_unix(timezone.now() + timezone.timedelta(days=7)) subscription_create_mock.return_value = subscription_fake self.customer.subscribe(plan=plan, charge_immediately=False) self.customer.has_active_subscription(plan=plan.stripe_id)
def test_subscribe_not_charge_immediately( self, product_retrieve_mock, customer_retrieve_mock, subscription_create_mock, send_invoice_mock, ): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.customer.subscribe(plan=plan, charge_immediately=False) self.assertFalse(send_invoice_mock.called)
def test_create_from_djstripe_product(self, plan_create_mock, product_retrieve_mock): fake_plan = deepcopy(FAKE_PLAN) fake_plan["product"] = Product.sync_from_stripe_data(self.stripe_product) fake_plan["amount"] = fake_plan["amount"] / 100 self.assertIsInstance(fake_plan["product"], Product) plan = Plan.create(**fake_plan) plan_create_mock.assert_called_once_with(api_key=STRIPE_SECRET_KEY, **FAKE_PLAN) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_upcoming_invoice_with_subscription_plan(self, invoice_upcoming_mock, subscription_retrieve_mock, plan_retrieve_mock): invoice = Invoice.upcoming(subscription_plan=Plan(stripe_id=FAKE_PLAN["id"])) self.assertIsNotNone(invoice) self.assertIsNone(invoice.stripe_id) self.assertIsNone(invoice.save()) subscription_retrieve_mock.assert_called_once_with(api_key=ANY, expand=ANY, id=FAKE_SUBSCRIPTION["id"]) plan_retrieve_mock.assert_not_called() self.assertIsNotNone(invoice.plan) self.assertEqual(FAKE_PLAN["id"], invoice.plan.stripe_id)
def test_stripe_plan_null_product(self, product_retrieve_mock): """ assert that plan.Product can be null for backwards compatibility though note that it is a Stripe required field """ plan_data = deepcopy(FAKE_PLAN_II) del plan_data["product"] plan = Plan.sync_from_stripe_data(plan_data) self.assert_fks( plan, expected_blank_fks={"djstripe.Customer.coupon", "djstripe.Plan.product"} )
def setUp(self): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.url = reverse("djstripe:cancel_subscription") self.user = get_user_model().objects.create_user( username="******", email="*****@*****.**", password="******" ) self.assertTrue(self.client.login(username="******", password="******")) stripe_customer = Customer.sync_from_stripe_data(FAKE_CUSTOMER) stripe_customer.subscriber = self.user stripe_customer.save()
def remote_plan_cleanup(): """Go through the remote plans and remove thos that are not in the local list of plans.""" for remote_plan in Plan.api_list(): if remote_plan['nickname'] in PLAN_NAMES: active = True else: active = False stripe.Plan.modify(remote_plan['id'], api_key=djstripe_settings.STRIPE_SECRET_KEY, active=active) LOGGER.info('Remote Plan %s made %s', remote_plan['nickname'], 'active' if active else 'inactive')
def test_get_subscription(self): """Test a GET to the SubscriptionRestView. Should return the correct data. """ plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) subscription = Subscription.sync_from_stripe_data(deepcopy(FAKE_SUBSCRIPTION)) response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["plan"], plan.id) self.assertEqual(response.data['status'], subscription.status) self.assertEqual(response.data['cancel_at_period_end'], subscription.cancel_at_period_end)
def test_stripe_plan_null_product(self, product_retrieve_mock): """ assert that plan.Product can be null for backwards compatibility though note that it is a Stripe required field """ plan_data = deepcopy(FAKE_PLAN_II) del plan_data["product"] plan = Plan.sync_from_stripe_data(plan_data) self.assert_fks(plan, expected_blank_fks={ "djstripe.Customer.coupon", "djstripe.Plan.product" })
def test_create_from_product_id(self, plan_create_mock, product_retrieve_mock): fake_plan = deepcopy(FAKE_PLAN) fake_plan["amount"] = fake_plan["amount"] / 100 self.assertIsInstance(fake_plan["product"], str) plan = Plan.create(**fake_plan) expected_create_kwargs = deepcopy(FAKE_PLAN) expected_create_kwargs["api_key"] = STRIPE_SECRET_KEY plan_create_mock.assert_called_once_with(**expected_create_kwargs) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_stripe_plan(self, plan_retrieve_mock): stripe_plan = self.plan.api_retrieve() plan_retrieve_mock.assert_called_once_with(id=self.plan_data["id"], api_key=STRIPE_SECRET_KEY, expand=[]) plan = Plan.sync_from_stripe_data(stripe_plan) assert plan.amount_in_cents == plan.amount * 100 assert isinstance(plan.amount_in_cents, int) self.assert_fks(plan, expected_blank_fks={ "djstripe.Customer.coupon", "djstripe.Plan.product" })
def test_subscribe_plan_string( self, product_retrieve_mock, customer_retrieve_mock, subscription_create_mock, send_invoice_mock, ): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.assert_fks(plan, expected_blank_fks={}) self.customer.subscribe(plan=plan.id, charge_immediately=True) self.assertTrue(send_invoice_mock.called)
def test_stripe_plan(self, plan_retrieve_mock): stripe_plan = self.plan.api_retrieve() plan_retrieve_mock.assert_called_once_with( id=self.plan_data["id"], api_key=djstripe_settings.STRIPE_SECRET_KEY, expand=["tiers"], stripe_account=self.plan.djstripe_owner_account.id, ) plan = Plan.sync_from_stripe_data(stripe_plan) assert plan.amount_in_cents == plan.amount * 100 assert isinstance(plan.amount_in_cents, int) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_subscription_shortcut_with_multiple_subscriptions(self, customer_retrieve_mock, subscription_create_mock): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) subscription_fake_duplicate = deepcopy(FAKE_SUBSCRIPTION) subscription_fake_duplicate["id"] = "sub_6lsC8pt7IcF8jd" subscription_create_mock.side_effect = [deepcopy(FAKE_SUBSCRIPTION), subscription_fake_duplicate] self.customer.subscribe(plan=plan, charge_immediately=False) self.customer.subscribe(plan=plan, charge_immediately=False) self.assertEqual(2, self.customer.subscriptions.count()) with self.assertRaises(MultipleSubscriptionException): self.customer.subscription
def test_create_with_metadata(self, plan_create_mock, product_retrieve_mock): metadata = {"other_data": "more_data"} fake_plan = deepcopy(FAKE_PLAN) fake_plan["amount"] = fake_plan["amount"] / 100 fake_plan["metadata"] = metadata self.assertIsInstance(fake_plan["product"], str) plan = Plan.create(**fake_plan) expected_create_kwargs = deepcopy(FAKE_PLAN) expected_create_kwargs["metadata"] = metadata plan_create_mock.assert_called_once_with( api_key=STRIPE_SECRET_KEY, **expected_create_kwargs ) self.assert_fks(plan, expected_blank_fks={"djstripe.Customer.coupon"})
def test_get_subscription(self): """Test a GET to the SubscriptionRestView. Should return the correct data. """ with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True ): plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) subscription = Subscription.sync_from_stripe_data(deepcopy(FAKE_SUBSCRIPTION)) response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["plan"], plan.djstripe_id) self.assertEqual(response.data["status"], subscription.status) self.assertEqual( response.data["cancel_at_period_end"], subscription.cancel_at_period_end )
def test_update_with_plan_model( self, customer_retrieve_mock, subscription_retrieve_mock, product_retrieve_mock, plan_retrieve_mock, ): subscription_fake = deepcopy(FAKE_SUBSCRIPTION) subscription = Subscription.sync_from_stripe_data(subscription_fake) new_plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II)) self.assertEqual(FAKE_PLAN["id"], subscription.plan.id) new_subscription = subscription.update(plan=new_plan) self.assertEqual(FAKE_PLAN_II["id"], new_subscription.plan.id) self.assert_fks(subscription, expected_blank_fks={"djstripe.Customer.coupon"}) self.assert_fks(new_plan, expected_blank_fks={})
def setUp(self): self.plan_data = deepcopy(FAKE_PLAN) with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True ): self.plan = Plan.sync_from_stripe_data(self.plan_data)
def test_create_with_metadata(self, api_create_mock, object_create_mock): metadata = {'other_data': 'more_data'} Plan.create(metadata=metadata, arg1=1, arg2=2, amount=1, stripe_id=1) api_create_mock.assert_called_once_with(metadata=metadata, id=1, arg1=1, arg2=2, amount=100) object_create_mock.assert_called_once_with(metadata=metadata, stripe_id=1, arg1=1, arg2=2, amount=1)
def setUp(self): # create customers and current subscription records period_start = datetime.datetime(2013, 4, 1, tzinfo=timezone.utc) period_end = datetime.datetime(2013, 4, 30, tzinfo=timezone.utc) start = datetime.datetime( 2013, 1, 1, 0, 0, 1, tzinfo=timezone.utc ) # more realistic start with patch( "stripe.Product.retrieve", return_value=deepcopy(FAKE_PRODUCT), autospec=True ): self.plan = Plan.sync_from_stripe_data(FAKE_PLAN) self.plan2 = Plan.sync_from_stripe_data(FAKE_PLAN_II) for i in range(10): user = get_user_model().objects.create_user( username="******".format(i), email="patrick{0}@example.com".format(i) ) customer = Customer.objects.create( subscriber=user, id="cus_xxxxxxxxxxxxxx{0}".format(i), livemode=False, account_balance=0, delinquent=False, ) Subscription.objects.create( id="sub_xxxxxxxxxxxxxx{0}".format(i), customer=customer, plan=self.plan, current_period_start=period_start, current_period_end=period_end, status="active", start=start, quantity=1, ) user = get_user_model().objects.create_user( username="******".format(11), email="patrick{0}@example.com".format(11) ) customer = Customer.objects.create( subscriber=user, id="cus_xxxxxxxxxxxxxx{0}".format(11), livemode=False, account_balance=0, delinquent=False, ) Subscription.objects.create( id="sub_xxxxxxxxxxxxxx{0}".format(11), customer=customer, plan=self.plan, current_period_start=period_start, current_period_end=period_end, status="canceled", canceled_at=period_end, start=start, quantity=1, ) user = get_user_model().objects.create_user( username="******".format(12), email="patrick{0}@example.com".format(12) ) customer = Customer.objects.create( subscriber=user, id="cus_xxxxxxxxxxxxxx{0}".format(12), livemode=False, account_balance=0, delinquent=False, ) Subscription.objects.create( id="sub_xxxxxxxxxxxxxx{0}".format(12), customer=customer, plan=self.plan2, current_period_start=period_start, current_period_end=period_end, status="active", start=start, quantity=1, )
def setUp(self): self.plan_data = deepcopy(FAKE_PLAN) self.plan = Plan.sync_from_stripe_data(self.plan_data)
def setUp(self): self.plan = Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) self.site = AdminSite() self.plan_admin = PlanAdmin(Plan, self.site)
def setUp(self): Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN)) Plan.sync_from_stripe_data(deepcopy(FAKE_PLAN_II))