Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write test for de-serialization potential error #104

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
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,
rkeur7 marked this conversation as resolved.
Show resolved Hide resolved
'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}')