I want to write a unit test that directly executes HTTP requests (instead of using django.test.client.Client).
If you're interested, because I want to check the Thrift-over-HTTP API that I expose from my Django application - and I want to use the Thrift client in the unit test.
The problem is that during the tests the server does not actually start. When using django.test.client.Client, it simply calls the view functions instead of actually creating the HTTP request. (Please correct me if I am wrong.)
So, what would be the best way to get the test environment to start an HTTP server?
I tried writing a bash script that does something like this:
./manage.py testserver --addrport 7000 & PID=$! sleep 5 ./manage.py test --no-input kill $PID
But this is dirty (and actually does not work), because 1) I need a dream (otherwise the test will start before the database is initialized by the test server), and 2) the test will try to initialize the database again (after the test server has already initialized it).
Any other solutions?
Thanks.
source share