Django Rest Framework - Loading fixtures in APITestCase?
I am using django-rest-framework to build an API. I am using a framework APITestCase
to test some of my endpoints.
The documentation doesn't specify how to load the fixtures and the traditional fixtures= ['initial_data.json']
doesn't seem to work.
How can luminaires be loaded?
source to share
The way you describe should work as well. Make sure you declare fixtures in the test class. See example below:
class MyViewsTestCase(APITestCase):
fixtures = ['some_testdata.json']
def test_random_thingy(self):
variable = 'hello'
self.assertEqual(variable, 'hello')
Each time you run a test, fixtures will be loaded and removed after the test is run.
source to share
The fixtures really have nothing to do with the fact that you are testing the application. All you need is a documents folder inside the application folder, which should contain an initial_data.json file. When you run migrate or syncdb, the fixtures are automatically inserted into your db.
This is how it should look:
your_app
|
|__ models.py
|__ views.py
|__ fixtures
|
|__ initial_data.json
You don't need to include / write any other stuff.
source to share