Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django load test fixtures with django-nose

How do you load test fixtures using the django-nose test runner?

like image 614
epoch Avatar asked Feb 27 '23 04:02

epoch


2 Answers

#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']
like image 179
baklarz2048 Avatar answered Mar 07 '23 18:03

baklarz2048


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
like image 43
mhost Avatar answered Mar 07 '23 18:03

mhost