diff --git a/tests/conftest.py b/tests/conftest.py index 152ad5b..7036a44 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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( diff --git a/tests/integration/test_http_transport.py b/tests/integration/test_http_transport.py new file mode 100644 index 0000000..de792f4 --- /dev/null +++ b/tests/integration/test_http_transport.py @@ -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" diff --git a/tests/integration/test_sms_endpoint_credendials_formatting.py b/tests/integration/test_sms_endpoint_credendials_formatting.py new file mode 100644 index 0000000..70fd6e1 --- /dev/null +++ b/tests/integration/test_sms_endpoint_credendials_formatting.py @@ -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