Skip to content

Commit 82779f7

Browse files
feat: add missing tests
1 parent 403950e commit 82779f7

File tree

6 files changed

+271
-56
lines changed

6 files changed

+271
-56
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests==2.32.3
2-
cuenca-validations==2.1.17.dev3
2+
cuenca-validations==2.1.17.dev4
33
pydantic-extra-types==2.10.2

tests/conftest.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import datetime as dt
22
from io import BytesIO
3+
from typing import Generator
34

45
import pytest
5-
from cuenca_validations.types import Country, Gender, State
6+
from cuenca_validations.types import Country, Gender, SessionType, State
67
from cuenca_validations.types.enums import Profession
78

89
import cuenca
10+
from cuenca.http import Session as ClientSession
11+
from cuenca.resources.sessions import Session
912

1013
cuenca.configure(sandbox=True)
1114

@@ -76,3 +79,23 @@ def user_lists_request() -> dict:
7679
def file() -> BytesIO:
7780
with open('tests/data/test_file.jpeg', 'rb') as image_file:
7881
return BytesIO(image_file.read())
82+
83+
84+
@pytest.fixture
85+
def session_with_resource_id() -> Generator[Session]:
86+
session = Session.create(
87+
'USPR4JxMuwSG60u2h4gBpB6Q',
88+
SessionType.onboarding_verification,
89+
resource_id='68b887f60c33abad1ea841d3',
90+
)
91+
yield session
92+
93+
94+
@pytest.fixture
95+
def client_authed_with_session(
96+
session_with_resource_id: Session,
97+
) -> Generator[ClientSession]:
98+
client = ClientSession()
99+
client.configure(session_token=session_with_resource_id.id, sandbox=True)
100+
client.basic_auth = ('', '')
101+
yield client
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
interactions:
2-
- request:
3-
body:
4-
'{"user_id": "USPR4JxMuwSG60u2h4gBpB6Q", "type": "session.metamap_verification",
5-
"resource_id": "68b887f60c33abad1ea841d3"}'
6-
headers:
7-
Authorization:
8-
- DUMMY
9-
Content-Length:
10-
- "122"
11-
Content-Type:
12-
- application/json
13-
User-Agent:
14-
- cuenca-python/2.1.11.dev1
15-
X-Cuenca-Api-Version:
16-
- "2020-03-19"
17-
method: POST
18-
uri: https://sandbox.cuenca.com/sessions
19-
response:
20-
body:
21-
string: '{"id": "SSRk8W9VPBRgixHFh0rNOejg", "created_at": "2025-09-09T19:04:37.242865", "user_id": "USPR4JxMuwSG60u2h4gBpB6Q", "platform_id": "PTZbBlk__kQt-wfwzP5nwA9A", "expires_at": "2025-09-09T19:14:37.242877",
22-
"success_url": null, "failure_url": null, "type": "session.metamap_verification", "resource_id": "68b887f60c33abad1ea841d3"}'
23-
headers:
24-
Connection:
25-
- keep-alive
26-
Content-Length:
27-
- "49"
28-
Content-Type:
29-
- application/json
30-
Date:
31-
- Tue, 09 Sep 2025 19:10:56 GMT
32-
x-amz-apigw-id:
33-
- QphGKFeICYcEU6w=
34-
x-amzn-Remapped-Connection:
35-
- close
36-
x-amzn-Remapped-Content-Length:
37-
- "49"
38-
x-amzn-Remapped-Date:
39-
- Tue, 09 Sep 2025 19:10:56 GMT
40-
x-amzn-Remapped-Server:
41-
- nginx/1.28.0
42-
x-amzn-RequestId:
43-
- 0b3f6126-1702-42b2-934b-a69da53399e4
44-
status:
45-
code: 200
46-
message: OK
2+
- request:
3+
body: '{"user_id": "USPR4JxMuwSG60u2h4gBpB6Q", "type": "session.onboarding_verification",
4+
"resource_id": "68b887f60c33abad1ea841d3"}'
5+
headers:
6+
Authorization:
7+
- DUMMY
8+
Content-Length:
9+
- '125'
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- cuenca-python/2.1.11
14+
X-Cuenca-Api-Version:
15+
- '2020-03-19'
16+
method: POST
17+
uri: https://sandbox.cuenca.com/sessions
18+
response:
19+
body:
20+
string: '{"id":"SS-x6PU8GxSpKYL9btp4Btog","created_at":"2025-09-10T20:33:32.483427","user_id":"USPR4JxMuwSG60u2h4gBpB6Q","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","expires_at":"2025-09-10T20:43:32.483438","success_url":null,"failure_url":null,"type":"session.onboarding_verification","resource_id":"68b887f60c33abad1ea841d3"}'
21+
headers:
22+
Connection:
23+
- keep-alive
24+
Content-Length:
25+
- '315'
26+
Content-Type:
27+
- application/json
28+
Date:
29+
- Wed, 10 Sep 2025 20:33:32 GMT
30+
X-Request-Time:
31+
- 'value: 0.167'
32+
x-amz-apigw-id:
33+
- QtAIfG7eCYcEsfQ=
34+
x-amzn-Remapped-Connection:
35+
- keep-alive
36+
x-amzn-Remapped-Content-Length:
37+
- '315'
38+
x-amzn-Remapped-Date:
39+
- Wed, 10 Sep 2025 20:33:32 GMT
40+
x-amzn-Remapped-Server:
41+
- nginx/1.28.0
42+
x-amzn-RequestId:
43+
- deb095dd-c1c6-4837-b5ac-54a0c41d9fb2
44+
status:
45+
code: 201
46+
message: Created
4747
version: 1
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
interactions:
2+
- request:
3+
body: '{"user_id": "USPR4JxMuwSG60u2h4gBpB6Q", "type": "session.onboarding_verification",
4+
"resource_id": "68b887f60c33abad1ea841d3"}'
5+
headers:
6+
Authorization:
7+
- DUMMY
8+
Content-Length:
9+
- '125'
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- cuenca-python/2.1.11
14+
X-Cuenca-Api-Version:
15+
- '2020-03-19'
16+
method: POST
17+
uri: https://sandbox.cuenca.com/sessions
18+
response:
19+
body:
20+
string: '{"id":"SSOXga_D_VQXCPsWQT7Z0ddQ","created_at":"2025-09-10T20:33:32.875517","user_id":"USPR4JxMuwSG60u2h4gBpB6Q","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","expires_at":"2025-09-10T20:43:32.875529","success_url":null,"failure_url":null,"type":"session.onboarding_verification","resource_id":"68b887f60c33abad1ea841d3"}'
21+
headers:
22+
Connection:
23+
- keep-alive
24+
Content-Length:
25+
- '315'
26+
Content-Type:
27+
- application/json
28+
Date:
29+
- Wed, 10 Sep 2025 20:33:32 GMT
30+
X-Request-Time:
31+
- 'value: 0.151'
32+
x-amz-apigw-id:
33+
- QtAIjGCGiYcEuZw=
34+
x-amzn-Remapped-Connection:
35+
- keep-alive
36+
x-amzn-Remapped-Content-Length:
37+
- '315'
38+
x-amzn-Remapped-Date:
39+
- Wed, 10 Sep 2025 20:33:32 GMT
40+
x-amzn-Remapped-Server:
41+
- nginx/1.28.0
42+
x-amzn-RequestId:
43+
- 0d6c920d-4608-4d1c-9858-fe81fccba4b1
44+
status:
45+
code: 201
46+
message: Created
47+
- request:
48+
body: null
49+
headers:
50+
User-Agent:
51+
- cuenca-python/2.1.11
52+
X-Cuenca-Api-Version:
53+
- '2020-03-19'
54+
X-Cuenca-SessionId:
55+
- SSOXga_D_VQXCPsWQT7Z0ddQ
56+
method: GET
57+
uri: https://sandbox.cuenca.com/onboarding_verifications/68b887f60c33abad1ea841d3
58+
response:
59+
body:
60+
string: '{"gov_id_document_number":"267202610","gov_id_front":"https://media-cdn.prod.metamap.com/documents/production/9b1bccd3-1cc2-4f94-b9bc-e416f23a685c.jpeg?Expires=1757795613&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9tZWRpYS1jZG4ucHJvZC5tZXRhbWFwLmNvbS9kb2N1bWVudHMvcHJvZHVjdGlvbi85YjFiY2NkMy0xY2MyLTRmOTQtYjliYy1lNDE2ZjIzYTY4NWMuanBlZyIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTc1Nzc5NTYxM319fV19&Signature=kqeDz-ik5UJTUAC3JRN4y15BMyT-ruaExqM9vCuJQ1gVr8BYjFfwZENW4qDBU0-6c4J0zxkr853-IKeEwqus~Xxn7ui0jv5MGxt4HEZOGnv-CkKx2EENt-3-GelJ9EmiSUaUkIouHr-V1MNm8-Cuea1m1TMFjnOAXpoiEbudT0-RnILGKJui90DGWSEzQsLjwz0Y7wCS2KNaIOb~ors8V~WiwULVYSJh6L0IPPKUlbAch-HocVU3uQOlBTb3e-xSKsxcLVTLHTmnXefcZvPIHIiPWtOMwBQP7~AqesIszrHQVPAaS9VLkN~2md4zVwDb6VmBHCTqtg7sxJJMjGKiRQ__&Key-Pair-Id=K3UFJ5LH7J6562","proof_of_address":"https://media-cdn.prod.metamap.com/documents/production/52ac2e59-8416-49b0-bd56-9fe1f245a8d8.jpeg?Expires=1757795613&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9tZWRpYS1jZG4ucHJvZC5tZXRhbWFwLmNvbS9kb2N1bWVudHMvcHJvZHVjdGlvbi81MmFjMmU1OS04NDE2LTQ5YjAtYmQ1Ni05ZmUxZjI0NWE4ZDguanBlZyIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTc1Nzc5NTYxM319fV19&Signature=pET21fJJDoDHjd3agnQ1Aa-Ux9zuxGP9mAbrR7K4DLSeRq9tKzplchaWl3VZRBk2jeSSkcSLO0KhCmgFqGDj92SsPmIbJrB6Ay5XIjh6jQjrnGUIR3w8NFgSaxFeogoLBL5mzamyXf5KzRQ32I7xnWnIlLhhEzPGE3x74lZwIvZ04Gc1Vh5pLeBT-xFxlAtdlEW7HW3O8Y~GFo7TupQiH52YSx1c8us2URUCdXJxiRHId0-BHSTa~qk8uJghRNH~Q~4TQVlMS6LUDztvC0xaubmU7i0ArO8o3TMG~JYQcmil0kFq5XHcEwX734XyijRLRFkhWUrVLzojiSCXZwPPfA__&Key-Pair-Id=K3UFJ5LH7J6562","liveness_selfie":"https://media-cdn.prod.metamap.com/selfies/production/018fbc9f-085e-4a72-a2a4-8fe2e3d40473.jpeg?Expires=1757795613&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9tZWRpYS1jZG4ucHJvZC5tZXRhbWFwLmNvbS9zZWxmaWVzL3Byb2R1Y3Rpb24vMDE4ZmJjOWYtMDg1ZS00YTcyLWEyYTQtOGZlMmUzZDQwNDczLmpwZWciLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE3NTc3OTU2MTN9fX1dfQ__&Signature=nkckXL3~GOgWMPVc9RZCTTFIoSRcaCynFSSJGwYp5FIrepxH5us8Gx-lSzyYLmse2aQZqHOudiX2MDdIJXQCXYbxuNbVPY0EtQ3AhAzDU-a4k6lh4qH0GAkuUINRjfSmpAcj6JtDqsx4icLImZlZ0CTsP8cEguJlUUW994zKqHyT0UyQRy7wB39zVKIx9arqzULKQe-RRimu1mMmRIkfo5k0ARrDQYbWNiGpxZTNaYmXayPkH2T1sSa~sIkLxjpJbWCNGZ0kMqMPuSFdWYg4RjIrHb2UHDubegi7rj5SmefeqSUCVgb7YVD1YWutXfogRIJraDm~Ph9qpLQfEvV4~Q__&Key-Pair-Id=K3UFJ5LH7J6562"}'
61+
headers:
62+
Connection:
63+
- keep-alive
64+
Content-Length:
65+
- '2359'
66+
Content-Type:
67+
- application/json
68+
Date:
69+
- Wed, 10 Sep 2025 20:33:33 GMT
70+
X-Request-Time:
71+
- 'value: 0.388'
72+
x-amz-apigw-id:
73+
- QtAImGe5iYcEi4g=
74+
x-amzn-Remapped-Connection:
75+
- keep-alive
76+
x-amzn-Remapped-Content-Length:
77+
- '2359'
78+
x-amzn-Remapped-Date:
79+
- Wed, 10 Sep 2025 20:33:33 GMT
80+
x-amzn-Remapped-Server:
81+
- nginx/1.28.0
82+
x-amzn-RequestId:
83+
- 848ed62c-6ec3-4150-a3fb-5a082cb313b4
84+
status:
85+
code: 200
86+
message: OK
87+
version: 1
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
interactions:
2+
- request:
3+
body:
4+
'{"user_id": "USPR4JxMuwSG60u2h4gBpB6Q", "type": "session.onboarding_verification",
5+
"resource_id": "68b887f60c33abad1ea841d3"}'
6+
headers:
7+
Authorization:
8+
- DUMMY
9+
Content-Length:
10+
- "125"
11+
Content-Type:
12+
- application/json
13+
User-Agent:
14+
- cuenca-python/2.1.11
15+
X-Cuenca-Api-Version:
16+
- "2020-03-19"
17+
method: POST
18+
uri: https://sandbox.cuenca.com/sessions
19+
response:
20+
body:
21+
string: '{"id":"SSsxQina5sTNii7gv--OXg1g","created_at":"2025-09-10T20:34:31.525777","user_id":"USPR4JxMuwSG60u2h4gBpB6Q","platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","expires_at":"2025-09-10T20:44:31.525789","success_url":null,"failure_url":null,"type":"session.onboarding_verification","resource_id":"68b887f60c33abad1ea841d3"}'
22+
headers:
23+
Connection:
24+
- keep-alive
25+
Content-Length:
26+
- "315"
27+
Content-Type:
28+
- application/json
29+
Date:
30+
- Wed, 10 Sep 2025 20:34:31 GMT
31+
X-Request-Time:
32+
- "value: 0.129"
33+
x-amz-apigw-id:
34+
- QtARtGC6iYcEJYA=
35+
x-amzn-Remapped-Connection:
36+
- keep-alive
37+
x-amzn-Remapped-Content-Length:
38+
- "315"
39+
x-amzn-Remapped-Date:
40+
- Wed, 10 Sep 2025 20:34:31 GMT
41+
x-amzn-Remapped-Server:
42+
- nginx/1.28.0
43+
x-amzn-RequestId:
44+
- 965c6cc2-31d3-4024-9c21-09ae6d4da534
45+
status:
46+
code: 201
47+
message: Created
48+
- request:
49+
body: null
50+
headers:
51+
User-Agent:
52+
- cuenca-python/2.1.11
53+
X-Cuenca-Api-Version:
54+
- "2020-03-19"
55+
X-Cuenca-SessionId:
56+
- SSsxQina5sTNii7gv--OXg1g
57+
method: GET
58+
uri: https://sandbox.cuenca.com/onboarding_verifications/68b887f60c33abad1ea841d4
59+
response:
60+
body:
61+
string: '{"error":"User has not enough permissions"}'
62+
headers:
63+
Connection:
64+
- keep-alive
65+
Content-Length:
66+
- "43"
67+
Content-Type:
68+
- application/json
69+
Date:
70+
- Wed, 10 Sep 2025 20:34:31 GMT
71+
x-amz-apigw-id:
72+
- QtARxHZtCYcEoCg=
73+
x-amzn-Remapped-Connection:
74+
- keep-alive
75+
x-amzn-Remapped-Content-Length:
76+
- "43"
77+
x-amzn-Remapped-Date:
78+
- Wed, 10 Sep 2025 20:34:31 GMT
79+
x-amzn-Remapped-Server:
80+
- nginx/1.28.0
81+
x-amzn-RequestId:
82+
- c9539c27-70d2-4821-8afc-4bd7146253ef
83+
status:
84+
code: 401
85+
message: Unauthorized
86+
version: 1

tests/resources/test_sessions.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from cuenca_validations.types import Profession, SessionType
33
from pydantic import ValidationError
44

5-
import cuenca
5+
from cuenca.exc import CuencaResponseException
6+
from cuenca.http import Session as ClientSession
67
from cuenca.resources import CurpValidation, Session, User
78

89

@@ -33,7 +34,7 @@ def test_session_create(curp_validation_request: dict, user_request: dict):
3334
assert user_session.user_id == user.id
3435
assert user_session.type == SessionType.registration
3536

36-
ephimeral_cuenca_session = cuenca.http.Session()
37+
ephimeral_cuenca_session = ClientSession()
3738
ephimeral_cuenca_session.configure(session_token=user_session.id)
3839

3940
user = User.update(user.id, profession=Profession.comercio)
@@ -42,13 +43,31 @@ def test_session_create(curp_validation_request: dict, user_request: dict):
4243

4344
@pytest.mark.vcr
4445
def test_session_create_with_resource_id(
45-
curp_validation_request: dict, user_request: dict
46+
session_with_resource_id: Session,
4647
) -> None:
47-
session = Session.create(
48-
'USPR4JxMuwSG60u2h4gBpB6Q',
49-
SessionType.metamap_verification,
50-
resource_id='68b887f60c33abad1ea841d3',
48+
assert session_with_resource_id.user_id == 'USPR4JxMuwSG60u2h4gBpB6Q'
49+
assert session_with_resource_id.resource_id == '68b887f60c33abad1ea841d3'
50+
51+
52+
@pytest.mark.vcr
53+
def test_session_with_resource_id_authorized(
54+
client_authed_with_session: ClientSession,
55+
) -> None:
56+
resource_id = '68b887f60c33abad1ea841d3'
57+
response = client_authed_with_session.get(
58+
f'onboarding_verifications/{resource_id}'
5159
)
5260

53-
assert session.user_id == 'USPR4JxMuwSG60u2h4gBpB6Q'
54-
assert session.resource_id == '68b887f60c33abad1ea841d3'
61+
assert response['gov_id_document_number'] == '267202610'
62+
63+
64+
@pytest.mark.vcr
65+
def test_session_with_resource_id_unauthorized(
66+
client_authed_with_session: ClientSession,
67+
) -> None:
68+
resource_id = '68b887f60c33abad1ea841d4'
69+
with pytest.raises(CuencaResponseException) as e:
70+
client_authed_with_session.get(
71+
f'onboarding_verifications/{resource_id}'
72+
)
73+
assert e.value.json['error'] == 'User has not enough permissions'

0 commit comments

Comments
 (0)