Skip to content

Commit

Permalink
feat(Verfication): DTO improved
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed Jan 22, 2024
1 parent 79da667 commit 3b1c765
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 38 deletions.
11 changes: 10 additions & 1 deletion sinch/domains/verification/endpoints/get_verification_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@ def build_url(self, sinch):
def handle_response(self, response: HTTPResponse) -> GetVerificationStatusByIdResponse:
super().handle_response(response)
return GetVerificationStatusByIdResponse(
**response.body
id=response.body.get("id"),
method=response.body.get("method"),
status=response.body.get("status"),
price=response.body.get("price"),
identity=response.body.get("identity"),
country_id=response.body.get("country_id"),
verification_timestamp=response.body.get("verification_timestamp"),
reference=response.body.get("reference"),
reason=response.body.get("reason"),
call_complete=response.body.get("call_complete")
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ def build_url(self, sinch):
def handle_response(self, response: HTTPResponse) -> GetVerificationStatusByIdentityResponse:
super().handle_response(response)
return GetVerificationStatusByIdentityResponse(
**response.body
id=response.body.get("id"),
method=response.body.get("method"),
status=response.body.get("status"),
price=response.body.get("price"),
identity=response.body.get("identity"),
country_id=response.body.get("country_id"),
verification_timestamp=response.body.get("verification_timestamp"),
reference=response.body.get("reference"),
reason=response.body.get("reason"),
call_complete=response.body.get("call_complete")
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@ def build_url(self, sinch):
def handle_response(self, response: HTTPResponse) -> GetVerificationStatusByReferenceResponse:
super().handle_response(response)
return GetVerificationStatusByReferenceResponse(
**response.body
id=response.body.get("id"),
method=response.body.get("method"),
status=response.body.get("status"),
price=response.body.get("price"),
identity=response.body.get("identity"),
country_id=response.body.get("country_id"),
verification_timestamp=response.body.get("verification_timestamp"),
reference=response.body.get("reference"),
reason=response.body.get("reason"),
call_complete=response.body.get("call_complete")
)
8 changes: 7 additions & 1 deletion sinch/domains/verification/endpoints/start_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ def request_body(self):

def handle_response(self, response: HTTPResponse) -> StartVerificationResponse:
return StartVerificationResponse(
**response.body
id=response.body.get("id"),
method=response.body.get("method"),
_links=response.body.get("_links"),
sms=response.body.get("sms"),
flash_call=response.body.get("flashCall"),
callout=response.body.get("callout"),
seamless=response.body.get("seamless"),
)
9 changes: 9 additions & 0 deletions sinch/domains/verification/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ class VerificationMethod(Enum):
FLASHCALL = "flashCall"
CALLOUT = "callout"
SEAMLESS = "seamless"


class VerificationStatus(Enum):
PENDING = "PENDING"
SUCCESSFUL = "SUCCESSFUL"
FAIL = "FAIL"
DENIED = "DENIED"
ABORTED = "ABORTED"
ERROR = "ERROR"
16 changes: 11 additions & 5 deletions sinch/domains/verification/models/responses.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from dataclasses import dataclass
from sinch.core.models.base_model import SinchBaseModel
from sinch.domains.verification.enums import VerificationMethod
from sinch.domains.verification.enums import VerificationMethod, VerificationStatus
from typing import Optional


@dataclass
class StartVerificationResponse(SinchBaseModel):
id: str
method: VerificationMethod
sms: dict
_links: list
sms: Optional[dict] = None
flash_call: Optional[dict] = None
callout: Optional[dict] = None
seamless: Optional[dict] = None


@dataclass
class VerificationResponse(SinchBaseModel):
id: str
method: VerificationMethod
status: str
status: VerificationStatus
price: dict
identity: str
countryId: str
verificationTimestamp: str
country_id: str
verification_timestamp: str
reference: str
reason: str
call_complete: bool


@dataclass
Expand Down
36 changes: 8 additions & 28 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,34 +276,6 @@ def second_int_based_pagination_response():
)


@pytest.fixture
def int_based_pagination_request_data():
return IntBasedPaginationRequest(
page=0,
page_size=2
)


@pytest.fixture
def first_int_based_pagination_response():
return IntBasedPaginationResponse(
count=4,
page=0,
page_size=2,
pig_dogs=["Bartosz", "Piotr"]
)


@pytest.fixture
def second_int_based_pagination_response():
return IntBasedPaginationResponse(
count=4,
page=1,
page_size=2,
pig_dogs=["Walaszek", "Połać"]
)


@pytest.fixture
def third_int_based_pagination_response():
return IntBasedPaginationResponse(
Expand All @@ -314,6 +286,14 @@ def third_int_based_pagination_response():
)


@pytest.fixture
def int_based_pagination_request_data():
return IntBasedPaginationRequest(
page=0,
page_size=2
)


@pytest.fixture
def sinch_client_sync(
key_id,
Expand Down
18 changes: 17 additions & 1 deletion tests/e2e/verification/test_start_verification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sinch.domains.verification.models.responses import StartVerificationResponse


def test_start_verification(
def test_start_verification_sms(
sinch_client_sync,
phone_number
):
Expand All @@ -17,6 +17,22 @@ def test_start_verification(
assert isinstance(verification_response, StartVerificationResponse)


def test_start_verification_flash_call(
sinch_client_sync,
phone_number
):
verification_response = sinch_client_sync.verification.verifications.start(
method="flashCall",
identity={
"type": "number",
"endpoint": phone_number
},
reference="random5"
)

assert isinstance(verification_response, StartVerificationResponse)


async def test_start_verification_async(
sinch_client_async,
phone_number
Expand Down

0 comments on commit 3b1c765

Please sign in to comment.