From 6008291dd918ed50cbf88965b7f491910292e8cc Mon Sep 17 00:00:00 2001 From: 650elx Date: Mon, 4 Mar 2024 16:46:37 +0100 Subject: [PATCH 1/7] fix(Verification): missing super call added --- .../endpoints/start_verification.py | 1 + .../e2e/verification/test_start_verification.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/sinch/domains/verification/endpoints/start_verification.py b/sinch/domains/verification/endpoints/start_verification.py index 5902203..1d380de 100644 --- a/sinch/domains/verification/endpoints/start_verification.py +++ b/sinch/domains/verification/endpoints/start_verification.py @@ -29,6 +29,7 @@ def request_body(self): return self.request_data.as_json() def handle_response(self, response: HTTPResponse) -> StartVerificationResponse: + super().handle_response(response) if self.request_data.method == VerificationMethod.SMS.value: return StartSMSInitiateVerificationResponse( **response.body diff --git a/tests/e2e/verification/test_start_verification.py b/tests/e2e/verification/test_start_verification.py index da3dfb2..915238b 100644 --- a/tests/e2e/verification/test_start_verification.py +++ b/tests/e2e/verification/test_start_verification.py @@ -1,8 +1,10 @@ +pytest from sinch.domains.verification.models.responses import ( StartSMSInitiateVerificationResponse, StartFlashCallInitiateVerificationResponse ) from sinch.domains.verification.enums import VerificationMethod +from sinch.domains.verification.exceptions import VerificationException def test_start_verification_sms( @@ -21,6 +23,21 @@ def test_start_verification_sms( assert isinstance(verification_response, StartSMSInitiateVerificationResponse) +def test_start_verification_sms_malformed_phone_number( + sinch_client_sync, + phone_number +): + with pytest.raises(VerificationException): + verification_response = sinch_client_sync.verification.verifications.start( + method="sms", + identity={ + "type": "number", + "endpoint": "abcd" + phone_number + "abcd" + }, + reference="random" + ) + + def test_start_verification_flash_call( sinch_client_sync, phone_number From 6648fda0d64d7a563d740b10c52f05da3caa4916 Mon Sep 17 00:00:00 2001 From: 650elx Date: Tue, 5 Mar 2024 16:15:32 +0100 Subject: [PATCH 2/7] fix(Verification): test case for malformed phone number added --- tests/e2e/verification/test_start_verification.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/verification/test_start_verification.py b/tests/e2e/verification/test_start_verification.py index 915238b..beee465 100644 --- a/tests/e2e/verification/test_start_verification.py +++ b/tests/e2e/verification/test_start_verification.py @@ -1,4 +1,4 @@ -pytest +import pytest from sinch.domains.verification.models.responses import ( StartSMSInitiateVerificationResponse, StartFlashCallInitiateVerificationResponse @@ -27,8 +27,8 @@ def test_start_verification_sms_malformed_phone_number( sinch_client_sync, phone_number ): - with pytest.raises(VerificationException): - verification_response = sinch_client_sync.verification.verifications.start( + with pytest.raises(VerificationException) as err: + sinch_client_sync.verification.verifications.start( method="sms", identity={ "type": "number", @@ -36,6 +36,7 @@ def test_start_verification_sms_malformed_phone_number( }, reference="random" ) + assert "invalid" in err.value.http_response.body["message"] def test_start_verification_flash_call( From f3c58edda6d3e9d593717f4b29b2fc5131bdd097 Mon Sep 17 00:00:00 2001 From: 650elx Date: Tue, 5 Mar 2024 16:33:29 +0100 Subject: [PATCH 3/7] feat(Client): make oauth parameters optional --- sinch/core/clients/sinch_client_async.py | 10 +++++----- sinch/core/clients/sinch_client_base.py | 10 +++++----- sinch/core/clients/sinch_client_sync.py | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sinch/core/clients/sinch_client_async.py b/sinch/core/clients/sinch_client_async.py index a32a223..6eb18cc 100644 --- a/sinch/core/clients/sinch_client_async.py +++ b/sinch/core/clients/sinch_client_async.py @@ -17,11 +17,11 @@ class ClientAsync(ClientBase): """ def __init__( self, - key_id, - key_secret, - project_id, - logger_name=None, - logger=None, + key_id: str = None, + key_secret: str = None, + project_id: str = None, + logger_name: str = None, + logger: str = None, application_key: str = None, application_secret: str = None ): diff --git a/sinch/core/clients/sinch_client_base.py b/sinch/core/clients/sinch_client_base.py index 7f53fd0..657bc15 100644 --- a/sinch/core/clients/sinch_client_base.py +++ b/sinch/core/clients/sinch_client_base.py @@ -21,11 +21,11 @@ class ClientBase(ABC): @abstractmethod def __init__( self, - key_id, - key_secret, - project_id, - logger_name=None, - logger=None, + key_id: str = None, + key_secret: str = None, + project_id: str = None, + logger_name: str = None, + logger: str = None, application_key: str = None, application_secret: str = None ): diff --git a/sinch/core/clients/sinch_client_sync.py b/sinch/core/clients/sinch_client_sync.py index 0ec939c..c999a6c 100644 --- a/sinch/core/clients/sinch_client_sync.py +++ b/sinch/core/clients/sinch_client_sync.py @@ -17,11 +17,11 @@ class Client(ClientBase): """ def __init__( self, - key_id, - key_secret, - project_id, - logger_name=None, - logger=None, + key_id: str = None, + key_secret: str = None, + project_id: str = None, + logger_name: str = None, + logger: str = None, application_key: str = None, application_secret: str = None ): From 21dc00ad3edec8e7932c4c91b1bcc8d740b131a9 Mon Sep 17 00:00:00 2001 From: 650elx Date: Tue, 5 Mar 2024 17:29:43 +0100 Subject: [PATCH 4/7] fix(repr): adopt repr to the current state of the class --- sinch/core/clients/sinch_client_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sinch/core/clients/sinch_client_base.py b/sinch/core/clients/sinch_client_base.py index 657bc15..ad846c8 100644 --- a/sinch/core/clients/sinch_client_base.py +++ b/sinch/core/clients/sinch_client_base.py @@ -32,4 +32,4 @@ def __init__( pass def __repr__(self): - return f"Sinch SDK client for project_id: {self.configuration.project_id}" + return "Sinch SDK client" From a9c7bcca33d451403b04c74eea964462d1a5cb3d Mon Sep 17 00:00:00 2001 From: 650elx Date: Tue, 12 Mar 2024 11:47:45 +0100 Subject: [PATCH 5/7] fix(Logging): Logger type for logger instance added --- sinch/core/clients/sinch_client_async.py | 3 ++- sinch/core/clients/sinch_client_configuration.py | 3 ++- sinch/core/clients/sinch_client_sync.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sinch/core/clients/sinch_client_async.py b/sinch/core/clients/sinch_client_async.py index 6eb18cc..aab97e5 100644 --- a/sinch/core/clients/sinch_client_async.py +++ b/sinch/core/clients/sinch_client_async.py @@ -1,3 +1,4 @@ +from logging import Logger from sinch.core.clients.sinch_client_base import ClientBase from sinch.core.clients.sinch_client_configuration import Configuration from sinch.core.token_manager import TokenManagerAsync @@ -21,7 +22,7 @@ def __init__( key_secret: str = None, project_id: str = None, logger_name: str = None, - logger: str = None, + logger: Logger = None, application_key: str = None, application_secret: str = None ): diff --git a/sinch/core/clients/sinch_client_configuration.py b/sinch/core/clients/sinch_client_configuration.py index 74f0931..b087898 100644 --- a/sinch/core/clients/sinch_client_configuration.py +++ b/sinch/core/clients/sinch_client_configuration.py @@ -1,4 +1,5 @@ import logging +from logging import Logger from typing import Union from sinch.core.ports.http_transport import HTTPTransport @@ -16,7 +17,7 @@ def __init__( project_id: str, transport: HTTPTransport, token_manager: Union[TokenManager, TokenManagerAsync], - logger=None, + logger: Logger = None, logger_name: str = None, disable_https=False, connection_timeout=10, diff --git a/sinch/core/clients/sinch_client_sync.py b/sinch/core/clients/sinch_client_sync.py index c999a6c..5e81b78 100644 --- a/sinch/core/clients/sinch_client_sync.py +++ b/sinch/core/clients/sinch_client_sync.py @@ -1,3 +1,4 @@ +from logging import Logger from sinch.core.clients.sinch_client_base import ClientBase from sinch.core.clients.sinch_client_configuration import Configuration from sinch.core.token_manager import TokenManager @@ -21,7 +22,7 @@ def __init__( key_secret: str = None, project_id: str = None, logger_name: str = None, - logger: str = None, + logger: Logger = None, application_key: str = None, application_secret: str = None ): From f80c47d5577ded6671116f320d37262f4f736401 Mon Sep 17 00:00:00 2001 From: 650elx Date: Tue, 12 Mar 2024 14:43:48 +0100 Subject: [PATCH 6/7] fix(Logging): proper type for logger --- sinch/core/clients/sinch_client_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sinch/core/clients/sinch_client_base.py b/sinch/core/clients/sinch_client_base.py index ad846c8..45d6754 100644 --- a/sinch/core/clients/sinch_client_base.py +++ b/sinch/core/clients/sinch_client_base.py @@ -1,3 +1,4 @@ +from logging import Logger from abc import ABC, abstractmethod from sinch.core.clients.sinch_client_configuration import Configuration from sinch.domains.authentication import AuthenticationBase @@ -25,7 +26,7 @@ def __init__( key_secret: str = None, project_id: str = None, logger_name: str = None, - logger: str = None, + logger: Logger = None, application_key: str = None, application_secret: str = None ): From f897bdbac40f6a1ea9ec0c8b4768028aa4f76f75 Mon Sep 17 00:00:00 2001 From: 650elx Date: Tue, 12 Mar 2024 14:51:57 +0100 Subject: [PATCH 7/7] Revert "Merge branch 'fix_start_verification_response_handling' into devexp-323-make-client-oauth-params-optional" This reverts commit 61289a07e1e4aea761fdc31beb61b735d75d8f56, reversing changes made to 21dc00ad3edec8e7932c4c91b1bcc8d740b131a9. --- .../endpoints/start_verification.py | 1 - .../verification/test_start_verification.py | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/sinch/domains/verification/endpoints/start_verification.py b/sinch/domains/verification/endpoints/start_verification.py index 1d380de..5902203 100644 --- a/sinch/domains/verification/endpoints/start_verification.py +++ b/sinch/domains/verification/endpoints/start_verification.py @@ -29,7 +29,6 @@ def request_body(self): return self.request_data.as_json() def handle_response(self, response: HTTPResponse) -> StartVerificationResponse: - super().handle_response(response) if self.request_data.method == VerificationMethod.SMS.value: return StartSMSInitiateVerificationResponse( **response.body diff --git a/tests/e2e/verification/test_start_verification.py b/tests/e2e/verification/test_start_verification.py index beee465..da3dfb2 100644 --- a/tests/e2e/verification/test_start_verification.py +++ b/tests/e2e/verification/test_start_verification.py @@ -1,10 +1,8 @@ -import pytest from sinch.domains.verification.models.responses import ( StartSMSInitiateVerificationResponse, StartFlashCallInitiateVerificationResponse ) from sinch.domains.verification.enums import VerificationMethod -from sinch.domains.verification.exceptions import VerificationException def test_start_verification_sms( @@ -23,22 +21,6 @@ def test_start_verification_sms( assert isinstance(verification_response, StartSMSInitiateVerificationResponse) -def test_start_verification_sms_malformed_phone_number( - sinch_client_sync, - phone_number -): - with pytest.raises(VerificationException) as err: - sinch_client_sync.verification.verifications.start( - method="sms", - identity={ - "type": "number", - "endpoint": "abcd" + phone_number + "abcd" - }, - reference="random" - ) - assert "invalid" in err.value.http_response.body["message"] - - def test_start_verification_flash_call( sinch_client_sync, phone_number