pytest-dev / pytest-dev/pytest-django
How to test stripe webhook using pytest-django
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
I have a docker-compose based development environment with
services:
django:
postgres:
stripe:
command: listen --forward-to http://django:8000/stripe/webhook
When the user uses stripe to make a payment, an event is forwarded by stripe to a webhook http://django:800/stripe/webhook, handled by the django instance.
When I use pytest to test the service, the following happens (as far as I understand):
djangois still running with access to the regular database- A
live_serverwith--ds=config.settings.testis created with access to the test database - When a payment is made during testing,
stripestill forwards the request todjango, which accesses the regular database, NOT the test database that is hooked tolive_server, and the test payment would fail.
To fix this problem, we may
- Fix
stripe: Somehow configurestripeto--forward-to live_server.url/stripe/webhoo. This is what is supposed to happen but requires a differentstripe cliinstance to be created afterlive_server.urlis determined. - Keep
--forward-toto the regulardjangoinstance, butdjango(NOTlive_server) will access the test database to complete the test. This may be easier but I am not sure how to configuredjangoto access the test database.
Does anyone have any suggestions on how to do this properly?
Edit: A third option maybe running the tests on django directly without firing up a live_server, and using the normal database. The trouble is then how to direct pytest-django to NOT use the test database.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the docker-compose services and the pytest-django live_server setup described in the report; verify which process receives the Stripe webhook and which database it uses. Done means identifying a reproducible test configuration in which the webhook reaches the test environment and the payment completes, or documenting the project-specific decision needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, docker-compose, python
- Domain
- backend, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100