arcade-mcp/toolkits/stripe/tests/test_stripe.py
Eric Gustin c7fba25488
Add Stripe toolkit (#333)
| Name | Description | Package | Version |

|-----------------------------------|---------------------------------------------------------------------------|---------|---------|
| Stripe.CreateCustomer | This tool will create a customer in Stripe. |
Stripe | 0.0.1 |
| Stripe.ListCustomers | This tool will fetch a list of Customers from
Stripe. | Stripe | 0.0.1 |
| Stripe.CreateProduct | This tool will create a product in Stripe. |
Stripe | 0.0.1 |
| Stripe.ListProducts | This tool will fetch a list of Products from
Stripe. | Stripe | 0.0.1 |
| Stripe.CreatePrice | This tool will create a price in Stripe. If a
product has not already been | Stripe | 0.0.1 |
| Stripe.ListPrices | This tool will fetch a list of Prices from Stripe.
| Stripe | 0.0.1 |
| Stripe.CreatePaymentLink | This tool will create a payment link in
Stripe. | Stripe | 0.0.1 |
| Stripe.ListInvoices | This tool will list invoices in Stripe. | Stripe
| 0.0.1 |
| Stripe.CreateInvoice | This tool will create an invoice in Stripe. |
Stripe | 0.0.1 |
| Stripe.CreateInvoiceItem | This tool will create an invoice item in
Stripe. | Stripe | 0.0.1 |
| Stripe.FinalizeInvoice | This tool will finalize an invoice in Stripe.
| Stripe | 0.0.1 |
| Stripe.RetrieveBalance | This tool will retrieve the balance from
Stripe. It takes no input. | Stripe | 0.0.1 |
| Stripe.CreateRefund | This tool will refund a payment intent in
Stripe. | Stripe | 0.0.1 |
| Stripe.ListPaymentIntents | This tool will list payment intents in
Stripe. | Stripe | 0.0.1 |
| Stripe.CreateBillingPortalSession | This tool will create a billing
portal session. | Stripe | 0.0.1 |

-------------------------

This PR implements the tools in
[stripe-agent-toolkit](https://github.com/stripe/agent-toolkit)
verbatim. This means that the logic needed to implement these tools is
minimal since stripe has already done the heavy lifting.

The tools added in this toolkit are the same tools that are in the
stripe-agent-toolkit, but formatted as Arcade tools. This means that the
names of the tools, the parameter annotations, and tool docstrings are
taken from the stripe-agent-toolkit. I have omitted evals since the tool
definitions are taken from the stripe-agent-toolkit.

The tools in this PR are generated via a script. I have included this
script in the PR (`_generate.py`) so that if the stripe-agent-toolkit
ever adds more tools, then we can simply run that script to generate the
new tools.
2025-04-14 10:29:23 -07:00

87 lines
3 KiB
Python

import pytest
from arcade_stripe.tools.stripe import (
create_billing_portal_session,
create_customer,
create_invoice,
create_invoice_item,
create_payment_link,
create_price,
create_product,
create_refund,
finalize_invoice,
list_customers,
list_invoices,
list_payment_intents,
list_prices,
list_products,
retrieve_balance,
)
class DummyContext:
def get_secret(self, key: str):
return "test_secret_key"
class DummyStripeAPI:
def __init__(self, secret_key, context):
self.secret_key = secret_key
def run(self, method_name, **params):
return {"method": method_name, "params": params}
@pytest.mark.parametrize(
("current_tool", "params"),
[
(create_customer, {"name": "John Doe"}),
(create_customer, {"name": "John Doe", "email": "john.doe@example.com"}),
(list_customers, {}),
(list_customers, {"limit": 10}),
(list_customers, {"email": "john.doe@example.com"}),
(list_customers, {"limit": 10, "email": "john.doe@example.com"}),
(create_product, {"name": "Product 1"}),
(create_product, {"name": "Product 1", "description": "Description 1"}),
(list_products, {}),
(list_products, {"limit": 10}),
(create_price, {"product": "product_123", "unit_amount": 1000, "currency": "usd"}),
(list_prices, {}),
(list_prices, {"product": "product_123"}),
(list_prices, {"limit": 10}),
(list_prices, {"product": "product_123", "limit": 10}),
(create_payment_link, {"price": "price_123", "quantity": 100}),
(list_invoices, {}),
(list_invoices, {"customer": "customer_123"}),
(list_invoices, {"limit": 10}),
(list_invoices, {"customer": "customer_123", "limit": 10}),
(create_invoice, {"customer": "customer_123"}),
(create_invoice, {"customer": "customer_123", "days_until_due": 30}),
(
create_invoice_item,
{"customer": "customer_123", "price": "price_123", "invoice": "invoice_123"},
),
(finalize_invoice, {"invoice": "invoice_123"}),
(retrieve_balance, {}),
(create_refund, {"payment_intent": "payment_intent_123"}),
(create_refund, {"payment_intent": "payment_intent_123", "amount": 100}),
(list_payment_intents, {}),
(list_payment_intents, {"customer": "customer_123"}),
(list_payment_intents, {"limit": 10}),
(list_payment_intents, {"customer": "customer_123", "limit": 10}),
(create_billing_portal_session, {"customer": "customer_123"}),
(
create_billing_portal_session,
{"customer": "customer_123", "return_url": "https://example.com"},
),
],
)
def test_stripe_tools(monkeypatch, current_tool, params):
monkeypatch.setattr("arcade_stripe.tools.stripe.StripeAPI", DummyStripeAPI)
context = DummyContext()
result = current_tool(context, **params)
expected = {"method": current_tool.__name__, "params": params}
assert result == expected