def test_do_expresscheckout_redirects_if_no_token_or_payerid(self):
        """if GET['token'] or GET['PayerID'] are missing as querystring
        parameters then do_express_checkout_redirects to payment"""

        # send the view nothing and it redirects

        request = self.rf.get( reverse('paypalexpresscheckout:return'),{
            'METHOD': 'DoExpressCheckoutPayment'},)
        request.session['cccheckout'] = self.checkout
        r = do_express_checkout(request)
        self.assertEqual(reverse('cccheckout:payment'), r['Location'])
        # doesn't matter if we send one
        request = self.rf.get( reverse('paypalexpresscheckout:return'),{
            'METHOD': 'DoExpressCheckoutPayment',
            'PayerID': 'testpayerid'})
        request.session['cccheckout'] = self.checkout
        r = do_express_checkout(request)
        self.assertEqual(reverse('cccheckout:payment'), r['Location'])
        # or the other
        request = self.rf.get( reverse('paypalexpresscheckout:return'),{
            'METHOD': 'DoExpressCheckoutPayment',
            'token': 'testtoken'})
        request.session['cccheckout'] = self.checkout
        r = do_express_checkout(request)
        self.assertEqual(reverse('cccheckout:payment'), r['Location'])
        # we need both...
        request = self.rf.get( reverse('paypalexpresscheckout:return'),{
            'METHOD': 'DoExpressCheckoutPayment',
            'token': 'testtoken',
            'PayerID': 'testpayerid'})
        request.session['cccheckout'] = self.checkout
        r = do_express_checkout(request)
        self.assertEqual(reverse('cccheckout:complete'), r['Location'])
 def test_checkout_paid(self):
     """Ensure that the checkout is marked as paid"""
     # checkout is not paid
     self.assertFalse(self.checkout.paid)
     # make a request and call the do_express_checkout
     request = self.rf.get(reverse('paypalexpresscheckout:return'), {
         'METHOD': 'DoExpressCheckoutPayment',
         'token': 'testtoken',
         'PayerID': 'testpayerid'})
     request.session['cccheckout'] = self.checkout
     r = do_express_checkout(request)
     # we were redirected to complete
     self.assertEqual(r['Location'], reverse('cccheckout:complete'))
     # checkout is complete
     self.assertTrue(self.checkout.paid)
 def test_checkout_paid_custom_complete(self):
     """Ensure that the checkout is marked as paid"""
     # specify a custome location and reload settings
     settings.CCCHECKOUT_SUCCESS_URL = '/'
     reload(c_settings)
     # make a request and call the do_express_checkout
     request = self.rf.get( reverse('paypalexpresscheckout:return'),{
         'METHOD': 'DoExpressCheckoutPayment',
         'token': 'testtoken',
         'PayerID': 'testpayerid'})
     request.session['cccheckout'] = self.checkout
     r = do_express_checkout(request)
     # we were redirected to complete
     self.assertEqual(r['Location'], '/')
     # checkout is complete
     del(settings.CCCHECKOUT_SUCCESS_URL)
 def test_checkout_paid_signal_sent(self):
     """Ensure that the checkout is marked as paid"""
     # define a listener
     def test_listener(sender, request, **kwargs):
         request.session['mynameis'] = 'slimshady'
     # connect it
     checkout_paid.connect(test_listener)
     # checkout is not paid
     self.assertFalse(self.checkout.paid)
     # make a request and call the do_express_checkout
     request = self.rf.get( reverse('paypalexpresscheckout:return'),{
         'METHOD': 'DoExpressCheckoutPayment',
         'token': 'testtoken',
         'PayerID': 'testpayerid'})
     request.session['cccheckout'] = self.checkout
     request.session['mynameis'] = 'eminem'
     # his name is eminem
     self.assertEqual('eminem', request.session['mynameis'])
     r = do_express_checkout(request)
     # his name is eminem
     self.assertEqual('slimshady', request.session['mynameis'])
 def test_doexpresscheckout_fail(self):
     """ensure setExpressCheckout fails as expected when everything goes
     according to plan and a payment is not succesful"""
     # save the setting for later
     ORIGINAL_OUTCOME = settings.PAYPAL_OUTCOME
     settings.PAYPAL_OUTCOME = 'FAIL'
     reload(c_settings)
     # make the request for the view
     request = self.rf.get( reverse('paypalexpresscheckout:return'),{
         'METHOD': 'DoExpressCheckoutPayment',
         'token': 'testtoken',
         'PayerID': 'testpayerid'})
     request.session['cccheckout'] = self.checkout
     r = do_express_checkout(request)
     # redirected back to payment
     self.assertEqual(reverse('cccheckout:payment'), r['Location'])
     # checkout is not paid
     self.assertFalse(self.checkout.paid)
     # set it back
     settings.PAYPAL_OUTCOME = ORIGINAL_OUTCOME
     reload(c_settings)