Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Rest Framework - Loading fixtures in an APITestCase?

I'm using django-rest-framework to create an API. I'm using the framework's APITestCase to test some of my endpoints.

The documentation doesn't specify a way to load fixtures and the traditional fixtures= ['initial_data.json'] doesn't seem to be working.

How would one go about loading fixtures?

like image 360
fidiego Avatar asked Aug 13 '14 22:08

fidiego


1 Answers

The way you describe should work also. Make sure you're declaring the fixtures in the test class. An example below:

class MyViewsTestCase(APITestCase):

    fixtures = ['some_testdata.json']

    def test_random_thingy(self):
        variable = 'hello'
        self.assertEqual(variable, 'hello')

Every time you're test is run, the fixtures will be loaded in and removed after the test has run.

like image 164
timop Avatar answered Oct 30 '22 03:10

timop