Skip to content

Commit 6f72af7

Browse files
authored
Add OTP Resource (#402)
* Add OTP resource * Add resource init * Add test
1 parent 167320c commit 6f72af7

File tree

7 files changed

+196
-2
lines changed

7 files changed

+196
-2
lines changed

cuenca/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'KYCVerification',
2424
'LimitedWallet',
2525
'LoginToken',
26+
'Otp',
2627
'Platform',
2728
'Questionnaires',
2829
'Saving',
@@ -70,6 +71,7 @@
7071
KYCVerification,
7172
LimitedWallet,
7273
LoginToken,
74+
Otp,
7375
Platform,
7476
Questionnaires,
7577
Saving,

cuenca/resources/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'KYCVerification',
2323
'LimitedWallet',
2424
'LoginToken',
25+
'Otp',
2526
'Platform',
2627
'Questionnaires',
2728
'Saving',
@@ -62,6 +63,7 @@
6263
from .kyc_verifications import KYCVerification
6364
from .limited_wallets import LimitedWallet
6465
from .login_tokens import LoginToken
66+
from .otps import Otp
6567
from .platforms import Platform
6668
from .questionnaires import Questionnaires
6769
from .resources import RESOURCES

cuenca/resources/otps.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import ClassVar, cast
2+
3+
from ..http import Session, session as global_session
4+
from .base import Creatable
5+
6+
7+
class Otp(Creatable):
8+
_resource: ClassVar = 'otps'
9+
secret: str
10+
11+
class Config:
12+
schema_extra = {
13+
'example': {
14+
'id': 'OTNEUInh69SuKXXmK95sROwQ',
15+
'secret': 'somesecret',
16+
}
17+
}
18+
19+
@classmethod
20+
def create(cls, session: Session = global_session) -> 'Otp':
21+
"""
22+
Use this method to create a OTP seed
23+
"""
24+
return cast('Otp', cls._create(session=session))

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '1.0.0'
1+
__version__ = '1.0.1'
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,3 +1,3 @@
11
requests==2.31.0
2-
cuenca-validations==0.11.24
2+
cuenca-validations==0.11.29
33
dataclasses>=0.7;python_version<"3.7"
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
interactions:
2+
- request:
3+
body: '{"password": "111111"}'
4+
headers:
5+
Authorization:
6+
- DUMMY
7+
Content-Length:
8+
- '22'
9+
Content-Type:
10+
- application/json
11+
User-Agent:
12+
- cuenca-python/1.0.1
13+
X-Cuenca-Api-Version:
14+
- '2020-03-19'
15+
method: POST
16+
uri: https://sandbox.cuenca.com/user_logins
17+
response:
18+
body:
19+
string: '{"success":true,"id":"ULHErlEswQQOKUzDuXAwJJkw","last_login_at":"2024-06-04T19:23:14.810000Z"}'
20+
headers:
21+
Connection:
22+
- keep-alive
23+
Content-Length:
24+
- '94'
25+
Content-Type:
26+
- application/json
27+
Date:
28+
- Tue, 04 Jun 2024 19:24:17 GMT
29+
X-Request-Time:
30+
- 'value: 0.966'
31+
x-amz-apigw-id:
32+
- Y217JHAUiYcEJ4Q=
33+
x-amzn-Remapped-Connection:
34+
- keep-alive
35+
x-amzn-Remapped-Content-Length:
36+
- '94'
37+
x-amzn-Remapped-Date:
38+
- Tue, 04 Jun 2024 19:24:17 GMT
39+
x-amzn-Remapped-Server:
40+
- nginx/1.26.1
41+
x-amzn-RequestId:
42+
- 288bfa6d-285a-498a-8886-99260a06d126
43+
status:
44+
code: 201
45+
message: Created
46+
- request:
47+
body: '{}'
48+
headers:
49+
Authorization:
50+
- DUMMY
51+
Content-Length:
52+
- '2'
53+
Content-Type:
54+
- application/json
55+
User-Agent:
56+
- cuenca-python/1.0.1
57+
X-Cuenca-Api-Version:
58+
- '2020-03-19'
59+
X-Cuenca-LoginId:
60+
- ULHErlEswQQOKUzDuXAwJJkw
61+
method: POST
62+
uri: https://sandbox.cuenca.com/login_tokens
63+
response:
64+
body:
65+
string: '{"id":"LTKtGqXPLCTXyRCrsIs6gKuQ"}'
66+
headers:
67+
Connection:
68+
- keep-alive
69+
Content-Length:
70+
- '33'
71+
Content-Type:
72+
- application/json
73+
Date:
74+
- Tue, 04 Jun 2024 19:24:18 GMT
75+
X-Request-Time:
76+
- 'value: 0.259'
77+
x-amz-apigw-id:
78+
- Y217VFCDiYcES9Q=
79+
x-amzn-Remapped-Connection:
80+
- keep-alive
81+
x-amzn-Remapped-Content-Length:
82+
- '33'
83+
x-amzn-Remapped-Date:
84+
- Tue, 04 Jun 2024 19:24:18 GMT
85+
x-amzn-Remapped-Server:
86+
- nginx/1.26.1
87+
x-amzn-RequestId:
88+
- 58bbb2f1-a71b-4261-98d4-27c7bbcc1276
89+
status:
90+
code: 201
91+
message: Created
92+
- request:
93+
body: '{}'
94+
headers:
95+
Authorization:
96+
- DUMMY
97+
Content-Length:
98+
- '2'
99+
Content-Type:
100+
- application/json
101+
User-Agent:
102+
- cuenca-python/1.0.1
103+
X-Cuenca-Api-Version:
104+
- '2020-03-19'
105+
X-Cuenca-LoginToken:
106+
- LTKtGqXPLCTXyRCrsIs6gKuQ
107+
method: POST
108+
uri: https://sandbox.cuenca.com/otps
109+
response:
110+
body:
111+
string: '{"id":"OTlnzPI3L3TDGr7oOu1u1OmQ","created_at":"2024-06-04T19:24:18.484246","deactivated_at":null,"api_key_id":"AKVCW_e3u3RtuD8Zjl1skTsg","secret":"D2W32HMQLNOWHQOGN5LIHWNX2XRKUXTX"}'
112+
headers:
113+
Connection:
114+
- keep-alive
115+
Content-Length:
116+
- '181'
117+
Content-Type:
118+
- application/json
119+
Date:
120+
- Tue, 04 Jun 2024 19:24:18 GMT
121+
X-Request-Time:
122+
- 'value: 0.339'
123+
x-amz-apigw-id:
124+
- Y217aGweiYcEapg=
125+
x-amzn-Remapped-Connection:
126+
- keep-alive
127+
x-amzn-Remapped-Content-Length:
128+
- '181'
129+
x-amzn-Remapped-Date:
130+
- Tue, 04 Jun 2024 19:24:18 GMT
131+
x-amzn-Remapped-Server:
132+
- nginx/1.26.1
133+
x-amzn-RequestId:
134+
- 4a31636d-c821-42eb-965a-52184b4f8754
135+
status:
136+
code: 201
137+
message: Created
138+
version: 1

tests/resources/test_otps.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
from cuenca import LoginToken, Otp, UserLogin
4+
from cuenca.http.client import Session
5+
6+
7+
@pytest.fixture(scope='function')
8+
def session():
9+
session = Session()
10+
session.configure(
11+
'api_key',
12+
'api_secret',
13+
sandbox=True,
14+
)
15+
return session
16+
17+
18+
@pytest.mark.vcr
19+
def test_otps(session):
20+
UserLogin.create('111111', session=session)
21+
login_token = LoginToken.create(session=session)
22+
session.headers.pop(
23+
'X-Cuenca-LoginId',
24+
)
25+
session.configure(login_token=login_token.id)
26+
otp = Otp.create()
27+
assert otp
28+
assert type(otp.secret) == str

0 commit comments

Comments
 (0)