def test_post_with_no_token_redirects(self):
     """if a request is posted to the card view and the post data
     is missiung ['stripeToken'] then a HttpResponseRedirect is returned"""
     request = self.rf.post(reverse('stripe:card'))
     request.session['cccheckout'] = self.checkout
     r = card(request)
     # was a redirect
     self.assertEqual(reverse('stripe:card'), r['Location'])
 def test_unsuccessful_payment_redirects_to_payment(self):
     """if the response returns not paid then the checkout
     is not marked as paid"""
     settings.STRIPE_OUTCOME = 'UNPAID'
     reload(c_settings)
     # checkout is not paid self.assertFalse(self.checkout.paid)
     data = {'stripeToken': 'testtoken'}
     request = self.rf.post(reverse('stripe:mock_api'), data)
     request.session['cccheckout'] = self.checkout
     r = card(request)
     # get the checkout
     c = Checkout.objects.get(pk=self.checkout.pk)
     # checkout is not paid
     self.assertFalse(c.paid)
     # redirects to the payment
     self.assertEqual(200, r.status_code)
 def test_invalid_request_error_400(self):
     """if an InvalidRequestError is raised then it is handled 
     gracefully"""
     settings.STRIPE_OUTCOME = 'INVALIDREQUEST_400'
     reload(c_settings)
     # checkout is not paid self.assertFalse(self.checkout.paid)
     data = {'stripeToken': 'testtoken'}
     request = self.rf.post(reverse('stripe:mock_api'), data)
     request.session['cccheckout'] = self.checkout
     r = card(request)
     # get the checkout
     c = Checkout.objects.get(pk=self.checkout.pk)
     # checkout is not paid
     self.assertFalse(c.paid)
     # redirects to the payment
     self.assertEqual(200, r.status_code)
 def test_authentication_error_401(self):
     """if an AuthenticationError is raised then it is handled 
     gracefully"""
     settings.STRIPE_OUTCOME = 'AUTHENTICATIONERROR'
     reload(c_settings)
     # checkout is not paid self.assertFalse(self.checkout.paid)
     data = {'stripeToken': 'testtoken'}
     request = self.rf.post(reverse('stripe:mock_api'), data)
     request.session['cccheckout'] = self.checkout
     r = card(request)
     # get the checkout
     c = Checkout.objects.get(pk=self.checkout.pk)
     # checkout is not paid
     self.assertFalse(c.paid)
     # redirects to the payment
     self.assertEqual(200, r.status_code)
 def test_successful_payment_redirects(self):
     """if the response returns a paid amount then the checkout
     is marked as paid"""
     settings.STRIPE_OUTCOME = 'PASS'
     reload(c_settings)
     # checkout is not paid self.assertFalse(self.checkout.paid)
     data = {'stripeToken': 'testtoken'}
     request = self.rf.post(reverse('stripe:mock_api'), data)
     request.session['cccheckout'] = self.checkout
     r = card(request)
     # get the checkout
     c = Checkout.objects.get(pk=self.checkout.pk)
     # checkout is now paid
     self.assertTrue(c.paid)
     # redirects to the checkout:comlete
     self.assertEqual(r['Location'],
             reverse(c_settings.CCCHECKOUT_SUCCESS_URL))
 def test_successful_payment_redirects_custom_url(self):
     """Successul checkout can redirect to a url that throws a 
     NonReverseMatch exceprtion"""
     # store the original
     ORIGINAL_URL = c_settings.CCCHECKOUT_SUCCESS_URL
     # set the new one
     c_settings.CCCHECKOUT_SUCCESS_URL = '/epic-win.html'
     # checkout is not paid self.assertFalse(self.checkout.paid)
     data = {'stripeToken': 'testtoken'}
     request = self.rf.post(reverse('stripe:mock_api'), data)
     request.session['cccheckout'] = self.checkout
     r = card(request)
     # get the checkout
     c = Checkout.objects.get(pk=self.checkout.pk)
     # redirects to the new url
     self.assertEqual(r['Location'], '/epic-win.html')
     # put the original back
     c_settings.CCCHECKOUT_SUCCESS_URL = ORIGINAL_URL