Ejemplo n.º 1
0
    def test_update(self):
        """Test update from stripe."""
        stripe_subscription = StripeSubscription.construct_from(
            {
                'id': 'sub_foo',
                'status': 'active',
                'current_period_start': 120778389,
                'current_period_end': 123456789,
                'trial_end': 1475437877,
                'plan': {
                    'id': 'advanced',
                }
            },
            None,
        )
        subscription = fixture.get(
            Subscription,
            stripe_id='sub_foo',
            status='trialing',
        )
        Subscription.objects.update_from_stripe(
            rtd_subscription=subscription,
            stripe_subscription=stripe_subscription,
        )
        subscription.refresh_from_db()
        self.assertEqual(subscription.status, 'active')
        self.assertEqual(
            subscription.end_date,
            timezone.make_aware(datetime.fromtimestamp(123456789)),
        )
        self.assertEqual(
            subscription.trial_end_date,
            timezone.make_aware(datetime.fromtimestamp(1475437877)),
        )

        # Cancel event
        stripe_subscription = StripeSubscription.construct_from(
            {
                'id': 'sub_foo',
                'status': 'unpaid',
                'plan': {
                    'id': 'advanced',
                }
            },
            None,
        )
        Subscription.objects.update_from_stripe(
            rtd_subscription=subscription,
            stripe_subscription=stripe_subscription,
        )
        subscription.refresh_from_db()
        self.assertEqual(subscription.status, 'unpaid')
        self.assertEqual(
            subscription.trial_end_date,
            timezone.make_aware(datetime.fromtimestamp(1475437877)),
        )
Ejemplo n.º 2
0
 def test_replace_subscription(self):
     """Test update from stripe."""
     stripe_subscription = StripeSubscription.construct_from(
         {
             'id': 'sub_bar',
             'status': 'active',
             'plan': {
                 'id': 'advanced',
             }
         },
         None,
     )
     subscription = fixture.get(
         Subscription,
         stripe_id='sub_foo',
         status='trialing',
     )
     Subscription.objects.update_from_stripe(
         rtd_subscription=subscription,
         stripe_subscription=stripe_subscription,
     )
     subscription.refresh_from_db()
     self.assertEqual(subscription.stripe_id, 'sub_bar')
     self.assertEqual(subscription.status, 'active')