jeudi 25 août 2016

Django client test (get, post) response load data from main db instead fixtures loaded in test db

I'm new in Django, and I have this problem: I use self.client to test routes in my app. e.g.

class BookSell(TestCase):
    fixtures = [
        'sellers.yaml',
        'books.yaml'
          ...
    ]

    def test_get_book_sell(self):
        response = self.client.get('/sell/book-sell')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Book Sell")
        self.assertContains(response, "El Quijote")#book name 

The view method linked to that path should load some data from the database and then render it. But when I run

python manage.py test app_name

it doesn't load data from fixtures, because the response doesn't contain "El Quijote". Only when I run:

python manage.py loaddata fixture_name.yaml ...

and then run again the tests the view method loads data from the database.

So I conclude that when I run the tests, my views methods load data from main database instead of test database

What is that I'm doing wrong? Is there a way to load just data from test database?

django version: 1.9.4 python version: 2.7.6 I'm sure that the fixtures load with sucess in test database

Aucun commentaire:

Enregistrer un commentaire