Skip to content

Commit

Permalink
write test for de-serialization potential error (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkeur7 authored Dec 2, 2024
1 parent ca48d9b commit 844f3c4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_carrier_accounts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest
from marshmallow import ValidationError

import shippo
from shippo.models.components import CarriersEnum, ConnectExistingOwnAccountRequest
from shippo.models.operations import ListCarrierAccountsRequest
Expand All @@ -18,3 +21,34 @@ def test_list_all_carrier_accounts(self, api: shippo.Shippo):
assert carrier_account.object_id is not None
assert carrier_account.object_owner is not None
assert carrier_account.test is not None

def test_parameters_deserialize_to_dict(self, api: shippo.Shippo):
parameters = {
'api_version': 4,
'username': '12345',
'password': 'password',
'pickup_no': '12345',
'facility_code': '1234'
}

request_data = {
'account_id': '123456789',
'carrier': 'dhl_ecommerce',
'parameters': parameters,
'metadata': 'DHLEcomTestAccount',
'active': False,
'test': False
}

try:
request = ConnectExistingOwnAccountRequest.from_dict(request_data)
assert isinstance(request.parameters, dict)
for key, value in request.parameters.items():
assert key in parameters
assert value is not None

except ValidationError as e:
pytest.fail(f'Deserialization failed with ValidationError: {e}')
except Exception as e:
pytest.fail(f'Unexpected error occurred: {e}')

0 comments on commit 844f3c4

Please sign in to comment.