remove socket_timeout that didn't actually do anything, cheers @kumar

This commit is contained in:
Andy McKay 2012-05-25 17:41:26 +01:00
Родитель 8b38d02066
Коммит 8f4264ef5c
2 изменённых файлов: 6 добавлений и 19 удалений

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

@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-
import contextlib
from datetime import date
from decimal import Decimal, InvalidOperation
import socket
import urllib
import urlparse
import re
from django.conf import settings
from django.utils.http import urlencode, urlquote
from django.utils.http import urlquote
import commonware.log
from django_statsd.clients import statsd
@ -542,24 +540,13 @@ def check_paypal_id(name):
d['user'] = settings.PAYPAL_EMBEDDED_AUTH['USER']
d['pwd'] = settings.PAYPAL_EMBEDDED_AUTH['PASSWORD']
d['signature'] = settings.PAYPAL_EMBEDDED_AUTH['SIGNATURE']
with socket_timeout(10):
r = urllib.urlopen(settings.PAYPAL_API_URL, urlencode(d))
response = dict(urlparse.parse_qsl(r.read()))
r = requests.get(settings.PAYPAL_API_URL, params=d, timeout=10)
response = dict(urlparse.parse_qsl(r.text))
valid = response['ACK'] == 'Success'
msg = None if valid else response['L_LONGMESSAGE0']
return valid, msg
@contextlib.contextmanager
def socket_timeout(timeout):
"""Context manager to temporarily set the default socket timeout."""
old = socket.getdefaulttimeout()
try:
yield
finally:
socket.setdefaulttimeout(old)
def paypal_log_cef(request, addon, uuid, msg, caps, longer):
log_cef('Paypal %s' % msg, 5, request,
username=request.amo_user,

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

@ -281,9 +281,9 @@ class TestPurchase(amo.tests.TestCase):
eq_(paypal.check_purchase('some-paykey'), False)
@mock.patch('paypal.urllib.urlopen')
def test_check_paypal_id(urlopen_mock):
urlopen_mock.return_value = StringIO('ACK=Success')
@mock.patch('paypal.requests.get')
def test_check_paypal_id(get):
get.return_value.text = 'ACK=Success'
val = paypal.check_paypal_id(u'\u30d5\u30a9\u30af\u3059\u3051')
eq_(val, (True, None))