Skip to content

Commit 03136e0

Browse files
authored
Merge pull request #359 from EasyPost/billing_fixtures
chore: use new billing fixtures
2 parents 9af5da5 + 7d3e30c commit 03136e0

File tree

5 files changed

+61
-35
lines changed

5 files changed

+61
-35
lines changed

examples

Submodule examples updated 47 files

tests/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,8 @@ def planned_ship_date():
377377
@pytest.fixture
378378
def desired_delivery_date():
379379
return "2025-03-08"
380+
381+
382+
@pytest.fixture
383+
def billing():
384+
return read_fixture_data()["billing"]

tests/test_beta_referral_customer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
@pytest.mark.vcr()
6-
def test_beta_referral_customer_add_payment_method(referral_customer_prod_client):
6+
def test_beta_referral_customer_add_payment_method(referral_customer_prod_client, billing):
77
"""This test requires a referral customer's production API key via REFERRAL_CUSTOMER_PROD_API_KEY.
88
99
We expect this test to fail because we don't have valid Stripe details to use. Assert the correct error.
@@ -12,7 +12,7 @@ def test_beta_referral_customer_add_payment_method(referral_customer_prod_client
1212
referral_customer_prod_client.beta_referral_customer.add_payment_method(
1313
stripe_customer_id="cus_123",
1414
payment_method_reference="ba_123",
15-
priority="primary",
15+
priority=billing["priority"],
1616
)
1717

1818
assert str(error.value) == "Invalid connect integration."

tests/test_billing.py

+46-21
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77

88
@patch(
9-
"easypost.services.billing_service.BillingService._get_payment_method_info", return_value=["/endpoint", "card_123"]
9+
"easypost.services.billing_service.BillingService._get_payment_method_info",
10+
return_value=["/endpoint", "card_123"],
1011
)
11-
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
12-
def test_billing_fund_wallet(mock_request, mock_get_payment_info, prod_client):
13-
prod_client.billing.fund_wallet(
14-
amount="2000",
15-
priority="primary",
16-
)
12+
@patch(
13+
"easypost.services.billing_service.Requestor.request",
14+
return_value={"mock": "response"},
15+
)
16+
def test_billing_fund_wallet(mock_request, mock_get_payment_info, prod_client, billing):
17+
prod_client.billing.fund_wallet(amount="2000", priority=billing["priority"])
1718

1819
mock_request.assert_called_once_with(
1920
method=easypost.requestor.RequestMethod.POST,
@@ -26,10 +27,13 @@ def test_billing_fund_wallet(mock_request, mock_get_payment_info, prod_client):
2627
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
2728
return_value={"primary_payment_method": {"id": "pm_123", "object": "CreditCard"}},
2829
)
29-
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
30-
def test_billing_payment_method_delete_credit_card(mock_request, mock_payment_methods, prod_client):
30+
@patch(
31+
"easypost.services.billing_service.Requestor.request",
32+
return_value={"mock": "response"},
33+
)
34+
def test_billing_payment_method_delete_credit_card(mock_request, mock_payment_methods, prod_client, billing):
3135
"""Tests we make a valid call to delete a credit card."""
32-
prod_client.billing.delete_payment_method(priority="primary")
36+
prod_client.billing.delete_payment_method(priority=billing["priority"])
3337

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

@@ -38,10 +42,15 @@ def test_billing_payment_method_delete_credit_card(mock_request, mock_payment_me
3842
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
3943
return_value={"primary_payment_method": {"id": "pm_123", "object": "BankAccount"}},
4044
)
41-
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
42-
def test_billing_payment_method_delete_bank_account(mock_request, mock_payment_methods, prod_client):
45+
@patch(
46+
"easypost.services.billing_service.Requestor.request",
47+
return_value={"mock": "response"},
48+
)
49+
def test_billing_payment_method_delete_bank_account(mock_request, mock_payment_methods, prod_client, billing):
4350
"""Tests we make a valid call to delete a bank account."""
44-
prod_client.billing.delete_payment_method(priority="primary")
51+
prod_client.billing.delete_payment_method(
52+
priority=billing["priority"],
53+
)
4554

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

@@ -50,25 +59,36 @@ def test_billing_payment_method_delete_bank_account(mock_request, mock_payment_m
5059
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
5160
return_value={"primary_payment_method": {"id": "bad_id"}},
5261
)
53-
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
54-
def test_billing_payment_method_delete_invalid(mock_request, mock_payment_methods, prod_client):
62+
@patch(
63+
"easypost.services.billing_service.Requestor.request",
64+
return_value={"mock": "response"},
65+
)
66+
def test_billing_payment_method_delete_invalid(mock_request, mock_payment_methods, prod_client, billing):
5567
"""Tests we raise an error when we receive an invalid payment method"""
5668
with pytest.raises(InvalidObjectError):
57-
_ = prod_client.billing.delete_payment_method(priority="primary")
69+
_ = prod_client.billing.delete_payment_method(
70+
priority=billing["priority"],
71+
)
5872

5973

6074
@patch(
6175
"easypost.services.billing_service.BillingService.retrieve_payment_methods",
6276
return_value={"primary_payment_methods": {"id": "bad_id"}},
6377
)
64-
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
78+
@patch(
79+
"easypost.services.billing_service.Requestor.request",
80+
return_value={"mock": "response"},
81+
)
6582
def test_billing_payment_method_delete_bad_request(mock_request, mock_payment_methods, prod_client):
6683
"""Tests we raise an error when we cannot retrieve a payment method."""
6784
with pytest.raises(InvalidObjectError):
6885
_ = prod_client.billing.delete_payment_method(priority="tertiary")
6986

7087

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

7999

80-
@patch("easypost.services.billing_service.Requestor.request", return_value={"mock": "response"})
100+
@patch(
101+
"easypost.services.billing_service.Requestor.request",
102+
return_value={"mock": "response"},
103+
)
81104
def test_billing_retrieve_payment_methods_no_billing_setup(mock_request, prod_client):
82105
"""Tests that we throw an error when we cannot retrieve payment methods due to no billing being setup."""
83106
with pytest.raises(InvalidObjectError) as error:
@@ -94,9 +117,11 @@ def test_billing_retrieve_payment_methods_no_billing_setup(mock_request, prod_cl
94117
"secondary_payment_method": {"id": "pm_456", "object": "BankAccount"},
95118
},
96119
)
97-
def test_billing__get_payment_method_info_by_object_type(mock_request, prod_client):
120+
def test_billing__get_payment_method_info_by_object_type(mock_request, prod_client, billing):
98121
"""Tests we can determine the payment method type/endpoint by object type."""
99-
endpoint, payment_method_id = prod_client.billing._get_payment_method_info(priority="primary")
122+
endpoint, payment_method_id = prod_client.billing._get_payment_method_info(
123+
priority=billing["priority"],
124+
)
100125

101126
assert endpoint == "/credit_cards"
102127
assert payment_method_id == "pm_123"

tests/test_referral_customer.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -127,37 +127,33 @@ def test_referral_add_credit_card_error(
127127

128128

129129
@pytest.mark.vcr()
130-
def test_referral_customer_add_credit_card_from_stripe(partner_user_prod_client, credit_card_details):
130+
def test_referral_customer_add_credit_card_from_stripe(partner_user_prod_client, credit_card_details, billing):
131131
"""This test requires a referral customer's production API key via REFERRAL_CUSTOMER_PROD_API_KEY.
132132
133133
We expect this test to fail because we don't have valid billing details to use. Assert the correct error.
134134
"""
135135
with pytest.raises(ApiError) as error:
136136
partner_user_prod_client.referral_customer.add_credit_card_from_stripe(
137137
referral_api_key=REFERRAL_CUSTOMER_PROD_API_KEY,
138-
payment_method_id="pm_0Pn6bQDqT4huGUvd0CjpRerH",
139-
priority="primary",
138+
payment_method_id=billing["payment_method_id"],
139+
priority=billing["priority"],
140140
)
141141

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

144144

145145
@pytest.mark.vcr()
146-
def test_referral_customer_add_bank_account_from_stripe(partner_user_prod_client, credit_card_details):
146+
def test_referral_customer_add_bank_account_from_stripe(partner_user_prod_client, credit_card_details, billing):
147147
"""This test requires a referral customer's production API key via REFERRAL_CUSTOMER_PROD_API_KEY.
148148
149149
We expect this test to fail because we don't have valid billing details to use. Assert the correct error.
150150
"""
151151
with pytest.raises(ApiError) as error:
152152
partner_user_prod_client.referral_customer.add_bank_account_from_stripe(
153153
referral_api_key=REFERRAL_CUSTOMER_PROD_API_KEY,
154-
financial_connections_id="fca_0QAc7sDqT4huGUvdf6BahYa9",
155-
mandate_data={
156-
"ip_address": "127.0.0.1",
157-
"user_agent": "Mozilla/5.0",
158-
"accepted_at": 1722510730,
159-
},
160-
priority="primary",
154+
financial_connections_id=billing["financial_connections_id"],
155+
mandate_data=billing["mandate_data"],
156+
priority=billing["priority"],
161157
)
162158

163159
assert (

0 commit comments

Comments
 (0)