Reputation: 104
I'm writing a complicated web application in Django. There are many components. Two in particular, are the Django server (lets call this Server
), and a C++ application server (lets call this Calculator
) which serves calculations to Server
. When Server
wants a calculation done, it sends a command to a socket on which Calculator
is listening. Like this:
{
"command": "doCalculations"
}
Now, Calculator
might need different pieces of information at different times to do its work. So instead of passing the data directly to Calaculator
in the command, it is up to Calculator
to ask for what it needs. It does this by calling a RESTful API on Server
:
https://Server/getStuff?with=arguments
Calculator
then uses the data from this call to do its calculations, and respond to Server
with an answer.
The problems begin when I try to do unit testing using Djangos unittest framework. I set up a bunch of data structures in my test, but when Server
calls Calculator
, it needs to have this data available in the REST API so Calculator
can get what it needs. The trouble is that the Django test framework doesn't spin up a webserver, and if I do this manually it reads the data from the real database, and not the test-case.
Does anybody know how to run a unit test with the data made available to external people/processes?
I hope that makes sense...
Upvotes: 1
Views: 532
Reputation: 1698
You need specify the fixtures to load in your test class.
https://docs.djangoproject.com/en/1.7/topics/testing/tools/#fixture-loading
class MyTest(TestCase):
fixtures = ['data.json']
def setUp(self):
# do stuff
def tearDown(self):
# do stuff
Where data.json
can be retrieved by using python manage.py dumpdata
.
It will be filled with data from your main db in JSON format.
data.json
should exist in the fixtures
folder of the app you are testing. (Create one if necessary).
Upvotes: 1