Testing Your Money-Native App
Payment code is exactly the code you don't want to break. Larz makes it testable end to end - no real provider, no live charges - so you can ship changes with confidence.
The scariest bugs are the ones that touch money. The good news is that Larz was built to be tested: a keyless mock provider drives the whole payment flow in tests, and a built-in test client exercises your routes without a running server - so you can verify 'a non-paying user is sent to checkout' automatically, every time.
Drive routes with the test client
from larz.testing import Client
c = Client(app)
r = c.get('/pro/report') # not paid yet
assert r.status == 402 or 'checkout' in r.headers.get('Location', '')
c.login('ada@example.com') # simulate an authenticated, paid user
assert c.get('/pro/report').status == 200Payments without live charges
The mock provider completes checkout deterministically, so you can assert that paying grants the entitlement - and that a webhook records the invoice - with no network and no keys.
money.enable(app) # dev: MockProvider, no keys
# simulate a completed payment and assert the entitlement was granted
app.money.grant(subject, 'pro')
assert app.money.feature(subject, 'pro')Takeaways
- Money code is the code you least want to break - so test it, and Larz makes that easy.
- The test client exercises routes (incl. paywalls) with no running server.
- The keyless mock provider drives the whole payment flow in tests - no live charges.