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 examples
Submodule examples updated 47 files
+0 −5 .babelrc
+29 −25 Gemfile.lock
+11 −9 README.md
+3 −3 examples.gemspec
+10 −0 official/fixtures/client-library-fixtures.json
+2,036 −1,408 package-lock.json
+0 −2 package.json
+10 −9 style_guides/ruby/.rubocop.yml
+2 −2 style_guides/ruby/easycop.yml
+2 −0 tools/docs/responses/.gitignore
+62 −0 tools/docs/responses/Makefile
+19 −0 tools/docs/responses/README.md
+0 −0 tools/docs/responses/builder/__init__.py
+164 −0 tools/docs/responses/builder/snippets.py
+45 −0 tools/docs/responses/setup.py
+0 −0 tools/docs/responses/tests/__init__.py
+256 −0 tools/docs/responses/tests/conftest.py
+68 −0 tools/docs/responses/tests/test_address.py
+69 −0 tools/docs/responses/tests/test_api_keys.py
+100 −0 tools/docs/responses/tests/test_batch.py
+69 −0 tools/docs/responses/tests/test_billing.py
+11 −0 tools/docs/responses/tests/test_brand.py
+48 −0 tools/docs/responses/tests/test_carrier_account.py
+10 −0 tools/docs/responses/tests/test_carrier_types.py
+18 −0 tools/docs/responses/tests/test_customs_info.py
+18 −0 tools/docs/responses/tests/test_customs_item.py
+54 −0 tools/docs/responses/tests/test_end_shipper.py
+112 −0 tools/docs/responses/tests/test_event.py
+15 −0 tools/docs/responses/tests/test_form.py
+25 −0 tools/docs/responses/tests/test_insurance.py
+11 −0 tools/docs/responses/tests/test_options.py
+48 −0 tools/docs/responses/tests/test_order.py
+18 −0 tools/docs/responses/tests/test_parcel.py
+43 −0 tools/docs/responses/tests/test_pickup.py
+20 −0 tools/docs/responses/tests/test_rate.py
+84 −0 tools/docs/responses/tests/test_referral_customer.py
+31 −0 tools/docs/responses/tests/test_refund.py
+34 −0 tools/docs/responses/tests/test_report.py
+11 −0 tools/docs/responses/tests/test_returns.py
+27 −0 tools/docs/responses/tests/test_scan_form.py
+61 −0 tools/docs/responses/tests/test_shipment.py
+18 −0 tools/docs/responses/tests/test_shipping_insurance.py
+11 −0 tools/docs/responses/tests/test_smartrate.py
+12 −0 tools/docs/responses/tests/test_tax_identifiers.py
+18 −0 tools/docs/responses/tests/test_tracker.py
+37 −0 tools/docs/responses/tests/test_user.py
+50 −0 tools/docs/responses/tests/test_webhook.py
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,8 @@ def planned_ship_date():
@pytest.fixture
def desired_delivery_date():
return "2025-03-08"


@pytest.fixture
def billing():
return read_fixture_data()["billing"]
4 changes: 2 additions & 2 deletions tests/test_beta_referral_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@pytest.mark.vcr()
def test_beta_referral_customer_add_payment_method(referral_customer_prod_client):
def test_beta_referral_customer_add_payment_method(referral_customer_prod_client, billing):
"""This test requires a referral customer's production API key via REFERRAL_CUSTOMER_PROD_API_KEY.

We expect this test to fail because we don't have valid Stripe details to use. Assert the correct error.
Expand All @@ -12,7 +12,7 @@ def test_beta_referral_customer_add_payment_method(referral_customer_prod_client
referral_customer_prod_client.beta_referral_customer.add_payment_method(
stripe_customer_id="cus_123",
payment_method_reference="ba_123",
priority="primary",
priority=billing["priority"],
)

assert str(error.value) == "Invalid connect integration."
Expand Down
67 changes: 46 additions & 21 deletions tests/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@


@patch(
"easypost.services.billing_service.BillingService._get_payment_method_info", return_value=["/endpoint", "card_123"]
"easypost.services.billing_service.BillingService._get_payment_method_info",
return_value=["/endpoint", "card_123"],
)
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
def test_billing_fund_wallet(mock_request, mock_get_payment_info, prod_client):
prod_client.billing.fund_wallet(
amount="2000",
priority="primary",
)
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"mock": "response"},
)
def test_billing_fund_wallet(mock_request, mock_get_payment_info, prod_client, billing):
prod_client.billing.fund_wallet(amount="2000", priority=billing["priority"])

mock_request.assert_called_once_with(
method=easypost.requestor.RequestMethod.POST,
Expand All @@ -26,10 +27,13 @@ def test_billing_fund_wallet(mock_request, mock_get_payment_info, prod_client):
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
return_value={"primary_payment_method": {"id": "pm_123", "object": "CreditCard"}},
)
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
def test_billing_payment_method_delete_credit_card(mock_request, mock_payment_methods, prod_client):
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"mock": "response"},
)
def test_billing_payment_method_delete_credit_card(mock_request, mock_payment_methods, prod_client, billing):
"""Tests we make a valid call to delete a credit card."""
prod_client.billing.delete_payment_method(priority="primary")
prod_client.billing.delete_payment_method(priority=billing["priority"])

mock_request.assert_called_once_with(method=easypost.requestor.RequestMethod.DELETE, url="/credit_cards/pm_123")

Expand All @@ -38,10 +42,15 @@ def test_billing_payment_method_delete_credit_card(mock_request, mock_payment_me
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
return_value={"primary_payment_method": {"id": "pm_123", "object": "BankAccount"}},
)
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
def test_billing_payment_method_delete_bank_account(mock_request, mock_payment_methods, prod_client):
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"mock": "response"},
)
def test_billing_payment_method_delete_bank_account(mock_request, mock_payment_methods, prod_client, billing):
"""Tests we make a valid call to delete a bank account."""
prod_client.billing.delete_payment_method(priority="primary")
prod_client.billing.delete_payment_method(
priority=billing["priority"],
)

mock_request.assert_called_once_with(method=easypost.requestor.RequestMethod.DELETE, url="/bank_accounts/pm_123")

Expand All @@ -50,25 +59,36 @@ def test_billing_payment_method_delete_bank_account(mock_request, mock_payment_m
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
return_value={"primary_payment_method": {"id": "bad_id"}},
)
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
def test_billing_payment_method_delete_invalid(mock_request, mock_payment_methods, prod_client):
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"mock": "response"},
)
def test_billing_payment_method_delete_invalid(mock_request, mock_payment_methods, prod_client, billing):
"""Tests we raise an error when we receive an invalid payment method"""
with pytest.raises(InvalidObjectError):
_ = prod_client.billing.delete_payment_method(priority="primary")
_ = prod_client.billing.delete_payment_method(
priority=billing["priority"],
)


@patch(
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
return_value={"primary_payment_methods": {"id": "bad_id"}},
)
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"mock": "response"},
)
def test_billing_payment_method_delete_bad_request(mock_request, mock_payment_methods, prod_client):
"""Tests we raise an error when we cannot retrieve a payment method."""
with pytest.raises(InvalidObjectError):
_ = prod_client.billing.delete_payment_method(priority="tertiary")


@patch("easypost.services.billing_service.Requestor.request", return_value={"id": "card_123"})
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"id": "card_123"},
)
def test_billing_retrieve_payment_methods(mock_request, prod_client):
"""Tests that we throw an error when we cannot retrieve payment methods due to no billing being setup."""
response = prod_client.billing.retrieve_payment_methods()
Expand All @@ -77,7 +97,10 @@ def test_billing_retrieve_payment_methods(mock_request, prod_client):
assert isinstance(response, easypost.easypost_object.EasyPostObject)


@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
@patch(
"easypost.services.billing_service.Requestor.request",
return_value={"mock": "response"},
)
def test_billing_retrieve_payment_methods_no_billing_setup(mock_request, prod_client):
"""Tests that we throw an error when we cannot retrieve payment methods due to no billing being setup."""
with pytest.raises(InvalidObjectError) as error:
Expand All @@ -94,9 +117,11 @@ def test_billing_retrieve_payment_methods_no_billing_setup(mock_request, prod_cl
"secondary_payment_method": {"id": "pm_456", "object": "BankAccount"},
},
)
def test_billing__get_payment_method_info_by_object_type(mock_request, prod_client):
def test_billing__get_payment_method_info_by_object_type(mock_request, prod_client, billing):
"""Tests we can determine the payment method type/endpoint by object type."""
endpoint, payment_method_id = prod_client.billing._get_payment_method_info(priority="primary")
endpoint, payment_method_id = prod_client.billing._get_payment_method_info(
priority=billing["priority"],
)

assert endpoint == "/credit_cards"
assert payment_method_id == "pm_123"
Expand Down
18 changes: 7 additions & 11 deletions tests/test_referral_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,33 @@ def test_referral_add_credit_card_error(


@pytest.mark.vcr()
def test_referral_customer_add_credit_card_from_stripe(partner_user_prod_client, credit_card_details):
def test_referral_customer_add_credit_card_from_stripe(partner_user_prod_client, credit_card_details, billing):
"""This test requires a referral customer's production API key via REFERRAL_CUSTOMER_PROD_API_KEY.

We expect this test to fail because we don't have valid billing details to use. Assert the correct error.
"""
with pytest.raises(ApiError) as error:
partner_user_prod_client.referral_customer.add_credit_card_from_stripe(
referral_api_key=REFERRAL_CUSTOMER_PROD_API_KEY,
payment_method_id="pm_0Pn6bQDqT4huGUvd0CjpRerH",
priority="primary",
payment_method_id=billing["payment_method_id"],
priority=billing["priority"],
)

assert str(error.value) == "Stripe::PaymentMethod does not exist for the specified reference_id"


@pytest.mark.vcr()
def test_referral_customer_add_bank_account_from_stripe(partner_user_prod_client, credit_card_details):
def test_referral_customer_add_bank_account_from_stripe(partner_user_prod_client, credit_card_details, billing):
"""This test requires a referral customer's production API key via REFERRAL_CUSTOMER_PROD_API_KEY.

We expect this test to fail because we don't have valid billing details to use. Assert the correct error.
"""
with pytest.raises(ApiError) as error:
partner_user_prod_client.referral_customer.add_bank_account_from_stripe(
referral_api_key=REFERRAL_CUSTOMER_PROD_API_KEY,
financial_connections_id="fca_0QAc7sDqT4huGUvdf6BahYa9",
mandate_data={
"ip_address": "127.0.0.1",
"user_agent": "Mozilla/5.0",
"accepted_at": 1722510730,
},
priority="primary",
financial_connections_id=billing["financial_connections_id"],
mandate_data=billing["mandate_data"],
priority=billing["priority"],
)

assert (
Expand Down