Code

Ticket #13636: fixtures-doctests-remove.diff

File fixtures-doctests-remove.diff, 51.1 KB (added by ericholscher, 4 years ago)
Line 
1commit eab20e90901ffa645534b869d3730eff90e9ba3e
2Author: Eric Holscher <eric@ericholscher.com>
3Date:   Thu May 27 17:43:59 2010 +0200
4
5    Change fixtures tests to unit tests. This should make these tests a lot
6    faster on real databases.
7
8diff --git a/django/core/management/base.py b/django/core/management/base.py
9index 4016faa..0bce8c8 100644
10--- a/django/core/management/base.py
11+++ b/django/core/management/base.py
12@@ -215,16 +215,20 @@ class BaseCommand(object):
13         try:
14             if self.requires_model_validation:
15                 self.validate()
16+            to_output = ""
17             output = self.handle(*args, **options)
18             if output:
19                 if self.output_transaction:
20                     # This needs to be imported here, because it relies on settings.
21                     from django.db import connection
22                     if connection.ops.start_transaction_sql():
23-                        print self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
24-                print output
25+                        to_output += self.style.SQL_KEYWORD(connection.ops.start_transaction_sql())
26+                to_output += output
27                 if self.output_transaction:
28-                    print self.style.SQL_KEYWORD("COMMIT;")
29+                    to_output += self.style.SQL_KEYWORD("COMMIT;")
30+                if options.get('return_output'):
31+                    return to_output
32+                print to_output
33         except CommandError, e:
34             sys.stderr.write(smart_str(self.style.ERROR('Error: %s\n' % e)))
35             sys.exit(1)
36diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py
37index 46e07a5..216a8e2 100644
38--- a/tests/modeltests/fixtures/models.py
39+++ b/tests/modeltests/fixtures/models.py
40@@ -90,230 +90,3 @@ class Book(models.Model):
41 
42     class Meta:
43         ordering = ('name',)
44-
45-__test__ = {'API_TESTS': """
46->>> from django.core import management
47->>> from django.db.models import get_app
48-
49-# Reset the database representation of this app.
50-# This will return the database to a clean initial state.
51->>> management.call_command('flush', verbosity=0, interactive=False)
52-
53-# Syncdb introduces 1 initial data object from initial_data.json.
54->>> Article.objects.all()
55-[<Article: Python program becomes self aware>]
56-
57-# Load fixture 1. Single JSON file, with two objects.
58->>> management.call_command('loaddata', 'fixture1.json', verbosity=0)
59->>> Article.objects.all()
60-[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
61-
62-# Dump the current contents of the database as a JSON fixture
63->>> management.call_command('dumpdata', 'fixtures', format='json')
64-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
65-
66-# Try just dumping the contents of fixtures.Category
67->>> management.call_command('dumpdata', 'fixtures.Category', format='json')
68-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]
69-
70-# ...and just fixtures.Article
71->>> management.call_command('dumpdata', 'fixtures.Article', format='json')
72-[{"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
73-
74-# ...and both
75->>> management.call_command('dumpdata', 'fixtures.Category', 'fixtures.Article', format='json')
76-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
77-
78-# Specify a specific model twice
79->>> management.call_command('dumpdata', 'fixtures.Article', 'fixtures.Article', format='json')
80-[{"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
81-
82-# Specify a dump that specifies Article both explicitly and implicitly
83->>> management.call_command('dumpdata', 'fixtures.Article', 'fixtures', format='json')
84-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
85-
86-# Same again, but specify in the reverse order
87->>> management.call_command('dumpdata', 'fixtures', 'fixtures.Article', format='json')
88-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
89-
90-# Specify one model from one application, and an entire other application.
91->>> management.call_command('dumpdata', 'fixtures.Category', 'sites', format='json')
92-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]
93-
94-# Load fixture 2. JSON file imported by default. Overwrites some existing objects
95->>> management.call_command('loaddata', 'fixture2.json', verbosity=0)
96->>> Article.objects.all()
97-[<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>]
98-
99-# Load fixture 3, XML format.
100->>> management.call_command('loaddata', 'fixture3.xml', verbosity=0)
101->>> Article.objects.all()
102-[<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>]
103-
104-# Load fixture 6, JSON file with dynamic ContentType fields. Testing ManyToOne.
105->>> management.call_command('loaddata', 'fixture6.json', verbosity=0)
106->>> Tag.objects.all()
107-[<Tag: <Article: Copyright is fine the way it is> tagged "copyright">, <Tag: <Article: Copyright is fine the way it is> tagged "law">]
108-
109-# Load fixture 7, XML file with dynamic ContentType fields. Testing ManyToOne.
110->>> management.call_command('loaddata', 'fixture7.xml', verbosity=0)
111->>> Tag.objects.all()
112-[<Tag: <Article: Copyright is fine the way it is> tagged "copyright">, <Tag: <Article: Copyright is fine the way it is> tagged "legal">, <Tag: <Article: Django conquers world!> tagged "django">, <Tag: <Article: Django conquers world!> tagged "world domination">]
113-
114-# Load fixture 8, JSON file with dynamic Permission fields. Testing ManyToMany.
115->>> management.call_command('loaddata', 'fixture8.json', verbosity=0)
116->>> Visa.objects.all()
117-[<Visa: Django Reinhardt Can add user, Can change user, Can delete user>, <Visa: Stephane Grappelli Can add user>, <Visa: Prince >]
118-
119-# Load fixture 9, XML file with dynamic Permission fields. Testing ManyToMany.
120->>> management.call_command('loaddata', 'fixture9.xml', verbosity=0)
121->>> Visa.objects.all()
122-[<Visa: Django Reinhardt Can add user, Can change user, Can delete user>, <Visa: Stephane Grappelli Can add user, Can delete user>, <Visa: Artist formerly known as "Prince" Can change user>]
123-
124->>> Book.objects.all()
125-[<Book: Music for all ages by Artist formerly known as "Prince" and Django Reinhardt>]
126-
127-# Load a fixture that doesn't exist
128->>> management.call_command('loaddata', 'unknown.json', verbosity=0)
129-
130-# object list is unaffected
131->>> Article.objects.all()
132-[<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>]
133-
134-# By default, you get raw keys on dumpdata
135->>> management.call_command('dumpdata', 'fixtures.book', format='json')
136-[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}]
137-
138-# But you can get natural keys if you ask for them and they are available
139->>> management.call_command('dumpdata', 'fixtures.book', format='json', use_natural_keys=True)
140-[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]
141-
142-# Dump the current contents of the database as a JSON fixture
143->>> management.call_command('dumpdata', 'fixtures', format='json', use_natural_keys=True)
144-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 5, "model": "fixtures.article", "fields": {"headline": "XML identified as leading cause of cancer", "pub_date": "2006-06-16 16:00:00"}}, {"pk": 4, "model": "fixtures.article", "fields": {"headline": "Django conquers world!", "pub_date": "2006-06-16 15:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16 14:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker on TV is great!", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 1, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": 3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "legal", "tagged_id": 3}}, {"pk": 3, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "django", "tagged_id": 4}}, {"pk": 4, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "world domination", "tagged_id": 4}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Artist formerly known as \\"Prince\\""}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 1, "model": "fixtures.visa", "fields": {"person": ["Django Reinhardt"], "permissions": [["add_user", "auth", "user"], ["change_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 2, "model": "fixtures.visa", "fields": {"person": ["Stephane Grappelli"], "permissions": [["add_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 3, "model": "fixtures.visa", "fields": {"person": ["Artist formerly known as \\"Prince\\""], "permissions": [["change_user", "auth", "user"]]}}, {"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]
145-
146-# Dump the current contents of the database as an XML fixture
147->>> management.call_command('dumpdata', 'fixtures', format='xml', use_natural_keys=True)
148-<?xml version="1.0" encoding="utf-8"?>
149-<django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="5" model="fixtures.article"><field type="CharField" name="headline">XML identified as leading cause of cancer</field><field type="DateTimeField" name="pub_date">2006-06-16 16:00:00</field></object><object pk="4" model="fixtures.article"><field type="CharField" name="headline">Django conquers world!</field><field type="DateTimeField" name="pub_date">2006-06-16 15:00:00</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Copyright is fine the way it is</field><field type="DateTimeField" name="pub_date">2006-06-16 14:00:00</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker on TV is great!</field><field type="DateTimeField" name="pub_date">2006-06-16 11:00:00</field></object><object pk="1" model="fixtures.article"><field type="CharField" name="headline">Python program becomes self aware</field><field type="DateTimeField" name="pub_date">2006-06-16 11:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">legal</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="3" model="fixtures.tag"><field type="CharField" name="name">django</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="4" model="fixtures.tag"><field type="CharField" name="name">world domination</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Artist formerly known as "Prince"</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="1" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Django Reinhardt</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>change_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="2" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Stephane Grappelli</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="3" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Artist formerly known as "Prince"</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>change_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="1" model="fixtures.book"><field type="CharField" name="name">Music for all ages</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"><object><natural>Artist formerly known as "Prince"</natural></object><object><natural>Django Reinhardt</natural></object></field></object></django-objects>
150-
151-"""}
152-
153-# Database flushing does not work on MySQL with the default storage engine
154-# because it requires transaction support.
155-if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':
156-    __test__['API_TESTS'] += \
157-"""
158-# Reset the database representation of this app. This will delete all data.
159->>> management.call_command('flush', verbosity=0, interactive=False)
160->>> Article.objects.all()
161-[<Article: Python program becomes self aware>]
162-
163-# Load fixture 1 again, using format discovery
164->>> management.call_command('loaddata', 'fixture1', verbosity=0)
165->>> Article.objects.all()
166-[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
167-
168-# Try to load fixture 2 using format discovery; this will fail
169-# because there are two fixture2's in the fixtures directory
170->>> management.call_command('loaddata', 'fixture2', verbosity=0) # doctest: +ELLIPSIS
171-Multiple fixtures named 'fixture2' in '...fixtures'. Aborting.
172-
173-# object list is unaffected
174->>> Article.objects.all()
175-[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
176-
177-# Dump the current contents of the database as a JSON fixture
178->>> management.call_command('dumpdata', 'fixtures', format='json')
179-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
180-
181-# Load fixture 4 (compressed), using format discovery
182->>> management.call_command('loaddata', 'fixture4', verbosity=0)
183->>> Article.objects.all()
184-[<Article: Django pets kitten>, <Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
185-
186->>> management.call_command('flush', verbosity=0, interactive=False)
187-
188-# Load fixture 4 (compressed), using format specification
189->>> management.call_command('loaddata', 'fixture4.json', verbosity=0)
190->>> Article.objects.all()
191-[<Article: Django pets kitten>, <Article: Python program becomes self aware>]
192-
193->>> management.call_command('flush', verbosity=0, interactive=False)
194-
195-# Load fixture 5 (compressed), using format *and* compression specification
196->>> management.call_command('loaddata', 'fixture5.json.zip', verbosity=0)
197->>> Article.objects.all()
198-[<Article: WoW subscribers now outnumber readers>, <Article: Python program becomes self aware>]
199-
200->>> management.call_command('flush', verbosity=0, interactive=False)
201-
202-# Load fixture 5 (compressed), only compression specification
203->>> management.call_command('loaddata', 'fixture5.zip', verbosity=0)
204->>> Article.objects.all()
205-[<Article: WoW subscribers now outnumber readers>, <Article: Python program becomes self aware>]
206-
207->>> management.call_command('flush', verbosity=0, interactive=False)
208-
209-# Try to load fixture 5 using format and compression discovery; this will fail
210-# because there are two fixture5's in the fixtures directory
211->>> management.call_command('loaddata', 'fixture5', verbosity=0) # doctest: +ELLIPSIS
212-Multiple fixtures named 'fixture5' in '...fixtures'. Aborting.
213-
214->>> management.call_command('flush', verbosity=0, interactive=False)
215-
216-# Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
217->>> management.call_command('loaddata', 'db_fixture_1', verbosity=0)
218->>> management.call_command('loaddata', 'db_fixture_2', verbosity=0)
219->>> Article.objects.all()
220-[<Article: Who needs more than one database?>, <Article: Who needs to use compressed data?>, <Article: Python program becomes self aware>]
221-
222->>> management.call_command('flush', verbosity=0, interactive=False)
223-
224-# Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
225->>> management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default')
226->>> management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default')
227->>> Article.objects.all()
228-[<Article: Who needs more than one database?>, <Article: Who needs to use compressed data?>, <Article: Python program becomes self aware>]
229-
230->>> management.call_command('flush', verbosity=0, interactive=False)
231-
232-# Try to load db fixture 3. This won't load because the database identifier doesn't match
233->>> management.call_command('loaddata', 'db_fixture_3', verbosity=0)
234->>> Article.objects.all()
235-[<Article: Python program becomes self aware>]
236-
237->>> management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default')
238->>> Article.objects.all()
239-[<Article: Python program becomes self aware>]
240-
241->>> management.call_command('flush', verbosity=0, interactive=False)
242-
243-# Load back in fixture 1, we need the articles from it
244->>> management.call_command('loaddata', 'fixture1', verbosity=0)
245-
246-# Try to load fixture 6 using format discovery
247->>> management.call_command('loaddata', 'fixture6', verbosity=0)
248->>> Tag.objects.all()
249-[<Tag: <Article: Time to reform copyright> tagged "copyright">, <Tag: <Article: Time to reform copyright> tagged "law">]
250-
251-# Dump the current contents of the database as a JSON fixture
252->>> management.call_command('dumpdata', 'fixtures', format='json', use_natural_keys=True)
253-[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 1, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": 3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "law", "tagged_id": 3}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Prince"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}]
254-
255-# Dump the current contents of the database as an XML fixture
256->>> management.call_command('dumpdata', 'fixtures', format='xml', use_natural_keys=True)
257-<?xml version="1.0" encoding="utf-8"?>
258-<django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Time to reform copyright</field><field type="DateTimeField" name="pub_date">2006-06-16 13:00:00</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16 12:00:00</field></object><object pk="1" model="fixtures.article"><field type="CharField" name="headline">Python program becomes self aware</field><field type="DateTimeField" name="pub_date">2006-06-16 11:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">law</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object></django-objects>
259-
260-"""
261-
262-from django.test import TestCase
263-
264-class SampleTestCase(TestCase):
265-    fixtures = ['fixture1.json', 'fixture2.json']
266-
267-    def testClassFixtures(self):
268-        "Check that test case has installed 4 fixture objects"
269-        self.assertEqual(Article.objects.count(), 4)
270-        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>]")
271diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
272new file mode 100644
273index 0000000..e9b9b3e
274--- /dev/null
275+++ b/tests/modeltests/fixtures/tests.py
276@@ -0,0 +1,198 @@
277+import StringIO
278+import sys
279+
280+from django.test import TestCase, TransactionTestCase
281+from django.core import management
282+
283+from models import *
284+
285+class SampleTestCase(TestCase):
286+    fixtures = ['fixture1.json', 'fixture2.json']
287+
288+    def testClassFixtures(self):
289+        "Check that test case has installed 4 fixture objects"
290+        self.assertEqual(Article.objects.count(), 4)
291+        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>]")
292+
293+class AnotherTestCase(TestCase):
294+
295+    def test_initial_data(self):
296+        # Syncdb introduces 1 initial data object from initial_data.json.
297+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Python program becomes self aware'])
298+
299+    def test_loading_and_dumping(self):
300+
301+        # Load fixture 1. Single JSON file, with two objects.
302+        management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
303+        # FIXME: Had to convert classes to strings. Ensure this looks right.
304+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Time to reform copyright', 'Poker has no place on ESPN', 'Python program becomes self aware'])
305+
306+        # Dump the current contents of the database as a JSON fixture
307+        self.assertEqual(management.call_command('dumpdata', 'fixtures', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
308+
309+        # Try just dumping the contents of fixtures.Category
310+        self.assertEqual(management.call_command('dumpdata', 'fixtures.Category', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]')
311+
312+        # ...and just fixtures.Article
313+        self.assertEqual(management.call_command('dumpdata', 'fixtures.Article', format='json', return_output=True), '[{"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
314+
315+        # ...and both
316+        self.assertEqual(management.call_command('dumpdata', 'fixtures.Category', 'fixtures.Article', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
317+
318+        # Specify a specific model twice
319+        self.assertEqual(management.call_command('dumpdata', 'fixtures.Article', 'fixtures.Article', format='json', return_output=True), '[{"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
320+
321+        # Specify a dump that specifies Article both explicitly and implicitly
322+        self.assertEqual(management.call_command('dumpdata', 'fixtures.Article', 'fixtures', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
323+
324+        # Same again, but specify in the reverse order
325+        self.assertEqual(management.call_command('dumpdata', 'fixtures', 'fixtures.Article', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
326+
327+        # Specify one model from one application, and an entire other application.
328+        self.assertEqual(management.call_command('dumpdata', 'fixtures.Category', 'sites', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]')
329+
330+        # Load fixture 2. JSON file imported by default. Overwrites some existing objects
331+        management.call_command('loaddata', 'fixture2.json', verbosity=0, commit=False)
332+        # FIXME: Had to convert classes to strings. Ensure this looks right.
333+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Django conquers world!', 'Copyright is fine the way it is', 'Poker has no place on ESPN', 'Python program becomes self aware'])
334+
335+        # Load fixture 3, XML format.
336+        management.call_command('loaddata', 'fixture3.xml', verbosity=0, commit=False)
337+        # FIXME: Had to convert classes to strings. Ensure this looks right.
338+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['XML identified as leading cause of cancer', 'Django conquers world!', 'Copyright is fine the way it is', 'Poker on TV is great!', 'Python program becomes self aware'])
339+
340+        # Load fixture 6, JSON file with dynamic ContentType fields. Testing ManyToOne.
341+        management.call_command('loaddata', 'fixture6.json', verbosity=0, commit=False)
342+        # FIXME: Had to convert classes to strings. Ensure this looks right.
343+        self.assertEqual([str(obj) for obj in Tag.objects.all()], ['<Article: Copyright is fine the way it is> tagged "copyright"', '<Article: Copyright is fine the way it is> tagged "law"'])
344+
345+        # Load fixture 7, XML file with dynamic ContentType fields. Testing ManyToOne.
346+        management.call_command('loaddata', 'fixture7.xml', verbosity=0, commit=False)
347+        # FIXME: Had to convert classes to strings. Ensure this looks right.
348+        self.assertEqual([str(obj) for obj in Tag.objects.all()], ['<Article: Copyright is fine the way it is> tagged "copyright"', '<Article: Copyright is fine the way it is> tagged "legal"', '<Article: Django conquers world!> tagged "django"', '<Article: Django conquers world!> tagged "world domination"'])
349+
350+        # Load fixture 8, JSON file with dynamic Permission fields. Testing ManyToMany.
351+        management.call_command('loaddata', 'fixture8.json', verbosity=0, commit=False)
352+        # FIXME: Had to convert classes to strings. Ensure this looks right.
353+        self.assertEqual([str(obj) for obj in Visa.objects.all()], ['Django Reinhardt Can add user, Can change user, Can delete user', 'Stephane Grappelli Can add user', 'Prince '])
354+
355+        # Load fixture 9, XML file with dynamic Permission fields. Testing ManyToMany.
356+        management.call_command('loaddata', 'fixture9.xml', verbosity=0, commit=False)
357+        # FIXME: Had to convert classes to strings. Ensure this looks right.
358+        self.assertEqual([str(obj) for obj in Visa.objects.all()], ['Django Reinhardt Can add user, Can change user, Can delete user', 'Stephane Grappelli Can add user, Can delete user', 'Artist formerly known as "Prince" Can change user'])
359+
360+        # FIXME: Had to convert classes to strings. Ensure this looks right.
361+        self.assertEqual([str(obj) for obj in Book.objects.all()], ['Music for all ages by Artist formerly known as "Prince" and Django Reinhardt'])
362+
363+        # Load a fixture that doesn't exist
364+        management.call_command('loaddata', 'unknown.json', verbosity=0, commit=False)
365+
366+        # object list is unaffected
367+        # FIXME: Had to convert classes to strings. Ensure this looks right.
368+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['XML identified as leading cause of cancer', 'Django conquers world!', 'Copyright is fine the way it is', 'Poker on TV is great!', 'Python program becomes self aware'])
369+
370+        # By default, you get raw keys on dumpdata
371+        self.assertEqual(management.call_command('dumpdata', 'fixtures.book', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}]')
372+
373+        # But you can get natural keys if you ask for them and they are available
374+        self.assertEqual(management.call_command('dumpdata', 'fixtures.book', format='json', use_natural_keys=True, return_output=True), '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]')
375+
376+        # Dump the current contents of the database as a JSON fixture
377+        self.assertEqual(management.call_command('dumpdata', 'fixtures', format='json', use_natural_keys=True, return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 5, "model": "fixtures.article", "fields": {"headline": "XML identified as leading cause of cancer", "pub_date": "2006-06-16 16:00:00"}}, {"pk": 4, "model": "fixtures.article", "fields": {"headline": "Django conquers world!", "pub_date": "2006-06-16 15:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16 14:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker on TV is great!", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 1, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": 3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "legal", "tagged_id": 3}}, {"pk": 3, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "django", "tagged_id": 4}}, {"pk": 4, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "world domination", "tagged_id": 4}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Artist formerly known as \\"Prince\\""}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 1, "model": "fixtures.visa", "fields": {"person": ["Django Reinhardt"], "permissions": [["add_user", "auth", "user"], ["change_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 2, "model": "fixtures.visa", "fields": {"person": ["Stephane Grappelli"], "permissions": [["add_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 3, "model": "fixtures.visa", "fields": {"person": ["Artist formerly known as \\"Prince\\""], "permissions": [["change_user", "auth", "user"]]}}, {"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]')
378+
379+        # Dump the current contents of the database as an XML fixture
380+        self.assertEqual(management.call_command('dumpdata', 'fixtures', format='xml', use_natural_keys=True, return_output=True), """<?xml version="1.0" encoding="utf-8"?>
381+<django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="5" model="fixtures.article"><field type="CharField" name="headline">XML identified as leading cause of cancer</field><field type="DateTimeField" name="pub_date">2006-06-16 16:00:00</field></object><object pk="4" model="fixtures.article"><field type="CharField" name="headline">Django conquers world!</field><field type="DateTimeField" name="pub_date">2006-06-16 15:00:00</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Copyright is fine the way it is</field><field type="DateTimeField" name="pub_date">2006-06-16 14:00:00</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker on TV is great!</field><field type="DateTimeField" name="pub_date">2006-06-16 11:00:00</field></object><object pk="1" model="fixtures.article"><field type="CharField" name="headline">Python program becomes self aware</field><field type="DateTimeField" name="pub_date">2006-06-16 11:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">legal</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="3" model="fixtures.tag"><field type="CharField" name="name">django</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="4" model="fixtures.tag"><field type="CharField" name="name">world domination</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Artist formerly known as "Prince"</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="1" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Django Reinhardt</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>change_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="2" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Stephane Grappelli</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="3" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Artist formerly known as "Prince"</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>change_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="1" model="fixtures.book"><field type="CharField" name="name">Music for all ages</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"><object><natural>Artist formerly known as "Prince"</natural></object><object><natural>Django Reinhardt</natural></object></field></object></django-objects>""")
382+
383+
384+    def test_awesome(self):
385+        # Load fixture 4 (compressed), using format specification
386+        management.call_command('loaddata', 'fixture4.json', verbosity=0, commit=False)
387+        # FIXME: Had to convert classes to strings. Ensure this looks right.
388+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Django pets kitten', 'Python program becomes self aware'])
389+
390+    def test_more_awesome(self):
391+        # Load fixture 5 (compressed), using format *and* compression specification
392+        management.call_command('loaddata', 'fixture5.json.zip', verbosity=0, commit=False)
393+        # FIXME: Had to convert classes to strings. Ensure this looks right.
394+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['WoW subscribers now outnumber readers', 'Python program becomes self aware'])
395+
396+    def test_most_awesome(self):
397+
398+        # Load fixture 5 (compressed), only compression specification
399+        management.call_command('loaddata', 'fixture5.zip', verbosity=0, commit=False)
400+        # FIXME: Had to convert classes to strings. Ensure this looks right.
401+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['WoW subscribers now outnumber readers', 'Python program becomes self aware'])
402+
403+    def test_bojangling(self):
404+
405+        # Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
406+        management.call_command('loaddata', 'db_fixture_1', verbosity=0, commit=False)
407+        management.call_command('loaddata', 'db_fixture_2', verbosity=0, commit=False)
408+        # FIXME: Had to convert classes to strings. Ensure this looks right.
409+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Who needs more than one database?', 'Who needs to use compressed data?', 'Python program becomes self aware'])
410+
411+    def test_zomgwtf(self):
412+
413+        # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
414+        management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default', commit=False)
415+        management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default', commit=False)
416+        # FIXME: Had to convert classes to strings. Ensure this looks right.
417+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Who needs more than one database?', 'Who needs to use compressed data?', 'Python program becomes self aware'])
418+
419+    def test_no_more_flushing(self):
420+
421+        # Try to load db fixture 3. This won't load because the database identifier doesn't match
422+        management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False)
423+        # FIXME: Had to convert classes to strings. Ensure this looks right.
424+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Python program becomes self aware'])
425+
426+        management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False)
427+        # FIXME: Had to convert classes to strings. Ensure this looks right.
428+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Python program becomes self aware'])
429+
430+    def test_down_with_flushing(self):
431+
432+        # Load back in fixture 1, we need the articles from it
433+        management.call_command('loaddata', 'fixture1', verbosity=0, commit=False)
434+
435+        # Try to load fixture 6 using format discovery
436+        management.call_command('loaddata', 'fixture6', verbosity=0, commit=False)
437+        # FIXME: Had to convert classes to strings. Ensure this looks right.
438+        self.assertEqual([str(obj) for obj in Tag.objects.all()], ['<Article: Time to reform copyright> tagged "copyright"', '<Article: Time to reform copyright> tagged "law"'])
439+
440+        # Dump the current contents of the database as a JSON fixture
441+        self.assertEqual(management.call_command('dumpdata', 'fixtures', format='json', use_natural_keys=True, return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 1, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": 3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "law", "tagged_id": 3}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Prince"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}]')
442+
443+        # Dump the current contents of the database as an XML fixture
444+        self.assertEqual(management.call_command('dumpdata', 'fixtures', format='xml', use_natural_keys=True, return_output=True), """<?xml version="1.0" encoding="utf-8"?>
445+<django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Time to reform copyright</field><field type="DateTimeField" name="pub_date">2006-06-16 13:00:00</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16 12:00:00</field></object><object pk="1" model="fixtures.article"><field type="CharField" name="headline">Python program becomes self aware</field><field type="DateTimeField" name="pub_date">2006-06-16 11:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">law</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object></django-objects>""")
446+
447+class TransTests(TransactionTestCase):
448+
449+    def test_format_discovery(self):
450+
451+        # Load fixture 1 again, using format discovery
452+        management.call_command('loaddata', 'fixture1', verbosity=0, commit=False)
453+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Time to reform copyright', 'Poker has no place on ESPN', 'Python program becomes self aware'])
454+
455+        # Try to load fixture 2 using format discovery; this will fail
456+        # because there are two fixture2's in the fixtures directory
457+        old_io = sys.stdout
458+        new_io = StringIO.StringIO()
459+        sys.stdout = new_io
460+        management.call_command('loaddata', 'fixture2', verbosity=0)
461+        output = new_io.getvalue().strip()
462+        self.assertTrue("Multiple fixtures named 'fixture2'" in output)
463+        sys.stdout = old_io
464+
465+        # object list is unaffected
466+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Time to reform copyright', 'Poker has no place on ESPN', 'Python program becomes self aware'])
467+
468+        # Dump the current contents of the database as a JSON fixture
469+        self.assertEqual(management.call_command('dumpdata', 'fixtures', format='json', return_output=True), '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": 1, "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]')
470+
471+        # Load fixture 4 (compressed), using format discovery
472+        management.call_command('loaddata', 'fixture4', verbosity=0, commit=False)
473+        # FIXME: Had to convert classes to strings. Ensure this looks right.
474+        self.assertEqual([str(obj) for obj in Article.objects.all()], ['Django pets kitten', 'Time to reform copyright', 'Poker has no place on ESPN', 'Python program becomes self aware'])
475\ No newline at end of file