예제 #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, {})
예제 #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, {})
예제 #3
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, {})
예제 #4
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, {})
예제 #5
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.']})
예제 #6
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."]})
예제 #7
0
 def test_invalid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'stripe_id': 'sub_yyyyyyyyyyyyyy',
             'plan': settings.DJSTRIPE_PLANS['test0']['plan'],
             'start': now,
             'status': Subscription.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.']})
예제 #8
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."]})
예제 #9
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.']})
예제 #10
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."]})
예제 #11
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, {})
예제 #12
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, {})
예제 #13
0
 def test_valid_serializer(self):
     now = timezone.now()
     serializer = SubscriptionSerializer(
         data={
             'stripe_id': 'sub_yyyyyyyyyyyyyy',
             'plan': settings.DJSTRIPE_PLANS['test0']['plan'],
             'quantity': 2,
             'start': now,
             'status': Subscription.STATUS_ACTIVE,
             'amount': settings.DJSTRIPE_PLANS['test0']['price'],
         }
     )
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.validated_data, {
         'stripe_id': 'sub_yyyyyyyyyyyyyy',
         'plan': 'test0',
         'quantity': 2,
         'start': now,
         'status': 'active',
         'amount': Decimal('1000'),
     })
     self.assertEqual(serializer.errors, {})
예제 #14
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)