Skip to content

Commit 857865d

Browse files
tests added
1 parent 7a46016 commit 857865d

4 files changed

Lines changed: 168 additions & 4 deletions

File tree

hyperwallet/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
StatusTransition, # noqa
3333
TransferMethodConfiguration, # noqa
3434
Webhook, # noqa
35-
TransferRefunds # naqa
35+
TransferRefunds, # naqa
36+
HyperwalletVerificationDocument,
37+
HyperwalletVerificationDocumentReason,
38+
RejectReason,
3639
)
3740

3841
from .api import Api # noqa

hyperwallet/api.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
StatusTransition,
2424
TransferMethodConfiguration,
2525
Webhook,
26-
TransferRefunds
26+
TransferRefunds,
27+
HyperwalletVerificationDocument,
28+
HyperwalletVerificationDocumentReason,
29+
RejectReason
2730
)
2831

2932

@@ -2743,6 +2746,39 @@ def listWebhookNotifications(self,
27432746
def __buildUrl(self, *paths):
27442747
return '/'.join(s.strip('/') for s in paths)
27452748

2749+
def setDocumentAndReasonFromResponseHelper(self,
2750+
data=None):
2751+
'''
2752+
Helper to modify dictionary with Document and Reason classes
2753+
2754+
:param data:
2755+
A dictionary containing data for either a User
2756+
sample data:
2757+
jsonData={'data': ['{"documents": [{"type": "DRIVERS_LICENSE", "country": "US", "category": "IDENTIFICATION", "reasons": {"name": 0, "description": "STRING_VAL"}}]}']};
2758+
:returns:
2759+
A Dictionary with documents and reasons information
2760+
'''
2761+
2762+
if "documents" in data.keys():
2763+
documents = data["documents"]
2764+
listOfDocs = []
2765+
for dVal in documents:
2766+
if "reasons" in dVal.keys():
2767+
reasons = dVal["reasons"]
2768+
listOfReasons = []
2769+
for rVal in reasons:
2770+
if type(rVal["name"]) == str:
2771+
rVal["name"] = RejectReason[rVal["name"]]
2772+
else:
2773+
rVal["name"] = RejectReason(rVal["name"])
2774+
rVal = HyperwalletVerificationDocumentReason(rVal)
2775+
listOfReasons.append(rVal)
2776+
dVal["reasons"] = listOfReasons
2777+
dVal = HyperwalletVerificationDocument(dVal)
2778+
listOfDocs.append(dVal)
2779+
data["documents"] = listOfDocs
2780+
return data
2781+
27462782
def uploadDocumentsForUser(self,
27472783
userToken=None,
27482784
data=None,
@@ -2778,7 +2814,7 @@ def uploadDocumentsForUser(self,
27782814
data,
27792815
files
27802816
)
2781-
2817+
response = self.setDocumentAndReasonFromResponseHelper(response)
27822818
return User(response)
27832819

27842820
'''

hyperwallet/models.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
import json
4-
4+
from enum import Enum
55

66
class HyperwalletModel(object):
77
'''
@@ -129,6 +129,76 @@ def __repr__(self):
129129
token=self.token
130130
)
131131

132+
class HyperwalletVerificationDocument(HyperwalletModel):
133+
'''
134+
The HyperwalletVerificationDocument Model.
135+
136+
:param data:
137+
A dictionary containing the attributes for the HyperwalletVerificationDocument.
138+
'''
139+
140+
def __init__(self, data):
141+
'''
142+
Create a new HyperwalletVerificationDocument with the provided attributes.
143+
'''
144+
145+
super(HyperwalletVerificationDocument, self).__init__(data)
146+
147+
self.defaults = {
148+
'category': None,
149+
'type': None,
150+
'status': None,
151+
'country': None,
152+
'reasons': None,
153+
'createdOn': None,
154+
'uploadFiles': None,
155+
}
156+
157+
for (param, default) in self.defaults.items():
158+
setattr(self, param, data.get(param, default))
159+
160+
def __repr__(self):
161+
return "HyperwalletVerificationDocument({category}, {createdOn})".format(
162+
createdOn=self.createdOn, category=self.category
163+
)
164+
165+
class HyperwalletVerificationDocumentReason(HyperwalletModel):
166+
'''
167+
The HyperwalletVerificationDocumentReason Model.
168+
169+
:param data:
170+
A dictionary containing the attributes for the HyperwalletVerificationDocumentReason.
171+
'''
172+
173+
def __init__(self, data):
174+
'''
175+
Create a new HyperwalletVerificationDocumentReason with the provided attributes.
176+
'''
177+
178+
super(HyperwalletVerificationDocumentReason, self).__init__(data)
179+
180+
self.defaults = {
181+
'name': None,
182+
'description': None,
183+
}
184+
185+
for (param, default) in self.defaults.items():
186+
setattr(self, param, data.get(param, default))
187+
188+
def __repr__(self):
189+
return "HyperwalletVerificationDocumentReason({name}, {description})".format(
190+
name=self.name, description=self.description
191+
)
192+
193+
class RejectReason(Enum):
194+
DOCUMENT_EXPIRED = 0
195+
DOCUMENT_NOT_RELATED_TO_PROFILE = 1
196+
DOCUMENT_NOT_READABLE = 2
197+
DOCUMENT_NOT_DECISIVE = 3
198+
DOCUMENT_NOT_COMPLETE = 4
199+
DOCUMENT_CORRECTION_REQUIRED = 5
200+
DOCUMENT_NOT_VALID_WITH_NOTES = 6
201+
DOCUMENT_TYPE_NOT_VALID = 7
132202

133203
class AuthenticationToken(HyperwalletModel):
134204
'''

hyperwallet/tests/test_api.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ def setUp(self):
6464
'currencies': ['USD'],
6565
'type': 'INDIVIDUAL'
6666
}
67+
68+
self.uploadSuccessData = {
69+
'token': 'tkn-12345',
70+
"documents": [{
71+
"category": "IDENTIFICATION",
72+
"type": "DRIVERS_LICENSE",
73+
"country": "AL",
74+
"status": "NEW"
75+
}]
76+
}
77+
78+
self.uploadRejectionData = {
79+
'token': 'tkn-12345',
80+
"documents": [{
81+
"category": "IDENTIFICATION",
82+
"type": "DRIVERS_LICENSE",
83+
"country": "AL",
84+
"status": "INVALID",
85+
"reasons": [
86+
{
87+
"name": "DOCUMENT_CORRECTION_REQUIRED",
88+
"description": "Document requires correction"
89+
},
90+
{
91+
"name": "DOCUMENT_NOT_DECISIVE",
92+
"description": "Decision cannot be made based on document. Alternative document required"
93+
}
94+
],
95+
"createdOn": "2020-11-24T19:05:02"
96+
}]
97+
}
6798

6899
self.value = {
69100
'data': ['{"documents": [{"type": "DRIVERS_LICENSE", "country": "AL", "category": "IDENTIFICATION"}]}']
@@ -2331,6 +2362,30 @@ def test_uploadDocumentsForUser_success(self, mock_put):
23312362

23322363
self.assertTrue(response.token, self.data.get('token'))
23332364

2365+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
2366+
def test_uploadDocumentsForUserAndParse_success(self, mock_put):
2367+
2368+
mock_put.return_value = self.uploadSuccessData
2369+
response = self.api.uploadDocumentsForUser('token', self.value)
2370+
2371+
self.assertEqual(response.token, self.uploadSuccessData.get('token'))
2372+
self.assertEqual(response.documents[0].type, self.uploadSuccessData.get("documents")[0].type)
2373+
2374+
2375+
@mock.patch('hyperwallet.utils.ApiClient._makeRequest')
2376+
def test_uploadDocumentsForUserAndParseRejection_success(self, mock_put):
2377+
2378+
mock_put.return_value = self.uploadRejectionData
2379+
response = self.api.uploadDocumentsForUser('token', self.value)
2380+
2381+
# print(response.documents)
2382+
# print(response.documents[0].reasons[0].name.name)
2383+
2384+
self.assertEqual(response.token, self.uploadRejectionData.get('token'))
2385+
self.assertEqual(response.documents[0].reasons[0].name.name, self.uploadRejectionData.get("documents")[0].reasons[0].name.name)
2386+
self.assertEqual(response.documents[0].reasons[1].name.name, self.uploadRejectionData.get("documents")[0].reasons[1].name.name)
2387+
self.assertEqual(response.documents[0].type, self.uploadRejectionData.get("documents")[0].type)
2388+
23342389
'''
23352390
23362391
Transfer Refunds

0 commit comments

Comments
 (0)