Skip to content
Open
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
26 changes: 13 additions & 13 deletions identity_insights/src/vonage_identity_insights/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InsightStatus(BaseModel):
"""

code: str
message: Optional[str]
message: Optional[str] = None


class FormatInsightResponse(BaseModel):
Expand All @@ -34,14 +34,14 @@ class FormatInsightResponse(BaseModel):
status (InsightStatus): Processing status of the insight.
"""

country_code: Optional[str]
country_name: Optional[str]
country_prefix: Optional[str]
offline_location: Optional[str]
time_zones: Optional[List[str]]
number_international: Optional[str]
number_national: Optional[str]
is_format_valid: Optional[bool]
country_code: Optional[str] = None
country_name: Optional[str] = None
country_prefix: Optional[str] = None
offline_location: Optional[str] = None
time_zones: Optional[List[str]] = None
number_international: Optional[str] = None
number_national: Optional[str] = None
is_format_valid: Optional[bool] = None
status: InsightStatus


Expand Down Expand Up @@ -77,10 +77,10 @@ class CarrierInsightResponse(BaseModel):
status (InsightStatus): Processing status of the insight.
"""

name: Optional[str]
network_type: Optional[str]
country_code: Optional[str]
network_code: Optional[str]
name: Optional[str] = None
network_type: Optional[str] = None
country_code: Optional[str] = None
network_code: Optional[str] = None
status: InsightStatus


Expand Down
16 changes: 16 additions & 0 deletions identity_insights/tests/data/nullable_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"request_id": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab",
"insights": {
"format": {
"status": {
"code": "OK"
}
},
"original_carrier": {
"status": {
"code": "OK",
"message": "Success"
}
}
}
}
32 changes: 32 additions & 0 deletions identity_insights/tests/test_identity_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,35 @@ def test_empty_insights_request_raises_exception():

with raises(EmptyInsightsRequestException):
identity_insights.requests(options)


@responses.activate
def test_nullable_response_fields():
build_response(
path,
'POST',
'https://api-eu.vonage.com/identity-insights/v1/requests',
'nullable_response.json',
)

options = IdentityInsightsRequest(
phone_number="1234567890", insights=InsightsRequest(format=EmptyInsight())
)

response = identity_insights.requests(options)

# Verify that optional fields with missing values are None
assert response.insights.format.country_code is None
assert response.insights.format.country_name is None
assert response.insights.format.time_zones is None
assert response.insights.format.is_format_valid is None
assert response.insights.format.status.code == "OK"
assert response.insights.format.status.message is None

# Verify original_carrier fields are None when not provided
assert response.insights.original_carrier.name is None
assert response.insights.original_carrier.network_type is None
assert response.insights.original_carrier.country_code is None
assert response.insights.original_carrier.network_code is None
assert response.insights.original_carrier.status.code == "OK"
assert response.insights.original_carrier.status.message == "Success"