Skip to content

Commit 23cfc25

Browse files
committed
DEVEXP-758: SinchClient Configuration
- Update unit tests to validate all credentials - Update README to explain which credentials must be set for each API Signed-off-by: Jessica Matsuoka <jessica.akemi.matsuoka@sinch.com>
1 parent 8cc9299 commit 23cfc25

File tree

3 files changed

+93
-31
lines changed

3 files changed

+93
-31
lines changed

README.md

+35-18
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,64 @@ For more information on the Sinch APIs on which this SDK is based, refer to the
3333
You can install this package by typing:
3434
`pip install sinch`
3535

36+
## Products
37+
38+
Sinch client provides access to the following Sinch products:
39+
- Numbers
40+
- SMS
41+
- Verification
42+
- Voice API
43+
- Conversation API (beta release)
44+
45+
3646
## Getting started
3747

48+
3849
### Client initialization
3950

4051

41-
To initialize communication with Sinch backed, credentials obtained from Sinch portal have to be provided to the main client class of this SDK.
42-
It's highly advised to not hardcode those credentials, but to fetch them from environment variables:
52+
To establish a connection with the Sinch backend, you must provide the appropriate credentials based on the API
53+
you intend to use. For security best practices, avoid hardcoding credentials.
54+
Instead, retrieve them from environment variables.
55+
56+
#### Verification and Voice APIs
57+
58+
To initialize the client for the **Verification** and **Voice** APIs, use the following credentials:
4359

4460
```python
4561
from sinch import SinchClient
4662

4763
sinch_client = SinchClient(
48-
key_id="key_id",
49-
key_secret="key_secret",
50-
project_id="some_project",
5164
application_key="application_key",
5265
application_secret="application_secret"
5366
)
5467
```
5568

69+
#### SMS API
70+
For the SMS API in **Australia (AU)**, **Brazil (BR)**, **Canada (CA)**, **the United States (US)**,
71+
and **the European Union (EU)**, provide the following parameters:
72+
5673
```python
57-
import os
5874
from sinch import SinchClient
5975

6076
sinch_client = SinchClient(
61-
key_id=os.getenv("KEY_ID"),
62-
key_secret=os.getenv("KEY_SECRET"),
63-
project_id=os.getenv("PROJECT_ID"),
64-
application_key=os.getenv("APPLICATION_KEY"),
65-
application_secret=os.getenv("APPLICATION_SECRET")
77+
service_plan_id="service_plan_id",
78+
sms_api_token="api_token"
6679
)
6780
```
6881

69-
## Products
82+
#### All Other Sinch APIs
83+
For all other Sinch APIs, including SMS in US and EU regions, use the following parameters:
7084

71-
Sinch client provides access to the following Sinch products:
72-
- Numbers
73-
- SMS
74-
- Verification
75-
- Voice API
76-
- Conversation API (beta release)
85+
```python
86+
from sinch import SinchClient
87+
88+
sinch_client = SinchClient(
89+
key_id="key_id",
90+
key_secret="key_secret",
91+
project_id="project_id",
92+
)
93+
```
7794

7895
## Logging
7996

tests/unit/test_client.py

+18
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,36 @@ def test_sinch_client_async_initialization():
2020
assert sinch_client_async
2121

2222

23+
def test_sinch_client_empty_expects_initialization():
24+
""" Test that SinchClient can be initialized with no parameters """
25+
sinch_client_sync = SinchClient()
26+
assert sinch_client_sync
27+
28+
29+
def test_sinch_client_async_empty_expects_initialization():
30+
""" Test that SinchClientAsync can be initialized with no parameters """
31+
sinch_client_async = SinchClientAsync()
32+
assert sinch_client_async
33+
34+
2335
def test_sinch_client_has_all_business_domains(sinch_client_sync):
36+
""" Test that SinchClient has all domains """
2437
assert hasattr(sinch_client_sync, "authentication")
2538
assert hasattr(sinch_client_sync, "sms")
2639
assert hasattr(sinch_client_sync, "conversation")
2740
assert hasattr(sinch_client_sync, "numbers")
41+
assert hasattr(sinch_client_sync, "verification")
42+
assert hasattr(sinch_client_sync, "voice")
2843

2944

3045
def test_sinch_client_async_has_all_business_domains(sinch_client_async):
46+
""" Test that SinchClientAsync has all domains """
3147
assert hasattr(sinch_client_async, "authentication")
3248
assert hasattr(sinch_client_async, "sms")
3349
assert hasattr(sinch_client_async, "conversation")
3450
assert hasattr(sinch_client_async, "numbers")
51+
assert hasattr(sinch_client_async, "verification")
52+
assert hasattr(sinch_client_async, "voice")
3553

3654

3755
def test_sinch_client_has_configuration_object(sinch_client_sync):

tests/unit/test_configuration.py

+40-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
1+
import pytest
2+
from logging import Logger, getLogger
13
from sinch.core.clients.sinch_client_configuration import Configuration
24
from sinch.core.adapters.requests_http_transport import HTTPTransportRequests
3-
from sinch.core.token_manager import TokenManager
5+
from sinch.core.adapters.httpx_adapter import HTTPXTransport
6+
from sinch.core.token_manager import TokenManager, TokenManagerAsync
7+
8+
9+
@pytest.mark.parametrize(
10+
"transport_class, token_manager_class, client_fixture",
11+
[
12+
(HTTPTransportRequests, TokenManager, "sinch_client_sync"),
13+
(HTTPXTransport, TokenManagerAsync, "sinch_client_async")
14+
]
15+
)
16+
def test_configuration_happy_capy_expects_initialization(
17+
request, transport_class, token_manager_class, client_fixture
18+
):
19+
""" Test that Configuration can be initialized with all parameters """
20+
sinch_client = request.getfixturevalue(client_fixture)
421

5-
6-
def test_configuration_initialization_happy_path(sinch_client_sync):
722
client_configuration = Configuration(
8-
key_id="Rodney",
9-
key_secret="Mullen",
10-
project_id="Is the King!",
11-
transport=HTTPTransportRequests(sinch_client_sync),
12-
token_manager=TokenManager(sinch_client_sync)
23+
key_id="CapyKey",
24+
key_secret="CapybaraWhisper",
25+
project_id="CapybaraProjectX",
26+
logger=getLogger("CapyTrace"),
27+
connection_timeout=10,
28+
application_key="AppybaraKey",
29+
application_secret="SecretHabitatEntry",
30+
service_plan_id="CappyPremiumPlan",
31+
sms_api_token="HappyCappyToken",
32+
transport=transport_class(sinch_client),
33+
token_manager=token_manager_class(sinch_client)
1334
)
14-
assert client_configuration.key_id == "Rodney"
15-
assert client_configuration.key_secret == "Mullen"
16-
assert client_configuration.project_id == "Is the King!"
17-
assert isinstance(client_configuration.transport, HTTPTransportRequests)
18-
assert isinstance(client_configuration.token_manager, TokenManager)
35+
36+
assert client_configuration.key_id == "CapyKey"
37+
assert client_configuration.key_secret == "CapybaraWhisper"
38+
assert client_configuration.project_id == "CapybaraProjectX"
39+
assert isinstance(client_configuration.logger, Logger)
40+
assert client_configuration.application_key == "AppybaraKey"
41+
assert client_configuration.application_secret == "SecretHabitatEntry"
42+
assert client_configuration.service_plan_id == "CappyPremiumPlan"
43+
assert client_configuration.sms_api_token == "HappyCappyToken"
44+
assert isinstance(client_configuration.transport, transport_class)
45+
assert isinstance(client_configuration.token_manager, token_manager_class)
1946

2047

2148
def test_set_sms_region_property_and_check_that_sms_origin_was_updated(sinch_client_sync):

0 commit comments

Comments
 (0)