Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django test not loading fixture data

I have written tests for a Django project that i am working on, but one particular fixture fails to load. The fixture is generated using dumpdata and i havent fiddled with it at all. I can load the data using manage.py on that fixture without errors. I have verified that the data actually loaded using shell and querying the data. This is driving me nuts, any help would be much appreciated.

Here is my test file (irrelevant portions removed):

class ViewsFromUrls(TestCase):
    fixtures = [
        'centers/fixtures/test_data.json',
        'intranet/fixtures/test_data.json',
        'training/fixtures/test_data.json', #The one that fails to load
        ]

    def setUp(self):
        self.c = Client()
        self.c.login(username='USER', password='PASS')

    ...

    def test_ViewBatch(self):
        b = Batch.objects.all()[0].ticket_number
        response = self.c.get(reverse('training.views.view_batch', kwargs={'id':b}))
        self.assertTrue(response.status_code, 200)
    ...
like image 530
zsquare Avatar asked Jan 11 '11 07:01

zsquare


1 Answers

Import the TestCase from django.test:

from django.test import TestCase

class test_something(TestCase):
    fixtures = ['one.json', 'two.json']
    ...
  • Not: import unittest
  • Not: import django.utils.unittest
  • But: import django.test

That's a day of frustration right there. Stop complaining - it's in the docs :-/

like image 114
John Mee Avatar answered Sep 21 '22 20:09

John Mee