Skip to content

Commit a9519c5

Browse files
authored
Merge pull request #49 from sinch/DEVEXP_758-SinchClient_Config
DEVEXP-758: SinchClient Configuration
2 parents 8cc9299 + b02b46a commit a9519c5

File tree

3 files changed

+98
-68
lines changed

3 files changed

+98
-68
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+
The Sinch client provides access to the following Sinch products:
39+
- Numbers API
40+
- SMS API
41+
- Verification API
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+
project_id="project_id",
90+
key_id="key_id",
91+
key_secret="key_secret"
92+
)
93+
```
7794

7895
## Logging
7996

tests/unit/test_client.py

+23-37
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
1+
import pytest
12
from sinch import SinchClient, SinchClientAsync
23
from sinch.core.clients.sinch_client_configuration import Configuration
34

4-
5-
def test_sinch_client_initialization():
6-
sinch_client_sync = SinchClient(
7-
key_id="test",
8-
key_secret="test_secret",
9-
project_id="test_project_id"
10-
)
11-
assert sinch_client_sync
12-
13-
14-
def test_sinch_client_async_initialization():
15-
sinch_client_async = SinchClientAsync(
5+
@pytest.mark.parametrize("client", [SinchClient, SinchClientAsync])
6+
def test_sinch_client_initialization(client):
7+
""" Test that SinchClient and SinchClientAsync can be initialized with or without parameters """
8+
sinch_client = client(
169
key_id="test",
1710
key_secret="test_secret",
1811
project_id="test_project_id"
1912
)
20-
assert sinch_client_async
21-
22-
23-
def test_sinch_client_has_all_business_domains(sinch_client_sync):
24-
assert hasattr(sinch_client_sync, "authentication")
25-
assert hasattr(sinch_client_sync, "sms")
26-
assert hasattr(sinch_client_sync, "conversation")
27-
assert hasattr(sinch_client_sync, "numbers")
28-
29-
30-
def test_sinch_client_async_has_all_business_domains(sinch_client_async):
31-
assert hasattr(sinch_client_async, "authentication")
32-
assert hasattr(sinch_client_async, "sms")
33-
assert hasattr(sinch_client_async, "conversation")
34-
assert hasattr(sinch_client_async, "numbers")
35-
36-
37-
def test_sinch_client_has_configuration_object(sinch_client_sync):
38-
assert hasattr(sinch_client_sync, "configuration")
39-
assert isinstance(sinch_client_sync.configuration, Configuration)
40-
41-
42-
def test_sinch_client_async_has_configuration_object(sinch_client_async):
43-
assert hasattr(sinch_client_async, "configuration")
44-
assert isinstance(sinch_client_async.configuration, Configuration)
13+
assert sinch_client
14+
15+
sinch_client_empty = client()
16+
assert sinch_client_empty
17+
18+
19+
@pytest.mark.parametrize("client", ["sinch_client_sync", "sinch_client_async"])
20+
def test_sinch_client_expects_all_attributes(request, client):
21+
""" Test that SinchClient and SinchClientAsync have all attributes"""
22+
client_instance = request.getfixturevalue(client)
23+
assert hasattr(client_instance, "authentication")
24+
assert hasattr(client_instance, "sms")
25+
assert hasattr(client_instance, "conversation")
26+
assert hasattr(client_instance, "numbers")
27+
assert hasattr(client_instance, "verification")
28+
assert hasattr(client_instance, "voice")
29+
assert hasattr(client_instance, "configuration")
30+
assert isinstance(client_instance.configuration, Configuration)

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)