Skip to content

Commit 3d44ccb

Browse files
author
Peter Joseph Olamit
authored
Merge pull request #10 from akreisman-epam/related-resources-in-exception
Add Related resources in HyperwalletAPIException
2 parents 7ea0687 + 4e01a04 commit 3d44ccb

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

hyperwallet/tests/test_client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def test_receive_valid_json_error_response(self, session_mock):
6262
data = {
6363
"errors": [{
6464
"message": "Houston, we have a problem",
65-
"code": "FORBIDDEN"
65+
"code": "FORBIDDEN",
66+
"relatedResources": ["trm-f3d38df1-adb7-4127-9858-e72ebe682a79",
67+
"trm-601b1401-4464-4f3f-97b3-09079ee7723b"]
6668
}]
6769
}
6870

@@ -79,6 +81,16 @@ def test_receive_valid_json_error_response(self, session_mock):
7981
'FORBIDDEN'
8082
)
8183

84+
self.assertEqual(
85+
exc.exception.message.get('errors')[0].get('relatedResources')[0],
86+
'trm-f3d38df1-adb7-4127-9858-e72ebe682a79'
87+
)
88+
89+
self.assertEqual(
90+
exc.exception.message.get('errors')[0].get('relatedResources')[1],
91+
'trm-601b1401-4464-4f3f-97b3-09079ee7723b'
92+
)
93+
8294
@mock.patch('requests.Session.request')
8395
def test_receive_valid_json_response(self, session_mock):
8496

hyperwallet/tests/test_encryption.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from jwcrypto.common import json_encode
1010
from hyperwallet.exceptions import HyperwalletException
1111
from hyperwallet.utils.encryption import Encryption
12-
from django.core.validators import URLValidator
13-
from django.core.exceptions import ValidationError
12+
from six.moves.urllib.parse import urlparse
1413

1514

1615
class EncryptionTest(unittest.TestCase):
@@ -158,19 +157,37 @@ def test_should_throw_exception_when_jws_signature_has_expired(self):
158157
self.assertEqual(exc.exception.message, 'JWS signature has expired, checked by [exp] JWS header')
159158

160159
def __getJwkKeySet(self, location):
161-
160+
'''
161+
Retrieves JWK key data from given location.
162+
163+
:param location:
164+
Location(can be a URL or path to file) of JWK key data. **REQUIRED**
165+
:returns:
166+
JWK key set found at given location.
167+
'''
162168
try:
163-
URLValidator()(location)
164-
except ValidationError:
169+
url = urlparse(location)
170+
if url.scheme and url.netloc and url.path:
171+
return requests.get(location).text
172+
raise HyperwalletException('Failed to parse url from string = ' + location)
173+
except Exception as e:
165174
if os.path.isfile(location):
166175
with open(location) as f:
167176
return f.read()
168177
else:
169178
raise HyperwalletException('Wrong JWK key set location path = ' + location)
170179

171-
return requests.get(location).text
172-
173180
def __findJwkKeyByAlgorithm(self, jwkKeySet, algorithm):
181+
'''
182+
Finds JWK key by given algorithm.
183+
184+
:param jwkKeySet:
185+
JSON representation of JWK key set. **REQUIRED**
186+
:param algorithm:
187+
Algorithm of the JWK key to be found in key set. **REQUIRED**
188+
:returns:
189+
JWK key with given algorithm.
190+
'''
174191

175192
try:
176193
keySet = json.loads(jwkKeySet)

0 commit comments

Comments
 (0)