From 7d3e30cd673fcb60e5656259f3f6f52d63a999d8 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:32:33 -0600 Subject: [PATCH] chore: use new billing fixtures --- examples | 2 +- tests/conftest.py | 5 +++ tests/test_beta_referral_customer.py | 4 +- tests/test_billing.py | 67 +++++++++++++++++++--------- tests/test_referral_customer.py | 18 +++----- 5 files changed, 61 insertions(+), 35 deletions(-) diff --git a/examples b/examples index 7669825f..394ea5ef 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 7669825fb53be074d7f585c78c4f38ad4fefe0d0 +Subproject commit 394ea5effde57b304c88999761126953cb1c7e91 diff --git a/tests/conftest.py b/tests/conftest.py index 5f072fa6..3921259e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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"] diff --git a/tests/test_beta_referral_customer.py b/tests/test_beta_referral_customer.py index 31167820..fbeea445 100644 --- a/tests/test_beta_referral_customer.py +++ b/tests/test_beta_referral_customer.py @@ -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. @@ -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." diff --git a/tests/test_billing.py b/tests/test_billing.py index 3e127e0c..578f14d4 100644 --- a/tests/test_billing.py +++ b/tests/test_billing.py @@ -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, @@ -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") @@ -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") @@ -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() @@ -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: @@ -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" diff --git a/tests/test_referral_customer.py b/tests/test_referral_customer.py index 787c335b..968e5153 100644 --- a/tests/test_referral_customer.py +++ b/tests/test_referral_customer.py @@ -127,7 +127,7 @@ 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. @@ -135,15 +135,15 @@ def test_referral_customer_add_credit_card_from_stripe(partner_user_prod_client, 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. @@ -151,13 +151,9 @@ def test_referral_customer_add_bank_account_from_stripe(partner_user_prod_client 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 (