12
12
app_label = 'fixtures_model_package'
13
13
ordering = ('-pub_date', 'headline')
15
__test__ = {'API_TESTS': """
16
>>> from django.core import management
17
>>> from django.db.models import get_app
19
# Reset the database representation of this app.
20
# This will return the database to a clean initial state.
21
>>> management.call_command('flush', verbosity=0, interactive=False)
23
# Syncdb introduces 1 initial data object from initial_data.json.
24
>>> Article.objects.all()
25
[<Article: Python program becomes self aware>]
27
# Load fixture 1. Single JSON file, with two objects.
28
>>> management.call_command('loaddata', 'fixture1.json', verbosity=0)
29
>>> Article.objects.all()
30
[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
32
# Load fixture 2. JSON file imported by default. Overwrites some existing objects
33
>>> management.call_command('loaddata', 'fixture2.json', verbosity=0)
34
>>> Article.objects.all()
35
[<Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
37
# Load a fixture that doesn't exist
38
>>> management.call_command('loaddata', 'unknown.json', verbosity=0)
40
# object list is unaffected
41
>>> Article.objects.all()
42
[<Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
46
from django.test import TestCase
48
class SampleTestCase(TestCase):
49
fixtures = ['fixture1.json', 'fixture2.json']
51
def testClassFixtures(self):
52
"Check that test case has installed 4 fixture objects"
53
self.assertEqual(Article.objects.count(), 4)
54
self.assertEquals(str(Article.objects.all()), "[<Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]")