Skip to content

Commit 21f0d9b

Browse files
authored
UD-15305 New Thread Application Fields (#301)
* feat: thread application updates and missing fields related functionality * version bump to 1.2.0 * fix: disable atm tests
1 parent 1fb741a commit 21f0d9b

8 files changed

Lines changed: 321 additions & 53 deletions

File tree

e2e_tests/application_test.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,60 @@ def test_update_thread_beneficial_owner():
786786
else:
787787
print("Test failed due to an error during thread application creation.")
788788

789+
790+
def test_get_missing_fields():
791+
app = create_individual_application()
792+
response = client.applications.get_missing_fields(app.data.id)
793+
assert response.data.type in ["individualApplicationMissingFields", "businessApplicationMissingFields"]
794+
assert "missingFields" in response.data.attributes
795+
796+
797+
def test_get_missing_fields_business():
798+
app = create_business_application()
799+
if app is not None:
800+
response = client.applications.get_missing_fields(app.data.id)
801+
assert response.data.type in ["individualApplicationMissingFields", "businessApplicationMissingFields"]
802+
assert "missingFields" in response.data.attributes
803+
else:
804+
print("Test failed due to an error during business application creation.")
805+
806+
807+
def test_missing_fields_dto_from_json():
808+
data = {
809+
"type": "individualApplicationMissingFields",
810+
"attributes": {
811+
"missingFields": [
812+
{
813+
"fieldName": "usNexus",
814+
"description": "usNexus is required"
815+
},
816+
{
817+
"fieldName": "transactionVolume",
818+
"description": "transactionVolume is required"
819+
}
820+
]
821+
}
822+
}
823+
824+
dto = IndividualApplicationMissingFieldsDTO.from_json_api(None, data.get("type"), data.get("attributes"), None)
825+
826+
assert dto.type == "individualApplicationMissingFields"
827+
assert len(dto.attributes["missingFields"]) == 2
828+
assert dto.attributes["missingFields"][0].field_name == "usNexus"
829+
assert dto.attributes["missingFields"][0].description == "usNexus is required"
830+
assert dto.attributes["missingFields"][1].field_name == "transactionVolume"
831+
832+
833+
def test_business_missing_fields_dto_from_json():
834+
data = {
835+
"type": "businessApplicationMissingFields",
836+
"attributes": {
837+
"missingFields": []
838+
}
839+
}
840+
841+
dto = BusinessApplicationMissingFieldsDTO.from_json_api(None, data.get("type"), data.get("attributes"), None)
842+
843+
assert dto.type == "businessApplicationMissingFields"
844+
assert len(dto.attributes["missingFields"]) == 0
845+

e2e_tests/atm_location_test.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import os
2-
import unittest
3-
from unit import Unit
4-
from unit.models.atm_location import *
1+
# NOTE: ATM location tests are temporarily disabled due to vendor issues
52

6-
token = os.environ.get('TOKEN')
7-
client = Unit("https://api.s.unit.sh", token)
3+
# import os
4+
# import unittest
5+
# from unit import Unit
6+
# from unit.models.atm_location import *
87

9-
def test_get_atm_location_by_coordinates():
10-
request = GetAtmLocationParams(30, Coordinates(-73.93041, 42.79894))
11-
response = client.atmLocations.get(request)
12-
for atm_location in response.data:
13-
assert atm_location.type == "atmLocation"
8+
# token = os.environ.get('TOKEN')
9+
# client = Unit("https://api.s.unit.sh", token)
1410

15-
def test_get_atm_location_by_postal_code():
16-
request = GetAtmLocationParams(5, postal_code='12300')
17-
response = client.atmLocations.get(request)
18-
for atm_location in response.data:
19-
assert atm_location.type == "atmLocation"
11+
# def test_get_atm_location_by_coordinates():
12+
# request = GetAtmLocationParams(30, Coordinates(-73.93041, 42.79894))
13+
# response = client.atmLocations.get(request)
14+
# for atm_location in response.data:
15+
# assert atm_location.type == "atmLocation"
2016

21-
def test_get_atm_location_by_address():
22-
request = GetAtmLocationParams(5, address=Address("1240 EASTERN AVE", "SCHENECTADY", "NY", "", "US"))
23-
response = client.atmLocations.get(request)
24-
for atm_location in response.data:
25-
assert atm_location.type == "atmLocation"
17+
# def test_get_atm_location_by_postal_code():
18+
# request = GetAtmLocationParams(5, postal_code='12300')
19+
# response = client.atmLocations.get(request)
20+
# for atm_location in response.data:
21+
# assert atm_location.type == "atmLocation"
22+
23+
# def test_get_atm_location_by_address():
24+
# request = GetAtmLocationParams(5, address=Address("1240 EASTERN AVE", "SCHENECTADY", "NY", "", "US"))
25+
# response = client.atmLocations.get(request)
26+
# for atm_location in response.data:
27+
# assert atm_location.type == "atmLocation"
2628

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name='unit-python-sdk',
55
packages=['unit', 'unit.api', 'unit.models', 'unit.utils'],
6-
version="1.1.1",
6+
version="1.2.0",
77
license='Mozilla Public License 2.0',
88
description='This library provides a python wrapper to http://unit.co API. See https://docs.unit.co/',
99
author='unit.co',

unit/api/application_resource.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,20 @@ def cancel(self, request: CancelApplicationRequest) -> Union[UnitResponse[Applic
115115
return UnitResponse[ApplicationDTO](DtoDecoder.decode(data), DtoDecoder.decode(included))
116116
else:
117117
return UnitError.from_json_api(response.json())
118+
119+
def upgrade_to_thread_application(self, request: UpgradeToThreadApplicationRequest) -> Union[UnitResponse[ThreadApplicationDTO], UnitError]:
120+
payload = request.to_json_api()
121+
response = super().patch(f"{self.resource}/{request.application_id}", payload)
122+
if super().is_20x(response.status_code):
123+
data = response.json().get("data")
124+
return UnitResponse[ThreadApplicationDTO](DtoDecoder.decode(data), None)
125+
else:
126+
return UnitError.from_json_api(response.json())
127+
128+
def get_missing_fields(self, application_id: str) -> Union[UnitResponse[ApplicationMissingFieldsDTO], UnitError]:
129+
response = super().get(f"{self.resource}/{application_id}/missing-fields")
130+
if super().is_20x(response.status_code):
131+
data = response.json().get("data")
132+
return UnitResponse[ApplicationMissingFieldsDTO](DtoDecoder.decode(data), None)
133+
else:
134+
return UnitError.from_json_api(response.json())

unit/models/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ def from_json_api(_id, _type, attributes, relationships):
347347
class ThreadBeneficialOwner(UnitDTO):
348348
def __init__(self, status: Optional[Status], full_name: FullName, ssn: Optional[str],
349349
passport: Optional[str], nationality: Optional[str], date_of_birth: date,
350-
address: Address, phone: Phone, email: str):
350+
address: Address, phone: Phone, email: str, percentage: Optional[int] = None,
351+
id_theft_score: Optional[int] = None):
351352
self.status = status
352353
self.full_name = full_name
353354
self.ssn = ssn
@@ -357,6 +358,8 @@ def __init__(self, status: Optional[Status], full_name: FullName, ssn: Optional[
357358
self.address = address
358359
self.phone = phone
359360
self.email = email
361+
self.percentage = percentage
362+
self.id_theft_score = id_theft_score
360363

361364
@staticmethod
362365
def create(data: Dict):
@@ -369,7 +372,9 @@ def create(data: Dict):
369372
data.get("dateOfBirth"),
370373
Address.from_json_api(data.get("address")),
371374
Phone.from_json_api(data.get("phone")),
372-
data.get("email"))
375+
data.get("email"),
376+
data.get("percentage"),
377+
data.get("idTheftScore"))
373378

374379
@staticmethod
375380
def from_json_api(l: Union[List, Dict]):

0 commit comments

Comments
 (0)