Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.

Commit 88e9925

Browse files
committed
Add support for Python3.7
Upgrade HTTPretty to version that supports Python3.7 Upgrade Recurly to version that supports Python3.7 Change the way timeout is simulated - return error instead of raising ssl.SSLError
1 parent 4899d45 commit 88e9925

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

mocurly/core.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
Exposes the main mocurly class which is the gateway into setting up the mocurly
44
context.
55
"""
6-
import recurly
7-
import re
8-
import ssl
96
import functools
10-
from six.moves.urllib.parse import urlparse, parse_qs, unquote
7+
import re
8+
9+
import recurly
1110
from httpretty import HTTPretty
11+
from six.moves.urllib.parse import parse_qs, unquote, urlparse
1212

13-
from .utils import deserialize
14-
from .errors import ResponseError
1513
from .backend import clear_backends
14+
from .errors import ResponseError
15+
from .utils import deserialize
1616

1717

1818
class mocurly(object):
@@ -260,11 +260,12 @@ def __init__(self, mocurly_instance):
260260

261261
def __call__(self, func):
262262
def wrapped(request, uri, headers, **kwargs):
263+
error_response_body = 'The read operation timed out'
263264
# If we want to timeout the request, timeout, but only if we aren't
264265
# going to allow the POST
265266
if (self.mocurly_instance.should_timeout(request) and
266267
not self.mocurly_instance.should_timeout_successful_post(request)):
267-
raise ssl.SSLError('The read operation timed out')
268+
return 502, headers, error_response_body
268269

269270
try:
270271
return_val = func(request, uri, headers, **kwargs)
@@ -275,7 +276,7 @@ def wrapped(request, uri, headers, **kwargs):
275276
return exc.status_code, headers, exc.response_body
276277

277278
if self.mocurly_instance.should_timeout_successful_post(request):
278-
raise ssl.SSLError('The read operation timed out')
279+
return 502, headers, error_response_body
279280

280281
return return_val
281282
return wrapped

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
httpretty>=0.8,<=0.8.10
2-
recurly>=2.2.23
1+
httpretty>=0.9.4
2+
recurly>=2.9.0,<3.0.0
33
jinja2
44
six
55
pytz
66
python-dateutil
7+
iso8601

tests/test_core.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import unittest
2-
import ssl
3-
import recurly
4-
recurly.API_KEY = 'blah'
52

63
import mocurly
74
import mocurly.backend
5+
import recurly
6+
7+
recurly.API_KEY = 'blah'
8+
89

910
class TestCore(unittest.TestCase):
1011
def setUp(self):
@@ -58,7 +59,7 @@ def test_timeout(self):
5859
mocurly_.start_timeout()
5960

6061
self.assertFalse(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
61-
self.assertRaises(ssl.SSLError, recurly.Account(**self.base_account_data).save)
62+
self.assertRaises(recurly.errors.BadGatewayError, recurly.Account(**self.base_account_data).save)
6263
self.assertFalse(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
6364

6465
mocurly_.stop_timeout()
@@ -76,7 +77,7 @@ def test_timeout_successful_post(self):
7677
mocurly_.start_timeout_successful_post()
7778

7879
self.assertFalse(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
79-
self.assertRaises(ssl.SSLError, recurly.Account(**self.base_account_data).save)
80+
self.assertRaises(recurly.errors.BadGatewayError, recurly.Account(**self.base_account_data).save)
8081
self.assertTrue(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
8182

8283
mocurly_.stop_timeout_successful_post()
@@ -101,7 +102,7 @@ def timeout_filter(request):
101102
self.assertFalse(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
102103
recurly.Account(**self.base_account_data).save()
103104
self.assertTrue(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
104-
self.assertRaises(ssl.SSLError, recurly.Account.get, self.base_account_data['account_code'])
105+
self.assertRaises(recurly.errors.BadGatewayError, recurly.Account.get, self.base_account_data['account_code'])
105106

106107
mocurly_.stop_timeout()
107108

@@ -126,7 +127,7 @@ def timeout_filter(request):
126127

127128
self.assertEqual(len(mocurly.backend.transactions_backend.datastore), 0)
128129
new_transaction = recurly.Transaction(account=new_account, amount_in_cents=20, currency='USD')
129-
self.assertRaises(ssl.SSLError, new_transaction.save)
130+
self.assertRaises(recurly.errors.BadGatewayError, new_transaction.save)
130131
self.assertEqual(len(mocurly.backend.transactions_backend.datastore), 1)
131132

132133
mocurly_.stop_timeout_successful_post()

0 commit comments

Comments
 (0)