Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sinch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

from sinch.core.clients.sinch_client_sync import SinchClient

__all__ = SinchClient
__all__ = ["SinchClient"]
4 changes: 2 additions & 2 deletions sinch/domains/numbers/api/v1/active_numbers_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
class ActiveNumbers(BaseNumbers):
def list(
self,
region_code: str,
number_type: NumberType,
region_code: Optional[str] = None,
number_type: Optional[NumberType] = None,
number_pattern: Optional[str] = None,
number_search_pattern: Optional[NumberSearchPatternType] = None,
capabilities: Optional[List[CapabilityType]] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@


class ListActiveNumbersRequest(BaseModelConfigurationRequest):
region_code: StrictStr = Field(
region_code: Optional[StrictStr] = Field(
default=None,
alias="regionCode",
description="ISO 3166-1 alpha-2 country code. Example: US, GB or SE.",
)
number_type: NumberType = Field(alias="type")
number_type: Optional[NumberType] = Field(default=None, alias="type")
page_size: Optional[StrictInt] = Field(default=None, alias="pageSize")
capabilities: Optional[conlist(CapabilityType)] = Field(default=None)
number_search_pattern: Optional[NumberSearchPatternType] = Field(
Expand Down
12 changes: 6 additions & 6 deletions sinch/domains/numbers/virtual_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def sinch_events(self, callback_secret: str) -> SinchEvents:

def list(
self,
region_code: str,
number_type: NumberType,
region_code: Optional[str] = None,
number_type: Optional[NumberType] = None,
number_pattern: Optional[str] = None,
number_search_pattern: Optional[NumberSearchPatternType] = None,
capabilities: Optional[List[CapabilityType]] = None,
Expand All @@ -69,11 +69,11 @@ def list(
"""
Search for all active virtual numbers associated with a certain project.

:param region_code: ISO 3166-1 alpha-2 country code. Example: US, GB or SE.
:type region_code: str
:param region_code: Optional. ISO 3166-1 alpha-2 country code. Example: US, GB or SE.
:type region_code: Optional[str]

:param number_type: Type of number (e.g., "MOBILE", "LOCAL", "TOLL_FREE").
:type number_type: NumberType
:param number_type: Optional. Type of number (e.g., "MOBILE", "LOCAL", "TOLL_FREE").
:type number_type: Optional[NumberType]

:param number_pattern: Specific sequence of digits to search for.
:type number_pattern: Optional[str]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def test_build_query_params_expects_correct_mapping(endpoint):
assert endpoint.build_query_params() == expected_params


def test_build_query_params_omits_none_region_and_type():
"""
Optional query params must not be sent when unset.
"""
request_data = ListActiveNumbersRequest(
page_size=10,
capabilities=["SMS"],
)
endpoint = ListActiveNumbersEndpoint("test_project_id", request_data)
assert endpoint.build_query_params() == {
"pageSize": 10,
"capabilities": ["SMS"],
}


def test_handle_response_expects_correct_mapping(endpoint, mock_response):
"""
Check if response is handled and mapped to the appropriate fields correctly.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
from pydantic import ValidationError
from sinch.domains.numbers.models.v1.internal import ListActiveNumbersRequest


Expand Down Expand Up @@ -70,12 +69,3 @@ def test_list_available_numbers_request_expects_camel_case_input():
request = ListActiveNumbersRequest(**data)
assert request.region_code == "US"
assert request.number_type == "MOBILE"


def test_list_active_numbers_request_expects_validation_error_for_missing_field():
"""
Test that missing required fields raise a ValidationError.
"""
data = {}
with pytest.raises(ValidationError):
ListActiveNumbersRequest(**data)
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ def test_list_available_numbers_request_expects_validation_error_for_missing_req
data = {
"number_type": "MOBILE",
"size": 10,
"capabilities": ["SMS", "VOICE"]
"capabilities": ["SMS", "VOICE"],
}

with pytest.raises(ValidationError) as exc_info:
ListAvailableNumbersRequest(**data)

# Assert the error mentions the missing region_code field
assert "region_code" in str(exc_info.value) or "regionCode" in str(exc_info.value)


Expand Down
Loading