Django load test fixtures with django-nose
How do you load test fixtures us开发者_StackOverflowing the django-nose test runner?
#settings.test.py
INSTALLED_APPS += ('django_nose', )
TEST_RUNNER = 'django_nose.run_tests'
#appname/tests.py
from datetime import date,datetime, timedelta
from django.contrib.auth.models import User
from django.test.client import Client
from django.test import TestCase
class BetViewsTestCase(TestCase):
#files placed in appname/fixtures/restaurant.json, appname/fixtures/map.json
fixtures = ['authtestdata.json', 'restaurant.json', 'map.json']
In your setup method, just call:
management.call_command('loaddata', 'Category.json', verbosity=0)
Then in your teardown, call:
management.call_command('flush', verbosity=0, interactive=False)
You can import management from here:
from django.core import management
Just make the test case a subclass of FastFixtureTestCase.
from django_nose import FastFixtureTestCase
from myapp.models import MyModel
from nose_tools import eq_
class TestFixtureLoading(FastFixtureTestCase):
fixtures = ['mymodel_data.yaml']
def test_fixture_loading(self):
eq_(1, MyModel.objects.count())
And then:
python manage.py test
精彩评论