Skip to content

Commit 37951c0

Browse files
committed
signature test
1 parent 744d960 commit 37951c0

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

cuenca/resources/signatures.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from ipaddress import IPv4Address, IPv6Address
12
from typing import ClassVar
23

3-
from cuenca_validations.types import Signature, SignatureRequest
4+
from cuenca_validations.types import SignatureFile, SignatureRequest
45
from pydantic import ConfigDict
56

67
from ..http import Session, session as global_session
@@ -9,24 +10,25 @@
910

1011
class Signature(Creatable, Retrievable):
1112
_resource: ClassVar = 'signatures'
12-
signature_id: Signature
13+
signature_id: SignatureFile
1314

1415
model_config = ConfigDict(
1516
json_schema_extra={
1617
'example': {
1718
'id': 'string',
18-
'signature_id': Signature.schema().get('example'),
19+
'signature_id': SignatureFile.schema().get('example'),
1920
'created_at': '2020-05-24T14:15:22Z',
2021
}
21-
}
22+
},
23+
json_encoders={IPv4Address: str, IPv6Address: str},
2224
)
2325

2426
@classmethod
2527
def create(
2628
cls,
27-
signature: Signature,
29+
signature: SignatureFile,
2830
user_id: str,
2931
session: Session = global_session,
3032
) -> 'Signature':
3133
req = SignatureRequest(signature=signature, user_id=user_id)
32-
return cls._create(**req.model_dump(), session=session)
34+
return cls._create(**req.model_dump(mode='json'), session=session)

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.0
2+
cuenca-validations==2.1.1.dev5
33
pydantic-extra-types==2.10.2
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
interactions:
2+
- request:
3+
body:
4+
'{"signature": {"uri": "https://www.google.com/image.png", "location": "19.432608,
5+
-99.133209", "ip": "192.168.1.100", "hash": "1234567890"}, "user_id": "USFOOBAR"}'
6+
headers:
7+
Content-Length:
8+
- "163"
9+
Content-Type:
10+
- application/json
11+
User-Agent:
12+
- cuenca-python/2.1.0
13+
X-Cuenca-Api-Version:
14+
- "2020-03-19"
15+
method: POST
16+
uri: https://sandbox.cuenca.com/signatures
17+
response:
18+
body:
19+
string:
20+
'{"id": "sig_123456789", "signature_id": {"uri": "https://www.google.com/image.png",
21+
"location": "19.432608, -99.133209", "ip": "192.168.1.100", "hash": "1234567890"},
22+
"created_at": "2025-02-13T20:58:46Z"}'
23+
headers:
24+
Connection:
25+
- keep-alive
26+
Content-Length:
27+
- "228"
28+
Content-Type:
29+
- application/json
30+
Date:
31+
- Thu, 13 Feb 2025 20:58:46 GMT
32+
x-amz-apigw-id:
33+
- F8N5CHhBoAMEJmQ=
34+
x-amzn-Remapped-Connection:
35+
- keep-alive
36+
x-amzn-Remapped-Content-Length:
37+
- "228"
38+
x-amzn-Remapped-Date:
39+
- Thu, 13 Feb 2025 20:58:46 GMT
40+
x-amzn-Remapped-Server:
41+
- nginx/1.26.2
42+
x-amzn-RequestId:
43+
- e36ae661-84ae-41db-98df-5e6e45df96ef
44+
status:
45+
code: 201
46+
message: Created
47+
version: 1

tests/resources/test_signature.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import pytest
2+
from cuenca_validations.types import SignatureFile
23

34
from cuenca import Signature
45

56

67
@pytest.mark.vcr
78
def test_signature_create():
8-
signature: Signature = Signature.create(user_id="USFOOBAR")
9+
signature_file = SignatureFile(
10+
uri="https://www.google.com/image.png",
11+
ip="192.168.1.100",
12+
location="19.432608, -99.133209",
13+
hash="1234567890",
14+
)
15+
signature: Signature = Signature.create(
16+
user_id="USFOOBAR",
17+
signature=signature_file,
18+
)
919
assert signature.id
1020
assert signature.signature_id

0 commit comments

Comments
 (0)