Skip to content

Commit 7ad5e3b

Browse files
committed
http exception test
1 parent 1ae7feb commit 7ad5e3b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

maxipago/managers/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, maxid, api_key, api_version, sandbox):
2525
def request(self, xml_data, api_type=None):
2626
uri = self.get_uri(api_type)
2727
response = requests.post(url=uri, data=xml_data, headers={'content-type': 'text/xml'})
28+
2829
if not str(response.status_code).startswith('2'):
2930
raise HttpErrorException(u'Error %s: %s' % (response.status_code, response.reason))
3031
return response

maxipago/resources/payment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def process(self):
1414

1515
tree = etree.parse(StringIO(self.data))
1616
error_code = tree.find('errorCode')
17-
if error_code is not None and error_code != '0':
17+
if error_code is not None and error_code.text != '0':
1818
error_message = tree.find('errorMsg').text
1919
raise PaymentException(message=error_message)
2020

tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,17 @@ def test_payment_direct_with_token_decline(self):
323323
self.assertFalse(response.authorized)
324324
self.assertFalse(response.captured)
325325

326+
def test_http_exception(self):
327+
CUSTOMER_ID = randint(1, 100000)
328+
customer_manager = self.maxipago.customer
329+
customer_manager.uri_api = 'https://testapi.maxipago.net/UniversalAPI/WrongUri'
330+
with self.assertRaises(exceptions.HttpErrorException):
331+
customer_manager.add(
332+
customer_id=CUSTOMER_ID,
333+
first_name='Fulano',
334+
last_name='de Tal',
335+
)
336+
326337

327338
if __name__ == '__main__':
328339
unittest.main()

0 commit comments

Comments
 (0)