From 3b1c76519c5889ef6ee425ffe89a3bd8bf0af40c Mon Sep 17 00:00:00 2001 From: 650elx Date: Mon, 22 Jan 2024 09:38:07 +0100 Subject: [PATCH] feat(Verfication): DTO improved --- .../endpoints/get_verification_by_id.py | 11 +++++- .../endpoints/get_verification_by_identity.py | 11 +++++- .../get_verification_by_reference.py | 11 +++++- .../endpoints/start_verification.py | 8 ++++- sinch/domains/verification/enums.py | 9 +++++ .../domains/verification/models/responses.py | 16 ++++++--- tests/conftest.py | 36 +++++-------------- .../verification/test_start_verification.py | 18 +++++++++- 8 files changed, 82 insertions(+), 38 deletions(-) diff --git a/sinch/domains/verification/endpoints/get_verification_by_id.py b/sinch/domains/verification/endpoints/get_verification_by_id.py index 4dd2a2c..131e1e7 100644 --- a/sinch/domains/verification/endpoints/get_verification_by_id.py +++ b/sinch/domains/verification/endpoints/get_verification_by_id.py @@ -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") ) diff --git a/sinch/domains/verification/endpoints/get_verification_by_identity.py b/sinch/domains/verification/endpoints/get_verification_by_identity.py index 3612efb..88008df 100644 --- a/sinch/domains/verification/endpoints/get_verification_by_identity.py +++ b/sinch/domains/verification/endpoints/get_verification_by_identity.py @@ -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") ) diff --git a/sinch/domains/verification/endpoints/get_verification_by_reference.py b/sinch/domains/verification/endpoints/get_verification_by_reference.py index 944b417..3a5115b 100644 --- a/sinch/domains/verification/endpoints/get_verification_by_reference.py +++ b/sinch/domains/verification/endpoints/get_verification_by_reference.py @@ -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") ) diff --git a/sinch/domains/verification/endpoints/start_verification.py b/sinch/domains/verification/endpoints/start_verification.py index 0508ff8..2770367 100644 --- a/sinch/domains/verification/endpoints/start_verification.py +++ b/sinch/domains/verification/endpoints/start_verification.py @@ -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"), ) diff --git a/sinch/domains/verification/enums.py b/sinch/domains/verification/enums.py index 38dc5f2..8ba9441 100644 --- a/sinch/domains/verification/enums.py +++ b/sinch/domains/verification/enums.py @@ -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" diff --git a/sinch/domains/verification/models/responses.py b/sinch/domains/verification/models/responses.py index 22708fb..a77289c 100644 --- a/sinch/domains/verification/models/responses.py +++ b/sinch/domains/verification/models/responses.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 6b84ada..a7cb74f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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( @@ -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, diff --git a/tests/e2e/verification/test_start_verification.py b/tests/e2e/verification/test_start_verification.py index 2456f88..79169f1 100644 --- a/tests/e2e/verification/test_start_verification.py +++ b/tests/e2e/verification/test_start_verification.py @@ -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 ): @@ -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