Skip to content

Commit

Permalink
test(SMS): test credentials formatting for different APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed Dec 11, 2024
1 parent 676c507 commit 35da17a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sinch import SinchClient
from sinch import SinchClientAsync
from sinch.core.models.http_response import HTTPResponse
from sinch.core.models.http_request import HttpRequest
from sinch.domains.authentication.models.authentication import OAuthToken
from sinch.core.models.base_model import SinchBaseModel, SinchRequestBaseModel

Expand Down Expand Up @@ -215,6 +216,19 @@ def verification_request_signature_timestamp():
return os.getenv("VERIFICATION_REQUEST_SIGNATURE_TIMESTAMP")


@pytest.fixture
def empty_http_request():
return HttpRequest(
headers={},
protocol=None,
http_method=None,
request_body=None,
query_params=None,
url=None,
auth=None
)


@pytest.fixture
def http_response():
return HTTPResponse(
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/test_http_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from sinch.core.adapters.requests_http_transport import HTTPTransportRequests
from sinch.domains.sms.endpoints.sms_endpoint import SMSEndpoint
from sinch.core.enums import HTTPAuthentication


def test_authenticate_method_with_service_plan_id_version_of_sms_api(
sinch_client_sync_with_service_plan_id,
empty_http_request
):
sms_endpoint = SMSEndpoint(
sinch=sinch_client_sync_with_service_plan_id,
request_data=empty_http_request
)
http_transport = HTTPTransportRequests(sinch=sinch_client_sync_with_service_plan_id)
http_transport.authenticate(endpoint=sms_endpoint, request_data=empty_http_request)

assert empty_http_request.headers
assert "Bearer" in empty_http_request.headers["Authorization"]
assert empty_http_request.headers["Content-Type"] == "application/json"


def test_authenticate_method_with_project_id_version_of_sms_api(
sinch_client_sync,
empty_http_request
):
sms_endpoint = SMSEndpoint(
sinch=sinch_client_sync,
request_data=empty_http_request,
)
sms_endpoint.HTTP_AUTHENTICATION = HTTPAuthentication.OAUTH.value
http_transport = HTTPTransportRequests(sinch=sinch_client_sync)
http_transport.authenticate(endpoint=sms_endpoint, request_data=empty_http_request)

assert empty_http_request.headers
assert "Bearer" in empty_http_request.headers["Authorization"]
assert empty_http_request.headers["Content-Type"] == "application/json"
23 changes: 23 additions & 0 deletions tests/integration/test_sms_endpoint_credendials_formatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from sinch.domains.sms.endpoints.sms_endpoint import SMSEndpoint
from sinch.core.enums import HTTPAuthentication


def test_sms_endpoint_service_plan_id_credentials_processing(sinch_client_sync_with_service_plan_id, service_plan_id):
sms_endpoint = SMSEndpoint(
sinch=sinch_client_sync_with_service_plan_id,
request_data={}
)
assert sms_endpoint.project_or_service_id == service_plan_id
assert sms_endpoint.HTTP_AUTHENTICATION == HTTPAuthentication.SMS_TOKEN.value
assert (
sms_endpoint.sms_origin == sinch_client_sync_with_service_plan_id.configuration._sms_origin_with_service_plan_id
)


def test_sms_endpoint_with_project_id_credentials_processing(sinch_client_sync, project_id):
sms_endpoint = SMSEndpoint(
sinch=sinch_client_sync,
request_data={}
)
assert sms_endpoint.project_or_service_id == project_id
assert sms_endpoint.sms_origin == sinch_client_sync.configuration.sms_origin

0 comments on commit 35da17a

Please sign in to comment.