Skip to content

Commit

Permalink
Change auth logic based on newer ADR
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed Nov 6, 2024
1 parent 5e0f9d5 commit 204ca86
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 73 deletions.
15 changes: 0 additions & 15 deletions sinch/core/clients/sinch_client_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,6 @@ def _get_sms_domain_with_service_plan_id(self):
doc="SMS Domain for service plan id version of the SMS API"
)

def _set_sms_authentication_method(
self,
auth_type: str
) -> None:
self._sms_authentication = auth_type

def _get_sms_authentication_method(self) -> str:
return self._sms_authentication

sms_authentication_method = property(
_get_sms_authentication_method,
_set_sms_authentication_method,
doc="SMS Authentication method"
)

def _set_voice_origin(self):
if not self._voice_region:
self.voice_origin = self._voice_domain.format("calling")
Expand Down
11 changes: 3 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from sinch import SinchClient
from sinch import SinchClientAsync
from sinch.core.enums import HTTPAuthentication
from sinch.core.models.http_response import HTTPResponse
from sinch.domains.authentication.models.authentication import OAuthToken
from sinch.core.models.base_model import SinchBaseModel, SinchRequestBaseModel
Expand Down Expand Up @@ -342,7 +341,6 @@ def sinch_client_sync(
key_secret,
application_key,
application_secret,
service_plan_id,
sms_api_token,
numbers_origin,
conversation_origin,
Expand All @@ -361,7 +359,6 @@ def sinch_client_sync(
project_id=project_id,
application_key=application_key,
application_secret=application_secret,
service_plan_id=service_plan_id,
sms_api_token=sms_api_token
),
numbers_origin,
Expand All @@ -381,7 +378,6 @@ def sinch_client_async(
key_secret,
application_key,
application_secret,
service_plan_id,
sms_api_token,
numbers_origin,
conversation_origin,
Expand All @@ -400,7 +396,6 @@ def sinch_client_async(
project_id=project_id,
application_key=application_key,
application_secret=application_secret,
service_plan_id=service_plan_id,
sms_api_token=sms_api_token
),
numbers_origin,
Expand All @@ -415,6 +410,6 @@ def sinch_client_async(


@pytest.fixture
def sinch_client_sync_with_sms_token_authentication(sinch_client_sync):
sinch_client_sync.configuration.sms_authentication_method = HTTPAuthentication.SMS_TOKEN.value
return sinch_client_sync
def sinch_client_sync_with_service_plan_id(sinch_client_sync, service_plan_id):
sinch_client_sync.configuration.service_plan_id = service_plan_id
return sinch_client_sync
4 changes: 2 additions & 2 deletions tests/e2e/sms/batches/test_batch_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def test_send_sms_sync(sinch_client_sync, phone_number, origin_phone_number):


def test_send_sms_sync_with_service_plan_id(
sinch_client_sync_with_sms_token_authentication,
sinch_client_sync_with_service_plan_id,
phone_number,
origin_phone_number
):
send_sms_response = sinch_client_sync_with_sms_token_authentication.sms.batches.send(
send_sms_response = sinch_client_sync_with_service_plan_id.sms.batches.send(
delivery_report="none",
to=[phone_number],
from_=origin_phone_number,
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/batches/test_cancel_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def test_cancel_sms_batch(sinch_client_sync, phone_number, origin_phone_number):


def test_cancel_sms_batch_with_service_plan_id(
sinch_client_sync_with_sms_token_authentication,
sinch_client_sync_with_service_plan_id,
phone_number,
origin_phone_number
):
send_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.send(
send_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.send(
delivery_report="none",
to=[phone_number],
from_=origin_phone_number,
body="Synchronous Batch Cancel",
feedback_enabled=True,
send_at="2024-08-24T21:37:00Z"
)
cancel_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.cancel(
cancel_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.cancel(
batch_id=send_batch_response.id
)
assert isinstance(cancel_batch_response, CancelSMSBatchResponse)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/sms/batches/test_dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def test_send_sms_dry_run(sinch_client_sync, phone_number, origin_phone_number):


def test_send_sms_dry_run_with_service_plan_id(
sinch_client_sync_with_sms_token_authentication,
sinch_client_sync_with_service_plan_id,
phone_number,
origin_phone_number
):
send_dry_run_response = sinch_client_sync_with_sms_token_authentication.sms.batches.send_dry_run(
send_dry_run_response = sinch_client_sync_with_service_plan_id.sms.batches.send_dry_run(
number_of_recipients=10,
per_recipient=True,
to=[phone_number],
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/batches/test_get_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def test_get_sms_batch(sinch_client_sync):
assert isinstance(get_batch_response, GetSMSBatchResponse)


def test_get_sms_batch_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.list()
get_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.get(
def test_get_sms_batch_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.list()
get_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.get(
batch_id=list_batch_response.result.batches[0].id
)
assert isinstance(get_batch_response, GetSMSBatchResponse)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/sms/batches/test_list_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_list_sms_batches(sinch_client_sync):
assert isinstance(list_batches_response, IntBasedPaginator)


def test_list_sms_batches_using_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_batches_response = sinch_client_sync_with_sms_token_authentication.sms.batches.list()
def test_list_sms_batches_using_service_plan_id(sinch_client_sync_with_service_plan_id):
list_batches_response = sinch_client_sync_with_service_plan_id.sms.batches.list()
assert isinstance(list_batches_response, IntBasedPaginator)
assert len(list_batches_response.result.batches) > 0

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/batches/test_replace_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def test_replace_sms_batch(sinch_client_sync, phone_number):


def test_replace_sms_batch_with_service_plan_id(
sinch_client_sync_with_sms_token_authentication,
sinch_client_sync_with_service_plan_id,
phone_number
):
list_batches_response = sinch_client_sync_with_sms_token_authentication.sms.batches.list(
list_batches_response = sinch_client_sync_with_service_plan_id.sms.batches.list(
start_date="2022-11-24T14:15:22Z"
)
replace_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.replace(
replace_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.replace(
batch_id=list_batches_response.result.batches[0].id,
to=[phone_number],
body="Replace SMS batch test"
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/batches/test_send_delivery_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test_send_delivery_feedback(sinch_client_sync, phone_number):
assert isinstance(delivery_feedback_response, SendSMSDeliveryFeedbackResponse)


def test_send_delivery_feedback_with_service_plan_id(sinch_client_sync_with_sms_token_authentication, phone_number):
list_batches_response = sinch_client_sync_with_sms_token_authentication.sms.batches.list()
delivery_feedback_response = sinch_client_sync_with_sms_token_authentication.sms.batches.send_delivery_feedback(
def test_send_delivery_feedback_with_service_plan_id(sinch_client_sync_with_service_plan_id, phone_number):
list_batches_response = sinch_client_sync_with_service_plan_id.sms.batches.list()
delivery_feedback_response = sinch_client_sync_with_service_plan_id.sms.batches.send_delivery_feedback(
batch_id=list_batches_response.result.batches[0].id,
recipients=[phone_number]
)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/batches/test_update_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@


def test_update_sms_batch_with_service_plan_id(
sinch_client_sync_with_sms_token_authentication,
sinch_client_sync_with_service_plan_id,
phone_number,
origin_phone_number
):
send_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.send(
send_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.send(
delivery_report="none",
to=[phone_number],
from_=origin_phone_number,
body="Update Batch Test",
feedback_enabled=True,
send_at="2024-12-01T21:37:00Z"
)
update_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.update(
update_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.update(
batch_id=send_batch_response.id,
body="Update Batch Test After Update"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def test_get_delivery_reports_for_specific_batch(sinch_client_sync, phone_number


def test_get_delivery_reports_for_specific_batch_with_service_plan_id(
sinch_client_sync_with_sms_token_authentication,
sinch_client_sync_with_service_plan_id,
phone_number,
origin_phone_number
):
send_batch_response = sinch_client_sync_with_sms_token_authentication.sms.batches.send(
send_batch_response = sinch_client_sync_with_service_plan_id.sms.batches.send(
delivery_report="summary",
to=[phone_number],
from_=origin_phone_number,
body="Delivery report test.",
feedback_enabled=True,
callback_url="http://testcallback.pl"
)
get_delivery_report_response = sinch_client_sync_with_sms_token_authentication.sms.delivery_reports.get_for_batch(
get_delivery_report_response = sinch_client_sync_with_service_plan_id.sms.delivery_reports.get_for_batch(
batch_id=send_batch_response.id,
type_="summary",
status=["Queued"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def test_get_delivery_reports_for_specific_number(sinch_client_sync):
assert isinstance(get_delivery_report_response, GetSMSDeliveryReportForNumberResponse)


def test_get_delivery_reports_for_specific_number_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_delivery_reports_response = sinch_client_sync_with_sms_token_authentication.sms.delivery_reports.list(
def test_get_delivery_reports_for_specific_number_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_delivery_reports_response = sinch_client_sync_with_service_plan_id.sms.delivery_reports.list(
start_date="2019-08-24T14:15:22Z"
)
assert isinstance(list_delivery_reports_response.result, ListSMSDeliveryReportsResponse)

get_delivery_report_response = sinch_client_sync_with_sms_token_authentication.sms.delivery_reports.get_for_number(
get_delivery_report_response = sinch_client_sync_with_service_plan_id.sms.delivery_reports.get_for_number(
batch_id=list_delivery_reports_response.result.delivery_reports[0].batch_id,
recipient_number=list_delivery_reports_response.result.delivery_reports[0].recipient
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def test_get_delivery_reports_for_project(sinch_client_sync):
assert isinstance(list_delivery_reports_response.result, ListSMSDeliveryReportsResponse)


def test_get_delivery_reports_for_project_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_delivery_reports_response = sinch_client_sync_with_sms_token_authentication.sms.delivery_reports.list(
def test_get_delivery_reports_for_project_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_delivery_reports_response = sinch_client_sync_with_service_plan_id.sms.delivery_reports.list(
start_date="2019-08-24T14:15:22Z"
)
assert isinstance(list_delivery_reports_response.result, ListSMSDeliveryReportsResponse)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/sms/groups/test_create_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def test_create_sms_group(sinch_client_sync, phone_number):
assert isinstance(create_group_response, CreateSMSGroupResponse)


def test_create_sms_group_with_service_plan_id(sinch_client_sync_with_sms_token_authentication, phone_number):
create_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.create(
def test_create_sms_group_with_service_plan_id(sinch_client_sync_with_service_plan_id, phone_number):
create_group_response = sinch_client_sync_with_service_plan_id.sms.groups.create(
name="KillerRabbit",
members=[phone_number]
)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/groups/test_delete_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def test_delete_sms_group(sinch_client_sync):
assert isinstance(delete_group_response, SinchDeleteSMSGroupResponse)


def test_delete_sms_group_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.list()
def test_delete_sms_group_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_group_response = sinch_client_sync_with_service_plan_id.sms.groups.list()

delete_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.delete(
delete_group_response = sinch_client_sync_with_service_plan_id.sms.groups.delete(
group_id=list_group_response.result.groups[0].id
)
assert isinstance(delete_group_response, SinchDeleteSMSGroupResponse)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/groups/test_get_group.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from sinch.domains.sms.models.groups.responses import GetSMSGroupResponse


def test_get_sms_group_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.list()
def test_get_sms_group_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_group_response = sinch_client_sync_with_service_plan_id.sms.groups.list()

get_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.get(
get_group_response = sinch_client_sync_with_service_plan_id.sms.groups.get(
group_id=list_group_response.result.groups[0].id
)
assert isinstance(get_group_response, GetSMSGroupResponse)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/groups/test_get_phone_numbers_for_group.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from sinch.domains.sms.models.groups.responses import SinchGetSMSGroupPhoneNumbersResponse


def test_get_group_phone_numbers_sms_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.list()
def test_get_group_phone_numbers_sms_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_group_response = sinch_client_sync_with_service_plan_id.sms.groups.list()

get_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.get_group_phone_numbers(
get_group_response = sinch_client_sync_with_service_plan_id.sms.groups.get_group_phone_numbers(
group_id=list_group_response.result.groups[0].id
)

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/sms/groups/test_list_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_list_sms_groups(sinch_client_sync):
assert isinstance(list_group_response.result, SinchListSMSGroupResponse)


def test_list_sms_groups_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.list()
def test_list_sms_groups_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_group_response = sinch_client_sync_with_service_plan_id.sms.groups.list()
assert isinstance(list_group_response.result, SinchListSMSGroupResponse)


Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/groups/test_replace_group.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from sinch.domains.sms.models.groups.responses import ReplaceSMSGroupResponse


def test_replace_sms_group_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.list()
def test_replace_sms_group_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_group_response = sinch_client_sync_with_service_plan_id.sms.groups.list()

replace_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.replace(
replace_group_response = sinch_client_sync_with_service_plan_id.sms.groups.replace(
group_id=list_group_response.result.groups[0].id,
members=["48111111111"]
)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/sms/groups/test_update_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def test_update_sms_group(sinch_client_sync, phone_number):
assert update_group_response.name == "KillerRabbit222"


def test_update_sms_group_with_service_plan_id(sinch_client_sync_with_sms_token_authentication, phone_number):
list_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.list()
def test_update_sms_group_with_service_plan_id(sinch_client_sync_with_service_plan_id, phone_number):
list_group_response = sinch_client_sync_with_service_plan_id.sms.groups.list()

update_group_response = sinch_client_sync_with_sms_token_authentication.sms.groups.update(
update_group_response = sinch_client_sync_with_service_plan_id.sms.groups.update(
name="KillerRabbit222",
group_id=list_group_response.result.groups[0].id
)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/sms/inbounds/test_list_inbound_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def test_list_inbound_sms(sinch_client_sync):
assert isinstance(list_incoming_message_response.result, SinchListInboundMessagesResponse)


def test_list_inbound_sms_with_service_plan_id(sinch_client_sync_with_sms_token_authentication):
list_incoming_message_response = sinch_client_sync_with_sms_token_authentication.sms.inbounds.list()
def test_list_inbound_sms_with_service_plan_id(sinch_client_sync_with_service_plan_id):
list_incoming_message_response = sinch_client_sync_with_service_plan_id.sms.inbounds.list()
assert isinstance(list_incoming_message_response.result, SinchListInboundMessagesResponse)


Expand Down

0 comments on commit 204ca86

Please sign in to comment.