You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
django is still running with access to the regular database
A live_server with --ds=config.settings.test is created with access to the test database
When a payment is made during testing, stripe still forwards the request to django, which accesses the regular database, NOT the test database that is hooked to live_server, and the test payment would fail.
To fix this problem, we may
Fix stripe: Somehow configure stripe to --forward-to live_server.url/stripe/webhoo. This is what is supposed to happen but requires a different stripe cli instance to be created after live_server.url is determined.
Keep --forward-to to the regular django instance, but django (NOT live_server) will access the test database to complete the test. This may be easier but I am not sure how to configure django to 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.
The text was updated successfully, but these errors were encountered:
It is quite a bit of exploratory work but here is how option two can be implemented:
In settings.test, add non_test_db as a placeholder for the original "normal" database. This should probably be a separate setting file to avoid demanding other tests to list non_test_db in django_db.
What is happening here is that when the test is started, the non_test_db fixture will modify settings.DATABASES and point non_test_db to the original database, and add a DATABASE_ROUTERS to force all database options to happen on the non-test database. This fixture needs to be placed before any other database-operating fixtures.
This will allow the tests to operate on the non-test database with data accessible by the webhook
I have a docker-compose based development environment with
When the user uses stripe to make a payment, an event is forwarded by
stripe
to a webhookhttp://django:800/stripe/webhook
, handled by thedjango
instance.When I use pytest to test the service, the following happens (as far as I understand):
django
is still running with access to the regular databaselive_server
with--ds=config.settings.test
is created with access to the test databasestripe
still 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
stripe
: Somehow configurestripe
to--forward-to live_server.url/stripe/webhoo
. This is what is supposed to happen but requires a differentstripe cli
instance to be created afterlive_server.url
is determined.--forward-to
to the regulardjango
instance, butdjango
(NOTlive_server
) will access the test database to complete the test. This may be easier but I am not sure how to configuredjango
to 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 alive_server
, and using the normal database. The trouble is then how to directpytest-django
to NOT use the test database.The text was updated successfully, but these errors were encountered: