Skip to content

Commit 3eed2c6

Browse files
authored
Adding name to balance entries model (#72)
* adding name to balance entries model * add type * remove transaction_uri * add cassettess and tests for balance entries * fix covergae * removed unecesarry parts from cassettes * update cuenca-validations version * update cuenca-validations version to 0.6.4 * update version
1 parent b26d61d commit 3eed2c6

File tree

7 files changed

+160
-78
lines changed

7 files changed

+160
-78
lines changed
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from typing import ClassVar
1+
from typing import ClassVar, cast
22

3+
from cuenca_validations.types import EntryType, RelatedTransaction
34
from pydantic.dataclasses import dataclass
45

6+
from cuenca import resources
7+
58
from .base import Queryable, Retrievable
69
from .resources import retrieve_uri
710

@@ -12,9 +15,13 @@ class BalanceEntry(Retrievable, Queryable):
1215

1316
amount: int # negative in the case of a debit
1417
descriptor: str
18+
name: str
1519
rolling_balance: int
16-
transaction_uri: str
20+
type: EntryType
21+
related_transaction_uri: RelatedTransaction
1722

1823
@property # type: ignore
19-
def transaction(self):
20-
return retrieve_uri(self.transaction_uri)
24+
def related_transaction(self):
25+
rt = self.related_transaction_uri
26+
resource = getattr(resources, rt.get_model())
27+
return cast(resource, retrieve_uri(rt)) if resource else None

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.3.6'
1+
__version__ = '0.3.7'
22
CLIENT_VERSION = __version__
33
API_VERSION = '2020-03-19'

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
requests==2.24.0
2-
cuenca-validations==0.6.2
2+
cuenca-validations==0.6.4
33
dataclasses>=0.7;python_version<"3.7"
44
aws-requests-auth==0.4.3
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- cuenca-python/0.3.6
15+
X-Cuenca-Api-Version:
16+
- '2020-03-19'
17+
x-amz-content-sha256:
18+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
19+
x-amz-date:
20+
- 20201019T180526Z
21+
method: GET
22+
uri: https://sandbox.cuenca.com/balance_entries/TV02
23+
response:
24+
body:
25+
string: '{"id":"TV02","created_at":"2020-10-15T22:27:53.786000","user_id":"US4CUUYCzSBj8494zjbmF7Np","name":"Cargo
26+
a cuenta","amount":1000,"descriptor":"Comisi\u00f3n por dep\u00f3sito de efectivo","rolling_balance":176000,"type":"credit","related_transaction_uri":"/commissions/CO3FI2mQsprTNhoik7Ni1VQF"}'
27+
headers:
28+
Connection:
29+
- keep-alive
30+
Content-Length:
31+
- '316'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Mon, 19 Oct 2020 18:05:27 GMT
36+
Via:
37+
- 1.1 f70a58ce7ab3276e2d4987075b643aea.cloudfront.net (CloudFront)
38+
X-Amz-Cf-Id:
39+
- b5skJUNS0zQrIBkcgS1s25ms89NQ-xsO8lbvcKvdivKE3_YpHNrLgw==
40+
X-Amz-Cf-Pop:
41+
- LAX50-C2
42+
X-Amzn-Trace-Id:
43+
- Root=1-5f8dd567-114ed07a0f869fb17dd7e8ea;Sampled=0
44+
X-Cache:
45+
- Miss from cloudfront
46+
x-amz-apigw-id:
47+
- Uq5INFTbIAMFZYQ=
48+
x-amzn-RequestId:
49+
- 6f80aa4f-6410-4042-9267-0bc9ecae7711
50+
status:
51+
code: 200
52+
message: OK
53+
- request:
54+
body: null
55+
headers:
56+
Accept:
57+
- '*/*'
58+
Accept-Encoding:
59+
- gzip, deflate
60+
Authorization:
61+
- DUMMY
62+
Connection:
63+
- keep-alive
64+
User-Agent:
65+
- cuenca-python/0.3.6
66+
X-Cuenca-Api-Version:
67+
- '2020-03-19'
68+
x-amz-content-sha256:
69+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
70+
x-amz-date:
71+
- 20201019T180527Z
72+
method: GET
73+
uri: https://sandbox.cuenca.com/commissions/CO3FI2mQsprTNhoik7Ni1VQF
74+
response:
75+
body:
76+
string: '{"Code":"NotFoundError","Message":"NotFoundError: Not valid id"}'
77+
headers:
78+
Connection:
79+
- keep-alive
80+
Content-Length:
81+
- '64'
82+
Content-Type:
83+
- application/json
84+
Date:
85+
- Mon, 19 Oct 2020 18:05:28 GMT
86+
Via:
87+
- 1.1 f70a58ce7ab3276e2d4987075b643aea.cloudfront.net (CloudFront)
88+
X-Amz-Cf-Id:
89+
- WfLqxzb9brwwjAuXAM0NhGWKvfCYIoVPq4Dk0P7uKwZRNhNnqn9Uaw==
90+
X-Amz-Cf-Pop:
91+
- LAX50-C2
92+
X-Amzn-Trace-Id:
93+
- Root=1-5f8dd568-5ff7c82f4990f22c55adce5f;Sampled=0
94+
X-Cache:
95+
- Error from cloudfront
96+
x-amz-apigw-id:
97+
- Uq5IVFX9IAMFcTg=
98+
x-amzn-RequestId:
99+
- 4260df4a-cd37-49e8-b099-b6bc7a5579e4
100+
status:
101+
code: 404
102+
message: Not Found
103+
version: 1

tests/resources/cassettes/test_balance_entry_retrieve.yaml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,42 @@ interactions:
1111
Connection:
1212
- keep-alive
1313
User-Agent:
14-
- cuenca-python/0.2.0.dev1
14+
- cuenca-python/0.3.6
1515
X-Cuenca-Api-Version:
1616
- '2020-03-19'
17+
x-amz-content-sha256:
18+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
19+
x-amz-date:
20+
- 20201019T172955Z
1721
method: GET
1822
uri: https://sandbox.cuenca.com/balance_entries/TV01
1923
response:
2024
body:
21-
string: '{"id":"TV01","created_at":"2020-06-01T03:07:27.879000","amount":10000,"descriptor":"Test
22-
deposit","rolling_balance":10000,"transaction_uri":"/deposits/SP01"}'
25+
string: '{"id":"TV01","created_at":"2020-10-15T22:27:53.712000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","name":"Dep\u00f3sito
26+
de efectivo","amount":25000,"descriptor":"Deposito v\u00eda paynet auth 304054","rolling_balance":144519,"type":"credit","related_transaction_uri":"/deposits/CDI7SJOifauN5WnqfMhXK4R"}'
2327
headers:
2428
Connection:
2529
- keep-alive
2630
Content-Length:
27-
- '157'
31+
- '317'
2832
Content-Type:
2933
- application/json
3034
Date:
31-
- Tue, 16 Jun 2020 03:43:47 GMT
35+
- Mon, 19 Oct 2020 17:29:56 GMT
3236
Via:
33-
- 1.1 2e7e64e85275c7c3d580e9eab0385c03.cloudfront.net (CloudFront)
37+
- 1.1 1f2a017323162153f3cbc068c08d683d.cloudfront.net (CloudFront)
3438
X-Amz-Cf-Id:
35-
- 8AKT32IyjJ2xsUV6Ovwo3JtsOMyjTBzCo7HkvELoFRP_e6G9faXkmA==
39+
- jmXPfoX1V3D4gfK2oNRvYyCVTa0H4CFDq2UIJW0k5H98ZXDVOwuVUA==
3640
X-Amz-Cf-Pop:
37-
- JFK51-C1
41+
- LAX50-C2
3842
X-Amzn-Trace-Id:
39-
- Root=1-5ee83ff3-0388090aa11c07e20440f246;Sampled=0
43+
- Root=1-5f8dcd14-062b68864a68a14d561f7483;Sampled=0
4044
X-Cache:
4145
- Miss from cloudfront
4246
x-amz-apigw-id:
43-
- OM7uAF3JoAMF2GA=
47+
- Uqz7NGGKoAMFuzg=
4448
x-amzn-RequestId:
45-
- ee92b173-840e-47ab-8041-876d99d24102
49+
- 3c4972d3-4bb0-45b6-99d9-b184ad9102f9
4650
status:
4751
code: 200
4852
message: OK
@@ -58,38 +62,42 @@ interactions:
5862
Connection:
5963
- keep-alive
6064
User-Agent:
61-
- cuenca-python/0.2.0.dev1
65+
- cuenca-python/0.3.6
6266
X-Cuenca-Api-Version:
6367
- '2020-03-19'
68+
x-amz-content-sha256:
69+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
70+
x-amz-date:
71+
- 20201019T172956Z
6472
method: GET
65-
uri: https://sandbox.cuenca.com/deposits/SP01
73+
uri: https://sandbox.cuenca.com/deposits/CDI7SJOifauN5WnqfMhXK4R
6674
response:
6775
body:
68-
string: '{"id":"SP01","created_at":"2020-06-03T03:07:36.338000","amount":10000,"status":"succeeded","descriptor":"SPEI
69-
1","source_uri":"/accounts/BA01","network":"spei","tracking_key":"RASTREO_1234","user_id":"US01"}'
76+
string: '{"id":"CDI7SJOifauN5WnqfMhXK4R","created_at":"2020-10-15T22:27:53.827000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":25000,"status":"succeeded","descriptor":"Deposito
77+
v\u00eda paynet auth 304054","source_uri":null,"network":"cash","tracking_key":null}'
7078
headers:
7179
Connection:
7280
- keep-alive
7381
Content-Length:
74-
- '190'
82+
- '254'
7583
Content-Type:
7684
- application/json
7785
Date:
78-
- Tue, 16 Jun 2020 03:43:51 GMT
86+
- Mon, 19 Oct 2020 17:29:57 GMT
7987
Via:
80-
- 1.1 2e7e64e85275c7c3d580e9eab0385c03.cloudfront.net (CloudFront)
88+
- 1.1 1f2a017323162153f3cbc068c08d683d.cloudfront.net (CloudFront)
8189
X-Amz-Cf-Id:
82-
- 8f7zBxOkJlxr-hiBS-R19S0onB1iR1TgTtKR6vEmkUN_eVkXPDpe-Q==
90+
- Oca8s1d7DyjaJBtN-bGe_6DgjyLBUCYwZ6KV07FAoawSmfGM2zS5Eg==
8391
X-Amz-Cf-Pop:
84-
- JFK51-C1
92+
- LAX50-C2
8593
X-Amzn-Trace-Id:
86-
- Root=1-5ee83ff7-f4b1d5056df6a7219645fa39;Sampled=0
94+
- Root=1-5f8dcd15-4a3f9ad77ee830f7704af8b5;Sampled=0
8795
X-Cache:
8896
- Miss from cloudfront
8997
x-amz-apigw-id:
90-
- OM7utGv3IAMFf6g=
98+
- Uqz7UG_QIAMFVtQ=
9199
x-amzn-RequestId:
92-
- 0e4fa451-7a8a-4e46-867d-0547f72ac39c
100+
- 75f5428f-9a18-455b-9984-cc3e80fbde4b
93101
status:
94102
code: 200
95103
message: OK

tests/resources/cassettes/test_commission_retrieve_witw_deposit.yaml

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,53 +50,6 @@ interactions:
5050
status:
5151
code: 200
5252
message: OK
53-
- request:
54-
body: null
55-
headers:
56-
Accept:
57-
- '*/*'
58-
Accept-Encoding:
59-
- gzip, deflate
60-
Connection:
61-
- keep-alive
62-
User-Agent:
63-
- python-requests/2.24.0
64-
method: GET
65-
uri: https://sandbox.cuenca.com/config/route_configuration.json
66-
response:
67-
body:
68-
string: "{\n \"default_route\": \"/oaxaca\",\n \"routes\": {\n \
69-
\ \"cards\": \"/knox\",\n \"api_keys\": \"/authed\"\n }\n}\n"
70-
headers:
71-
Accept-Ranges:
72-
- bytes
73-
Age:
74-
- '1622'
75-
Connection:
76-
- keep-alive
77-
Content-Length:
78-
- '114'
79-
Content-Type:
80-
- application/json
81-
Date:
82-
- Thu, 01 Oct 2020 18:27:33 GMT
83-
ETag:
84-
- '"f35b9f1de4b47e51d5a9b8706ef54e6b"'
85-
Last-Modified:
86-
- Tue, 15 Sep 2020 22:51:15 GMT
87-
Server:
88-
- AmazonS3
89-
Via:
90-
- 1.1 19934e8c827f304089a6e45a640882cd.cloudfront.net (CloudFront)
91-
X-Amz-Cf-Id:
92-
- qPWYfE69Ef2tZYj9FciaKOvxYaD84CHV1P-eeqRX8BLnX2Tspp3ufA==
93-
X-Amz-Cf-Pop:
94-
- DFW55-C1
95-
X-Cache:
96-
- Hit from cloudfront
97-
status:
98-
code: 200
99-
message: OK
10053
- request:
10154
body: null
10255
headers:
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import pytest
22

33
from cuenca import BalanceEntry
4+
from cuenca.exc import CuencaResponseException
45

56

67
@pytest.mark.vcr
78
def test_balance_entry_retrieve():
89
id_entry = 'TV01'
910
balance_entry: BalanceEntry = BalanceEntry.retrieve(id_entry)
1011
assert balance_entry.id == id_entry
12+
txn = balance_entry.related_transaction
13+
assert (
14+
balance_entry.related_transaction_uri == f'/{txn._resource}/{txn.id}'
15+
)
1116

12-
txn = balance_entry.transaction
13-
assert balance_entry.transaction_uri == f'/{txn._resource}/{txn.id}'
17+
18+
@pytest.mark.vcr
19+
def test_balance_entry_related_transaction_not_exist():
20+
id_entry = 'TV02'
21+
balance_entry: BalanceEntry = BalanceEntry.retrieve(id_entry)
22+
assert balance_entry.id == id_entry
23+
with pytest.raises(CuencaResponseException):
24+
balance_entry.related_transaction

0 commit comments

Comments
 (0)