Hi!
I want to write a unit test that performs HTTP requests directly (instead of using django.test.client.Client).
If you're curious why - it's because I want to test a 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 tests, the server is not actually being run. When using django.test.client.Client, it will simply call the view functions instead of actually making a HTTP request. (Please correct me if I'm wrong.)
So what would be the best way to force the test framework to start the 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 that is messy (and doesn't really work) because 1) I need the sleep (otherwise the test will start before the DB is initialized by the test server) and 2) the test will try to initialize the database again (after the testserver already initialized it).
Any other solutions to this?
Thank you.