stop raising errors and just bounce them to paypal anyway (bug 649022)

This commit is contained in:
Andy McKay 2011-04-13 11:20:58 -07:00
Родитель 9157bd3750
Коммит 76a53f3012
3 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from cStringIO import StringIO
from datetime import datetime
from decimal import Decimal
import json
@ -22,6 +23,7 @@ from amo.urlresolvers import reverse
from amo.tests.test_helpers import AbuseBase, AbuseDisabledBase
from addons.models import Addon, AddonUser, Charity
from files.models import File
from paypal.tests import other_error
from stats.models import Contribution
from translations.helpers import truncate
from translations.query import order_by_translation
@ -235,6 +237,13 @@ class TestContributeEmbedded(test_utils.TestCase):
'result_type=json'))
assert not json.loads(res.content)['paykey']
@patch('urllib2.OpenerDirector.open')
def test_paypal_other_error_json(self, opener, **kwargs):
opener.return_value = StringIO(other_error)
res = self.client.get('%s?%s' % (
reverse('addons.contribute', args=[self.addon.slug]),
'result_type=json'))
assert not json.loads(res.content)['paykey']
class TestContribute(test_utils.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592']

Просмотреть файл

@ -518,15 +518,14 @@ def embedded_contribute(request, addon):
paykey=paykey)
contrib.save()
assert settings.PAYPAL_FLOW_URL, 'settings.PAYPAL_FLOW_URL is not defined'
url = '%s?paykey=%s' % (settings.PAYPAL_FLOW_URL, paykey)
if request.GET.get('result_type') == 'json' or request.is_ajax():
# If there was an error getting the paykey, then JSON will
# not have a paykey and the JS can cope appropriately.
return http.HttpResponse(json.dumps({'url': url, 'paykey': paykey}),
content_type='application/json')
elif paykey is None:
# If there was an error getting the paykey, raise this.
raise
return http.HttpResponseRedirect(url)

Просмотреть файл

@ -21,6 +21,8 @@ auth_error = ('error(0).errorId=520003'
'&error(0).message=Authentication+failed.+API+'
'credentials+are+incorrect.')
other_error = ('error(0).errorId=520001'
'&error(0).message=Foo')
class TestPayPal(test_utils.TestCase):
def setUp(self):
@ -41,6 +43,11 @@ class TestPayPal(test_utils.TestCase):
opener.return_value = StringIO(good_response)
eq_(paypal.get_paykey(self.data), 'AP-9GD76073HJ780401K')
@mock.patch('urllib2.OpenerDirector.open')
def test_other_fails(self, opener):
opener.return_value = StringIO(other_error)
self.assertRaises(paypal.PaypalError, paypal.get_paykey, self.data)
def _test_no_mock(self):
# Remove _ and run if you'd like to try unmocked.
return paypal.get_paykey(self.data)