Skip to content

Commit ab447b5

Browse files
authored
Merge pull request #19 from hyperwallet/fix-tests-for-python3
Fix tests for python3
2 parents ecfc24a + 0f177e1 commit ab447b5

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

hyperwallet/tests/test_encryption.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_should_successfully_encrypt_and_decrypt_text_message(self):
2424
testMessage = 'Message for test'
2525
encryptedMessage = encryption.encrypt(testMessage)
2626
decryptedMessage = encryption.decrypt(encryptedMessage)
27-
self.assertEqual(decryptedMessage, testMessage)
27+
self.assertEqual(decryptedMessage.decode(), testMessage)
2828

2929
def test_should_fail_decryption_when_wrong_private_key_is_used(self):
3030

@@ -41,7 +41,7 @@ def test_should_fail_decryption_when_wrong_private_key_is_used(self):
4141
with self.assertRaises(HyperwalletException) as exc:
4242
encryption2.decrypt(encryptedMessage)
4343

44-
self.assertEqual(exc.exception.message, 'No recipient matched the provided key["Failed: [ValueError(\'Decryption failed.\',)]"]')
44+
self.assertTrue(str(exc.exception).startswith('No recipient matched the provided key["Failed: [ValueError(\'Decryption failed.\''))
4545

4646
def test_should_fail_signature_verification_when_wrong_public_key_is_used(self):
4747

@@ -58,7 +58,7 @@ def test_should_fail_signature_verification_when_wrong_public_key_is_used(self):
5858
with self.assertRaises(HyperwalletException) as exc:
5959
encryption2.decrypt(encryptedMessage)
6060

61-
self.assertEqual(exc.exception.message, 'Signature verification failed.')
61+
self.assertEqual(str(exc.exception), 'Signature verification failed.')
6262

6363
def test_should_throw_exception_when_wrong_jwk_key_set_location_is_given(self):
6464

@@ -212,7 +212,9 @@ def test_should_throw_exception_when_jwk_set_file_retrieved_from_url_is_invalid(
212212
with self.assertRaises(TypeError) as exc:
213213
encryption.encrypt('testMessage')
214214

215-
self.assertEqual(exc.exception.message, 'expected string or buffer')
215+
errorMessages = ['expected string or buffer', 'the JSON object must be str, bytes or bytearray, not MagicMock']
216+
217+
self.assertTrue(str(exc.exception) in errorMessages)
216218

217219
def __findJwkKeyByAlgorithm(self, jwkKeySet, algorithm):
218220
'''

hyperwallet/utils/encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def decrypt(self, body):
9898
try:
9999
jweToken.deserialize(body, key=privateKeyToDecrypt)
100100
except Exception as e:
101-
raise HyperwalletException(e.message)
101+
raise HyperwalletException(str(e))
102102
payload = jweToken.payload
103103

104104
self.checkJwsExpiration(payload)
@@ -107,7 +107,7 @@ def decrypt(self, body):
107107
try:
108108
return jws.verify(payload, json.dumps(jwkCheckSignKey), algorithms=self.signAlgorithm)
109109
except Exception as e:
110-
raise HyperwalletException(e.message)
110+
raise HyperwalletException(str(e))
111111

112112
def __getJwkKeySet(self, location):
113113
'''

0 commit comments

Comments
 (0)