Skip to content

Commit

Permalink
fix: update project remove cpf cnpj restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
joepreludian committed Jul 17, 2024
1 parent 0382852 commit 36fe3be
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "asaaspy"
version = "0.3.0"
version = "0.4.1"
description = "Unnoficial python client for Asaas"
authors = [
{name = "Jonhnatha Trigueiro", email = "[email protected]"},
Expand Down
13 changes: 9 additions & 4 deletions src/asaaspy/client/resources/customer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asaaspy.client.base import AsaasResource
from asaaspy.schemas.customer import (
CustomerCreateSchema,
CustomerSchema,
CustomerSearchParams,
CustomerViewSchema,
)


Expand Down Expand Up @@ -31,14 +31,19 @@ def all(
}
).as_lean_dict(),
),
data_response_class=CustomerSchema,
data_response_class=CustomerViewSchema,
)
return response

def create(self, customer: CustomerCreateSchema) -> CustomerSchema:
def get(self, customer_id):
with self.get_client() as client:
response = client.get(f"v3/customers/{customer_id}")
return CustomerViewSchema(**response.json())

def create(self, customer: CustomerCreateSchema) -> CustomerViewSchema:
with self.get_client() as client:
response = client.post("v3/customers", json=customer.as_lean_dict())
return CustomerSchema(**response.json())
return CustomerViewSchema(**response.json())

def delete(self, id: str) -> bool:
with self.get_client() as client:
Expand Down
6 changes: 3 additions & 3 deletions src/asaaspy/schemas/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CustomerCreateSchema(BaseSchema):
name: str
cpfCnpj: str
cpfCnpj: Optional[str] = None
email: Optional[str] = None
phone: Optional[str] = None
mobilePhone: Optional[str] = None
Expand All @@ -25,14 +25,14 @@ class CustomerCreateSchema(BaseSchema):
company: Optional[str] = None


class CustomerSchema(CustomerCreateSchema):
class CustomerViewSchema(CustomerCreateSchema):
id: Optional[str] = None
object: Optional[str] = None
personType: Optional[str] = None
deleted: Optional[bool] = None
canDelete: Optional[bool] = None
canEdit: Optional[bool] = None
cannotBeDeletedReason: Optional[bool] = None
cannotBeDeletedReason: Optional[str] = None
cannotEditReason: Optional[str] = None
dateCreated: Optional[Date] = None

Expand Down
74 changes: 74 additions & 0 deletions tests/asaas_sandbox_vcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,80 @@
"string": "{\"deleted\":true,\"id\":\"pay_vtkxai01k8o8jo55\"}"
}
}
},
{
"request": {
"method": "GET",
"uri": "https://sandbox.asaas.com/api/v3/customers/cus_000006102042",
"body": "",
"headers": {
"host": [
"sandbox.asaas.com"
],
"accept": [
"*/*"
],
"accept-encoding": [
"gzip, deflate"
],
"connection": [
"keep-alive"
],
"content-type": [
"application/json"
],
"user-agent": [
"AsaasPy"
]
}
},
"response": {
"status": {
"code": 200,
"message": ""
},
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Transfer-Encoding": [
"chunked"
],
"Connection": [
"keep-alive"
],
"Date": [
"Wed, 17 Jul 2024 18:47:22 GMT"
],
"Set-Cookie": [
"AWSALBTG=n9jcQybr+cT0KsQjEvSYZMKQCZfBlgjJIlhK6RV/8Q89vMrJyHSahvKt01jrx5tjIKQFVNR3WRa5v3ZGpTBRp8lINg9r+qq3/KUMlIeVin01GIQXwh7h9Ml4xzb2poTF0GA3ODA1pgECKELdxLyREqR25s3Ypu5ScMjFr5MPIbr+; Expires=Wed, 24 Jul 2024 18:47:22 GMT; Path=/",
"AWSALBTGCORS=n9jcQybr+cT0KsQjEvSYZMKQCZfBlgjJIlhK6RV/8Q89vMrJyHSahvKt01jrx5tjIKQFVNR3WRa5v3ZGpTBRp8lINg9r+qq3/KUMlIeVin01GIQXwh7h9Ml4xzb2poTF0GA3ODA1pgECKELdxLyREqR25s3Ypu5ScMjFr5MPIbr+; Expires=Wed, 24 Jul 2024 18:47:22 GMT; Path=/; SameSite=None; Secure",
"AWSALB=oNTocS64x+0+g2w2JD19o5HPnpaWp4TdY7781Jsj4tFxLjtujSNDQuUhJk5Va5mJSUUwewhvLJ4nQh1yMcsS2NAkRPaFYg1SEiN/ZmDtxwBQD8mf5aQyvjab6tNx; Expires=Wed, 24 Jul 2024 18:47:22 GMT; Path=/",
"AWSALBCORS=oNTocS64x+0+g2w2JD19o5HPnpaWp4TdY7781Jsj4tFxLjtujSNDQuUhJk5Va5mJSUUwewhvLJ4nQh1yMcsS2NAkRPaFYg1SEiN/ZmDtxwBQD8mf5aQyvjab6tNx; Expires=Wed, 24 Jul 2024 18:47:22 GMT; Path=/; SameSite=None; Secure"
],
"Server": [
"nginx"
],
"X-Cache": [
"Miss from cloudfront"
],
"Via": [
"1.1 f3ad6967905e6d2f0827e13dfa2c7d44.cloudfront.net (CloudFront)"
],
"X-Amz-Cf-Pop": [
"FOR50-P1"
],
"Alt-Svc": [
"h3=\":443\"; ma=86400"
],
"X-Amz-Cf-Id": [
"zyhesEV_gKg-x8dwQP_3XECrL5dxYVtOpQnrbQGiohy6CtaStSofZQ=="
]
},
"body": {
"string": "{\"object\":\"customer\",\"id\":\"cus_000006102042\",\"dateCreated\":\"2024-07-12\",\"name\":\"Karen Baldwin\",\"email\":null,\"company\":null,\"phone\":null,\"mobilePhone\":null,\"address\":null,\"addressNumber\":null,\"complement\":null,\"province\":null,\"postalCode\":null,\"cpfCnpj\":\"45890762338\",\"personType\":\"FISICA\",\"deleted\":true,\"additionalEmails\":null,\"externalReference\":null,\"notificationDisabled\":false,\"observations\":null,\"municipalInscription\":null,\"stateInscription\":null,\"canDelete\":false,\"cannotBeDeletedReason\":\"Cliente exclu\u00eddo, n\u00e3o \u00e9 poss\u00edvel fazer altera\u00e7\u00f5es.\",\"canEdit\":false,\"cannotEditReason\":\"Cliente exclu\u00eddo, n\u00e3o \u00e9 poss\u00edvel fazer altera\u00e7\u00f5es.\",\"city\":null,\"cityName\":null,\"state\":null,\"country\":\"Brasil\"}"
}
}
}
]
}
20 changes: 18 additions & 2 deletions tests/customer/test_asaas_customer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from asaaspy.schemas.customer import CustomerCreateSchema, CustomerSchema
from asaaspy.schemas.customer import CustomerCreateSchema, CustomerViewSchema
from asaaspy.service import AsaasService


Expand All @@ -10,7 +10,15 @@ def test_get_all_customers(self, asaas_svc):
all_customers = asaas_svc.customer.all()

assert all_customers.totalCount == 3
assert isinstance(all_customers.data[0], CustomerSchema)
assert isinstance(all_customers.data[0], CustomerViewSchema)

def test_get_customer(self, asaas_svc):
asaas_svc: AsaasService = asaas_svc

CUSTOMER_ID = "cus_000006102042"
customer = asaas_svc.customer.get(customer_id=CUSTOMER_ID)

assert customer.id == CUSTOMER_ID

@pytest.mark.parametrize(
"extra_params",
Expand All @@ -33,6 +41,14 @@ def test_create_customer(self, asaas_svc):

assert new_customer.id is not None

def test_create_customer_minimal(self, asaas_svc):
asaas_svc: AsaasService = asaas_svc

customer = CustomerCreateSchema(name="Empresa Apenas com o nome")
new_customer = asaas_svc.customer.create(customer)

assert new_customer.id.startswith("cus_")


class TestAsaasDeleteCustomer:
def test_delete(self, asaas_svc):
Expand Down

0 comments on commit 36fe3be

Please sign in to comment.