Skip to content

Commit c3f460e

Browse files
authored
Merge pull request #238 from andreshndz/verifications
Verifications 🛂
2 parents ca9f0f0 + 80becdc commit c3f460e

File tree

9 files changed

+238
-1
lines changed

9 files changed

+238
-1
lines changed

cuenca/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'UserCredential',
2828
'UserEvent',
2929
'UserLogin',
30+
'Verification',
3031
'WalletTransaction',
3132
'Webhook',
3233
'WhatsappTransfer',
@@ -65,6 +66,7 @@
6566
UserCredential,
6667
UserEvent,
6768
UserLogin,
69+
Verification,
6870
WalletTransaction,
6971
Webhook,
7072
WhatsappTransfer,

cuenca/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'User',
2626
'UserEvent',
2727
'UserLogin',
28+
'Verification',
2829
'WalletTransaction',
2930
'Webhook',
3031
'WhatsappTransfer',
@@ -58,6 +59,7 @@
5859
from .user_events import UserEvent
5960
from .user_logins import UserLogin
6061
from .users import User
62+
from .verifications import Verification
6163
from .wallet_transactions import WalletTransaction
6264
from .webhooks import Webhook
6365
from .whatsapp_transfers import WhatsappTransfer
@@ -91,6 +93,7 @@
9193
UserCredential,
9294
UserEvent,
9395
UserLogin,
96+
Verification,
9497
WalletTransaction,
9598
WhatsappTransfer,
9699
Webhook,

cuenca/resources/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _create(cls, *, session: Session = global_session, **data) -> Resource:
7171

7272
@dataclass
7373
class Updateable(Resource):
74+
7475
updated_at: dt.datetime
7576

7677
@classmethod

cuenca/resources/verifications.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import datetime as dt
2+
from typing import ClassVar, Optional, Union, cast
3+
4+
from cuenca_validations.types import VerificationType
5+
from cuenca_validations.types.identities import PhoneNumber
6+
from cuenca_validations.types.requests import (
7+
VerificationAttemptRequest,
8+
VerificationRequest,
9+
)
10+
from pydantic import EmailStr
11+
from pydantic.dataclasses import dataclass
12+
13+
from ..http import Session, session as global_session
14+
from .base import Creatable, Updateable
15+
16+
17+
@dataclass
18+
class Verification(Creatable, Updateable):
19+
_resource: ClassVar = 'verifications'
20+
21+
sender: Union[EmailStr, PhoneNumber]
22+
type: VerificationType
23+
created_at: dt.datetime
24+
deactivated_at: Optional[dt.datetime]
25+
26+
@classmethod
27+
def create(
28+
cls,
29+
sender: str,
30+
type: VerificationType,
31+
*,
32+
session: Session = global_session,
33+
) -> 'Verification':
34+
req = VerificationRequest(sender=sender, type=type)
35+
return cast('Verification', cls._create(**req.dict(), session=session))
36+
37+
@classmethod
38+
def verify(
39+
cls,
40+
id: str,
41+
code: str,
42+
*,
43+
session: Session = global_session,
44+
) -> 'Verification':
45+
req = VerificationAttemptRequest(code=code)
46+
return cast(
47+
'Verification',
48+
cls._update(id=id, **req.dict(), session=session),
49+
)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests==2.27.1
2-
cuenca-validations==0.9.22
2+
cuenca-validations==0.9.24.dev1
33
dataclasses>=0.7;python_version<"3.7"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
interactions:
2+
- request:
3+
body: '{"sender": "mail@cuenca.com", "type":"email_verification"}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '26'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- cuenca-python/0.7.13
19+
X-Cuenca-Api-Version:
20+
- '2020-03-19'
21+
method: POST
22+
uri: https://sandbox.cuenca.com/verifications
23+
response:
24+
body:
25+
string: '{"id":"VE01","created_at":"2022-02-09T19:06:44.109221","updated_at":"2022-02-09T19:06:44.109229","deactivated_at":null,"sender":"mail@cuenca.com","type":"email_verification"}'
26+
headers:
27+
Connection:
28+
- keep-alive
29+
Content-Length:
30+
- '335'
31+
Content-Type:
32+
- application/json
33+
Date:
34+
- Wed, 09 Feb 2022 19:06:44 GMT
35+
X-Request-Time:
36+
- 'value: 0.151'
37+
x-amz-apigw-id:
38+
- NSeOpF65CYcF8zg=
39+
x-amzn-Remapped-Connection:
40+
- keep-alive
41+
x-amzn-Remapped-Content-Length:
42+
- '335'
43+
x-amzn-Remapped-Date:
44+
- Wed, 09 Feb 2022 19:06:44 GMT
45+
x-amzn-Remapped-Server:
46+
- nginx/1.20.2
47+
x-amzn-RequestId:
48+
- 84a806f9-d2b6-4f9a-a8aa-a0f8fa0f94e7
49+
status:
50+
code: 201
51+
message: Created
52+
version: 1
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
interactions:
2+
- request:
3+
body: '{"sender": "+525555555555", "type":"phone_verification"}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '26'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- cuenca-python/0.7.13
19+
X-Cuenca-Api-Version:
20+
- '2020-03-19'
21+
method: POST
22+
uri: https://sandbox.cuenca.com/verifications
23+
response:
24+
body:
25+
string: '{"id":"VE01","created_at":"2022-02-09T19:06:44.109221","updated_at":"2022-02-09T19:06:44.109229","deactivated_at":null,"sender":"+525555555555","type":"phone_verification"}'
26+
headers:
27+
Connection:
28+
- keep-alive
29+
Content-Length:
30+
- '335'
31+
Content-Type:
32+
- application/json
33+
Date:
34+
- Wed, 09 Feb 2022 19:06:44 GMT
35+
X-Request-Time:
36+
- 'value: 0.151'
37+
x-amz-apigw-id:
38+
- NSeOpF65CYcF8zg=
39+
x-amzn-Remapped-Connection:
40+
- keep-alive
41+
x-amzn-Remapped-Content-Length:
42+
- '335'
43+
x-amzn-Remapped-Date:
44+
- Wed, 09 Feb 2022 19:06:44 GMT
45+
x-amzn-Remapped-Server:
46+
- nginx/1.20.2
47+
x-amzn-RequestId:
48+
- 84a806f9-d2b6-4f9a-a8aa-a0f8fa0f94e7
49+
status:
50+
code: 201
51+
message: Created
52+
version: 1
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
interactions:
2+
- request:
3+
body: '{"code": "123456"}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '26'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- cuenca-python/0.7.13
19+
X-Cuenca-Api-Version:
20+
- '2020-03-19'
21+
method: PATCH
22+
uri: https://sandbox.cuenca.com/verifications/VE01
23+
response:
24+
body:
25+
string: '{"id":"VE01","created_at":"2022-02-09T19:06:44.109221","updated_at":"2022-02-09T19:06:44.109229","deactivated_at":null,"sender":"+525555555555","type":"phone_verification"}'
26+
headers:
27+
Connection:
28+
- keep-alive
29+
Content-Length:
30+
- '335'
31+
Content-Type:
32+
- application/json
33+
Date:
34+
- Wed, 09 Feb 2022 19:06:44 GMT
35+
X-Request-Time:
36+
- 'value: 0.151'
37+
x-amz-apigw-id:
38+
- NSeOpF65CYcF8zg=
39+
x-amzn-Remapped-Connection:
40+
- keep-alive
41+
x-amzn-Remapped-Content-Length:
42+
- '335'
43+
x-amzn-Remapped-Date:
44+
- Wed, 09 Feb 2022 19:06:44 GMT
45+
x-amzn-Remapped-Server:
46+
- nginx/1.20.2
47+
x-amzn-RequestId:
48+
- 84a806f9-d2b6-4f9a-a8aa-a0f8fa0f94e7
49+
status:
50+
code: 200
51+
message: Ok
52+
version: 1
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
from cuenca_validations.types import VerificationType
3+
4+
from cuenca import Verification
5+
6+
7+
@pytest.mark.vcr
8+
def test_verification_email_create():
9+
verification: Verification = Verification.create(
10+
sender='mail@cuenca.com', type=VerificationType.email_verification
11+
)
12+
assert verification.id
13+
14+
15+
@pytest.mark.vcr
16+
def test_verification_phone_create():
17+
verification: Verification = Verification.create(
18+
sender='+525555555555', type=VerificationType.phone_verification
19+
)
20+
assert verification.id
21+
22+
23+
@pytest.mark.vcr
24+
def test_verification_verify():
25+
verification: Verification = Verification.verify(id='VE01', code='111111')
26+
assert verification.id

0 commit comments

Comments
 (0)