Ejemplo n.º 1
0
 def test_formatting_with_message_none_and_request_id(self):
     err = StripeError(None, headers={'request-id': '123'})
     self.assertEqual(u'Request 123: <empty message>', six.text_type(err))
     if six.PY2:
         self.assertEqual('Request 123: <empty message>', str(err))
     else:
         self.assertEqual('Request 123: <empty message>', str(err))
Ejemplo n.º 2
0
 def test_formatting(self):
     err = StripeError(u'öre')
     self.assertEqual(u'öre', six.text_type(err))
     if six.PY2:
         self.assertEqual('\xc3\xb6re', str(err))
     else:
         self.assertEqual(u'öre', str(err))
Ejemplo n.º 3
0
 def test_formatting_with_message_none_and_request_id_none(self):
     err = StripeError(None)
     self.assertEqual(u'<empty message>', six.text_type(err))
     if six.PY2:
         self.assertEqual('<empty message>', str(err))
     else:
         self.assertEqual('<empty message>', str(err))
Ejemplo n.º 4
0
 def test_formatting(self):
     err = StripeError(u'öre')
     if six.PY3:
         assert str(err) == u'öre'
     else:
         assert str(err) == '\xc3\xb6re'
         assert unicode(err) == u'öre'
Ejemplo n.º 5
0
 def test_formatting_with_request_id(self):
     err = StripeError(u'öre', headers={'request-id': '123'})
     self.assertEqual(u'Request 123: öre', six.text_type(err))
     if six.PY2:
         self.assertEqual('Request 123: \xc3\xb6re', str(err))
     else:
         self.assertEqual(u'Request 123: öre', str(err))
Ejemplo n.º 6
0
 def test_formatting_with_request_id(self):
     err = StripeError(u'öre', headers={'request-id': '123'})
     if six.PY3:
         assert str(err) == u'Request 123: öre'
     else:
         assert str(err) == 'Request 123: \xc3\xb6re'
         assert unicode(err) == u'Request 123: öre'
Ejemplo n.º 7
0
 def test_formatting_with_none(self):
     err = StripeError(None, headers={'request-id': '123'})
     if six.PY3:
         assert str(err) == u'Request 123: <empty message>'
     else:
         assert str(err) == 'Request 123: <empty message>'
         assert unicode(err) == u'Request 123: <empty message>'
 def test_formatting_with_none(self):
     err = StripeError(None, headers={'request-id': '123'})
     if sys.version_info > (3, 0):
         assert str(err) == 'Request 123: <empty message>'
     else:
         assert str(err) == 'Request 123: <empty message>'
         assert str(err) == 'Request 123: <empty message>'
Ejemplo n.º 9
0
 def test_formatting(self):
     err = StripeError(u'öre')
     if sys.version_info > (3, 0):
         assert str(err) == u'öre'
     else:
         assert str(err) == '\xc3\xb6re'
         assert unicode(err) == u'öre'
 def test_formatting_with_request_id(self):
     err = StripeError('öre', headers={'request-id': '123'})
     if sys.version_info > (3, 0):
         assert str(err) == 'Request 123: öre'
     else:
         assert str(err) == 'Request 123: \xc3\xb6re'
         assert str(err) == 'Request 123: öre'
Ejemplo n.º 11
0
 def test_repr(self):
     err = StripeError(u'öre', headers={'request-id': '123'})
     if six.PY2:
         self.assertEquals(
             repr(err),
             ("StripeError(message=u'\\xf6re', http_status=None, "
              "request_id='123')"))
     else:
         self.assertEquals(repr(err),
                           ("StripeError(message='öre', http_status=None, "
                            "request_id='123')"))
Ejemplo n.º 12
0
    def test_post(self, mock_security_invoice_item,
                  mock_shareholder_invoice_item, mock_sync_card):
        operator = OperatorGenerator().generate()
        operator.company.get_customer()

        view_url = reverse('djstripe:confirm',
                           args=[operator.company_id, 'test'])

        req = self.factory.post(view_url)
        req.user = operator.user
        req.resolver_match = resolve(view_url)
        self.view.request = req
        self.view.kwargs = dict(plan='test', company_id=operator.company_id)

        self.view.form_invalid = mock.Mock(
            side_effect=ValidationError('ERROR'))
        with self.assertRaises(ValidationError):
            res = self.view.post(req)
            self.assertIn('ERROR', res.content)  # pragma: nocover

        post_data = dict(plan='test', email=random_gen.gen_email())
        req = self.factory.post(view_url, data=post_data)
        req.user = operator.user
        req.resolver_match = resolve(view_url)
        self.view.request = req

        with mock.patch('djstripe.models.Customer.subscribe'):
            res = self.view.post(req)
            self.assertEqual(res.status_code, 302)

        mock_shareholder_invoice_item.assert_called()
        mock_security_invoice_item.assert_called()

        company = operator.company.__class__.objects.get(
            pk=operator.company_id)
        self.assertEqual(company.email, post_data['email'])

        # test unsubscribable
        with mock.patch('shareholder.models.Company.validate_plan',
                        return_value=(False, [])):

            with self.assertRaises(ValidationError):
                self.view.post(req)

        with mock.patch('djstripe.models.Customer.subscribe',
                        side_effect=StripeError('STRIPEERROR')):
            with self.assertRaises(ValidationError):
                res = self.view.post(req)
                self.assertIn('STRIPEERROR', res.content)  # pragma: nocover
Ejemplo n.º 13
0
 def test_make_donation_stripe_exception(self, charge_create, customer_create):
     customer_create.return_value.id = 'xxxx'
     charge_create.side_effect = StripeError('Payment failed')
     form = PaymentForm(data={
         'amount': 100,
         'stripe_token': 'xxxx',
         'interval': 'onetime',
         'receipt_email': '*****@*****.**',
     })
     self.assertTrue(form.is_valid())
     with self.assertRaisesMessage(StripeError, 'Payment failed'):
         donation = form.make_donation()
         self.assertIsNone(donation)
     # Hero shouldn't be created.
     self.assertFalse(DjangoHero.objects.exists())
Ejemplo n.º 14
0
 def charge_create(**kwargs):
     raise StripeError(message='Foo')
Ejemplo n.º 15
0
    def test_post(self, mock_security_invoice_item,
                  mock_shareholder_invoice_item, mock_sync_card):
        operator = OperatorGenerator().generate()

        view_url = reverse('djstripe:confirm',
                           args=[operator.company_id, 'test'])

        req = self.factory.post(view_url)
        req.user = operator.user
        req.resolver_match = resolve(view_url)
        self.view.request = req
        self.view.kwargs = dict(plan='test', company_id=operator.company_id)

        self.view.form_invalid = mock.Mock(
            side_effect=ValidationError('ERROR'))

        # no customer
        with self.assertRaises(ValidationError):
            res = self.view.post(req)
            self.assertIn('ERROR', res.content)  # pragma: nocover

        # create customer
        operator.company.get_customer()

        with self.assertRaises(ValidationError):
            self.view.post(req)
            self.assertIn('ERROR', res.content)  # pragma: nocover

        post_data = dict(plan='test')
        req = self.factory.post(view_url, data=post_data)
        req.user = operator.user
        req.resolver_match = resolve(view_url)
        self.view.request = req

        with mock.patch('djstripe.models.Customer.subscribe'):
            res = self.view.post(req)
            self.assertEqual(res.status_code, 302)

        mock_shareholder_invoice_item.assert_called()
        mock_security_invoice_item.assert_called()

        # test prorate
        self.add_subscription(operator.company)
        with mock.patch('djstripe.models.Customer.subscribe') as mock_sub:
            with mock.patch('company.views.PRORATION_POLICY_FOR_UPGRADES',
                            return_value=False):
                self.view.post(req)
                mock_sub.assert_called_with('test', prorate=False)

            mock_sub.reset_mock()

            with mock.patch('company.views.PRORATION_POLICY_FOR_UPGRADES',
                            return_value=True):
                self.view.post(req)
                mock_sub.assert_called_with('test', prorate=False)

            mock_sub.reset_mock()

            with mock.patch('company.views.PRORATION_POLICY_FOR_UPGRADES',
                            return_value=True):
                plans = copy.deepcopy(djstripe_settings.PLAN_LIST)
                plans[0]['price'] = 1
                with mock.patch('company.views.PLAN_LIST',
                                return_value=plans) as plan_mock:
                    plan_mock.__iter__.return_value = plans
                    self.view.post(req)
                    mock_sub.assert_called_with('test', prorate=True)

        # test unsubscribable
        with mock.patch('shareholder.models.Company.validate_plan',
                        return_value=(False, [])):

            with self.assertRaises(ValidationError):
                self.view.post(req)

        with mock.patch('djstripe.models.Customer.subscribe',
                        side_effect=StripeError('STRIPEERROR')):
            with self.assertRaises(ValidationError):
                res = self.view.post(req)
                self.assertIn('STRIPEERROR', res.content)  # pragma: nocover