Skip to content

Commit 89e5040

Browse files
authored
Bilal/entity attributes (#41)
* attributes added * updated entity & product objects * added tests * version bump
1 parent 3b4d9d1 commit 89e5040

5 files changed

Lines changed: 126 additions & 2 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import TypedDict, Optional, Literal, List
2+
3+
from method.resource import MethodResponse, Resource
4+
from method.configuration import Configuration
5+
from method.errors import ResourceError
6+
7+
8+
EntityAttributesResponseStatusLiterals = Literal[
9+
'completed',
10+
'in_progress',
11+
'pending',
12+
'failed'
13+
]
14+
15+
16+
CreditHealthAttributeRating = Literal[
17+
'excellent',
18+
'good',
19+
'fair',
20+
'needs_work'
21+
]
22+
23+
24+
class CreditHealthAttribute(TypedDict):
25+
value: int
26+
rating: CreditHealthAttributeRating
27+
28+
29+
class EntityAttributesType(TypedDict):
30+
credit_health_credit_card_usage: CreditHealthAttribute
31+
credit_health_derogatory_marks: CreditHealthAttribute
32+
credit_health_hard_inquiries: CreditHealthAttribute
33+
credit_health_total_accounts: CreditHealthAttribute
34+
credit_health_credit_age: CreditHealthAttribute
35+
credit_health_payment_history: CreditHealthAttribute
36+
37+
38+
class EntityAttributes(TypedDict):
39+
id: str
40+
entity_id: str
41+
status: EntityAttributesResponseStatusLiterals
42+
attributes: Optional[List[EntityAttributesType]]
43+
error: Optional[ResourceError]
44+
created_at: str
45+
updated_at: str
46+
47+
48+
class EntityAttributesResource(Resource):
49+
def __init__(self, config: Configuration):
50+
super(EntityAttributesResource, self).__init__(config.add_path('attributes'))
51+
52+
def retrieve(self, attr_id: str) -> MethodResponse[EntityAttributes]:
53+
return super(EntityAttributesResource, self)._get_with_id(attr_id)
54+
55+
def create(self) -> MethodResponse[EntityAttributes]:
56+
return super(EntityAttributesResource, self)._create({})

method/resources/Entities/Entity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from method.resource import MethodResponse, Resource, RequestOpts, ResourceListOpts
44
from method.configuration import Configuration
55
from method.errors import ResourceError
6+
from method.resources.Entities.Attributes import EntityAttributesResource
67
from method.resources.Entities.Types import EntityTypesLiterals, EntityCapabilitiesLiterals, EntityStatusesLiterals, \
78
CreditReportBureausLiterals, EntityIndividual, EntityCorporation, EntityAddress
89
from method.resources.Entities.Connect import EntityConnectResource
@@ -105,6 +106,7 @@ class Entity(TypedDict):
105106

106107

107108
class EntitySubResources:
109+
attributes: EntityAttributesResource
108110
connect: EntityConnectResource
109111
credit_scores: EntityCreditScoresResource
110112
identities: EntityIdentityResource
@@ -114,6 +116,7 @@ class EntitySubResources:
114116
verification_sessions: EntityVerificationSessionResource
115117

116118
def __init__(self, _id: str, config: Configuration):
119+
self.attributes = EntityAttributesResource(config.add_path(_id))
117120
self.connect = EntityConnectResource(config.add_path(_id))
118121
self.credit_scores = EntityCreditScoresResource(config.add_path(_id))
119122
self.identities = EntityIdentityResource(config.add_path(_id))

method/resources/Entities/Products.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class EntityProduct(TypedDict):
2424

2525

2626
class EntityProductListResponse(TypedDict):
27+
attribute: Optional[EntityProduct]
2728
connect: Optional[EntityProduct]
2829
credit_score: Optional[EntityProduct]
2930
identity: Optional[EntityProduct]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='method-python',
5-
version='1.1.0',
5+
version='1.1.1',
66
description='Python library for the Method API',
77
long_description='Python library for the Method API',
88
long_description_content_type='text/x-rst',

test/resources/Entity_test.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from method.resources.Entities.Attributes import EntityAttributes
23
import pytest
34
from method import Method
45
from dotenv import load_dotenv
@@ -26,6 +27,7 @@
2627
entities_account_list_response = None
2728
entities_account_ids = None
2829
entities_create_credit_score_response = None
30+
entities_create_attribute_response = None
2931
entities_create_idenitity_response = None
3032
entities_retrieve_product_list_response = None
3133
entities_create_connect_subscription_response = None
@@ -86,6 +88,7 @@ def test_create_entity():
8688
},
8789
'connect': None,
8890
'credit_score': None,
91+
'attribute': None,
8992
'products': [],
9093
'restricted_products': entities_create_response['restricted_products'],
9194
'subscriptions': [],
@@ -148,6 +151,7 @@ def test_retrieve_entity():
148151
},
149152
'connect': None,
150153
'credit_score': None,
154+
'attribute': None,
151155
'products': [],
152156
'restricted_products': entities_retrieve_response['restricted_products'],
153157
'subscriptions': [],
@@ -218,8 +222,9 @@ def test_update_entity():
218222
},
219223
'connect': None,
220224
'credit_score': None,
225+
'attribute': None,
221226
'products': [ 'identity' ],
222-
'restricted_products': [ 'connect', 'credit_score' ].sort(),
227+
'restricted_products': entities_update_response['restricted_products'],
223228
'subscriptions': [],
224229
'available_subscriptions': [],
225230
'restricted_subscriptions': [ 'connect', 'credit_score' ].sort(),
@@ -378,6 +383,44 @@ def get_credit_score():
378383

379384
assert credit_score_retrieve_response == expect_results
380385

386+
# ENTITY ATTRIBUTE TESTS
387+
388+
def test_create_entity_attribute():
389+
global entities_create_attribute_response
390+
entities_create_attribute_response = method.entities(entities_create_response['id']).attributes.create()
391+
392+
expect_results: EntityAttributes = {
393+
'id': entities_create_attribute_response['id'],
394+
'entity_id': entities_create_response['id'],
395+
'status': 'completed',
396+
'attributes': entities_create_attribute_response.attributes,
397+
'error': None,
398+
'created_at': entities_create_attribute_response['created_at'],
399+
'updated_at': entities_create_attribute_response['updated_at']
400+
}
401+
402+
assert entities_create_attribute_response == expect_results
403+
404+
@pytest.mark.asyncio
405+
async def test_retrieve_entity_attribute():
406+
def get_attribute():
407+
return method.entities(entities_create_response['id']).attributes.retrieve(entities_create_attribute_response['id'])
408+
409+
attribute_retrieve_response = await await_results(get_attribute)
410+
411+
expect_results: EntityAttributes = {
412+
'id': attribute_retrieve_response['id'],
413+
'entity_id': entities_create_response['id'],
414+
'status': 'completed',
415+
'attributes': attribute_retrieve_response.attributes,
416+
'error': None,
417+
'created_at': attribute_retrieve_response['created_at'],
418+
'updated_at': attribute_retrieve_response['updated_at']
419+
}
420+
421+
assert attribute_retrieve_response == expect_results
422+
423+
381424
# ENTITY IDENTITY TESTS
382425

383426
def test_create_entity_identity():
@@ -517,6 +560,16 @@ def test_retrieve_entity_product_list():
517560
'is_subscribable': False,
518561
'created_at': entities_retrieve_product_list_response.get('identity', {}).get('created_at', ''),
519562
'updated_at': entities_retrieve_product_list_response.get('identity', {}).get('updated_at', ''),
563+
},
564+
'attribute': {
565+
'id': entities_retrieve_product_list_response.get('attribute', {}).get('id', ''),
566+
'name': 'attribute',
567+
'status': 'available',
568+
'status_error': None,
569+
'latest_request_id': entities_retrieve_product_list_response.get('attribute', {}).get('latest_request_id', None),
570+
'is_subscribable': False,
571+
'created_at': entities_retrieve_product_list_response.get('attribute', {}).get('created_at', ''),
572+
'updated_at': entities_retrieve_product_list_response.get('attribute', {}).get('updated_at', ''),
520573
}
521574
}
522575

@@ -554,6 +607,17 @@ def test_retrieve_entity_product():
554607
'updated_at': entity_credit_score_product_response['updated_at']
555608
}
556609

610+
expect_attribute_results: EntityProduct = {
611+
'id': entities_retrieve_product_list_response.get('attribute', {}).get('id', ''),
612+
'name': 'attribute',
613+
'status': 'available',
614+
'status_error': None,
615+
'latest_request_id': entities_retrieve_product_list_response.get('attribute', {}).get('latest_request_id', None),
616+
'is_subscribable': False,
617+
'created_at': entities_retrieve_product_list_response.get('attribute', {}).get('created_at', ''),
618+
'updated_at': entities_retrieve_product_list_response.get('attribute', {}).get('updated_at', ''),
619+
}
620+
557621
expect_identity_results: EntityProduct = {
558622
'id': entity_identity_product_id,
559623
'name': 'identity',

0 commit comments

Comments
 (0)