diff --git a/identity_insights/src/vonage_identity_insights/responses.py b/identity_insights/src/vonage_identity_insights/responses.py index 4b5c4dfc..6239ce5c 100644 --- a/identity_insights/src/vonage_identity_insights/responses.py +++ b/identity_insights/src/vonage_identity_insights/responses.py @@ -13,7 +13,7 @@ class InsightStatus(BaseModel): """ code: str - message: Optional[str] + message: Optional[str] = None class FormatInsightResponse(BaseModel): @@ -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 @@ -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 diff --git a/identity_insights/tests/data/nullable_response.json b/identity_insights/tests/data/nullable_response.json new file mode 100644 index 00000000..eb6aa5b8 --- /dev/null +++ b/identity_insights/tests/data/nullable_response.json @@ -0,0 +1,16 @@ +{ + "request_id": "aaaaaaaa-bbbb-cccc-dddd-0123456789ab", + "insights": { + "format": { + "status": { + "code": "OK" + } + }, + "original_carrier": { + "status": { + "code": "OK", + "message": "Success" + } + } + } +} diff --git a/identity_insights/tests/test_identity_insights.py b/identity_insights/tests/test_identity_insights.py index bcc316cb..e7347b62 100644 --- a/identity_insights/tests/test_identity_insights.py +++ b/identity_insights/tests/test_identity_insights.py @@ -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"