Ejemplo n.º 1
0
 def test_valid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'stripe_id': "sub_6lsC8pt7IcFpjA",
             'customer': self.customer.djstripe_id,
             "billing": "charge_automatically",
             'plan': self.plan.djstripe_id,
             'quantity': 2,
             'start': now,
             'status': SubscriptionStatus.active,
             'current_period_end': now + timezone.timedelta(days=5),
             'current_period_start': now,
         })
     self.assertTrue(serializer.is_valid())
     self.assertEqual(
         serializer.validated_data, {
             'stripe_id': "sub_6lsC8pt7IcFpjA",
             'customer': self.customer,
             "billing": "charge_automatically",
             'plan': self.plan,
             'quantity': 2,
             'start': now,
             'status': SubscriptionStatus.active,
             'current_period_end': now + timezone.timedelta(days=5),
             'current_period_start': now,
         })
     self.assertEqual(serializer.errors, {})
Ejemplo n.º 2
0
 def test_valid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             "id": "sub_6lsC8pt7IcFpjA",
             "customer": self.customer.djstripe_id,
             "billing": "charge_automatically",
             "plan": self.plan.djstripe_id,
             "quantity": 2,
             "start": now,
             "status": SubscriptionStatus.active,
             "current_period_end": now + timezone.timedelta(days=5),
             "current_period_start": now,
         })
     self.assertTrue(serializer.is_valid())
     self.assertEqual(
         serializer.validated_data,
         {
             "id": "sub_6lsC8pt7IcFpjA",
             "customer": self.customer,
             "billing": "charge_automatically",
             "plan": self.plan,
             "quantity": 2,
             "start": now,
             "status": SubscriptionStatus.active,
             "current_period_end": now + timezone.timedelta(days=5),
             "current_period_start": now,
         },
     )
     self.assertEqual(serializer.errors, {})
Ejemplo n.º 3
0
 def test_valid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'stripe_id': "sub_6lsC8pt7IcFpjA",
             'customer': self.customer.id,
             'plan': self.plan.id,
             'quantity': 2,
             'start': now,
             'status': Subscription.STATUS_ACTIVE,
             'current_period_end': now + timezone.timedelta(days=5),
             'current_period_start': now,
         })
     self.assertTrue(serializer.is_valid())
     self.assertEqual(
         serializer.validated_data, {
             'stripe_id': "sub_6lsC8pt7IcFpjA",
             'customer': self.customer,
             'plan': self.plan,
             'quantity': 2,
             'start': now,
             'status': Subscription.STATUS_ACTIVE,
             'current_period_end': now + timezone.timedelta(days=5),
             'current_period_start': now,
         })
     self.assertEqual(serializer.errors, {})
Ejemplo n.º 4
0
 def test_invalid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'plan': settings.DJSTRIPE_PLANS['test0']['plan'],
             'start': now,
             'status': CurrentSubscription.STATUS_ACTIVE,
             'amount': settings.DJSTRIPE_PLANS['test0']['price'],
         }
     )
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.validated_data, {})
     self.assertEqual(serializer.errors, {'quantity': ['This field is required.']})
Ejemplo n.º 5
0
 def test_invalid_serializer(self, product_retrieve_mock):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             "id": "sub_6lsC8pt7IcFpjA",
             "customer": self.customer.djstripe_id,
             "plan": self.plan.djstripe_id,
             "start": now,
             "status": SubscriptionStatus.active,
             "current_period_end": now + timezone.timedelta(days=5),
             "current_period_start": now,
         })
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.validated_data, {})
     self.assertEqual(serializer.errors,
                      {"billing": ["This field is required."]})
Ejemplo n.º 6
0
 def test_invalid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'stripe_id': "sub_6lsC8pt7IcFpjA",
             'customer': self.customer.id,
             'plan': self.plan.id,
             'start': now,
             'status': SubscriptionStatus.active,
             'current_period_end': now + timezone.timedelta(days=5),
             'current_period_start': now,
         })
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.validated_data, {})
     self.assertEqual(serializer.errors,
                      {'quantity': ['This field is required.']})
Ejemplo n.º 7
0
    def get(self, request, format=None):
        """
        Return the users current subscription.
        Returns with status code 200.
        """

        try:
            customer, created = Customer.get_or_create(
                subscriber=subscriber_request_callback(self.request))
            subscription = customer.current_subscription

            serializer = SubscriptionSerializer(subscription)
            return Response(serializer.data)

        except:
            return Response(status=status.HTTP_204_NO_CONTENT)
Ejemplo n.º 8
0
 def test_valid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'plan': settings.DJSTRIPE_PLANS['test0']['plan'],
             'quantity': 2,
             'start': now,
             'status': CurrentSubscription.STATUS_ACTIVE,
             'amount': settings.DJSTRIPE_PLANS['test0']['price'],
         }
     )
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.validated_data, {
         'plan': 'test0',
         'quantity': 2,
         'start': now,
         'status': 'active',
         'amount': Decimal('1000'),
     })
     self.assertEqual(serializer.errors, {})