diff options
Diffstat (limited to 'tests/modeltests')
| -rw-r--r-- | tests/modeltests/fixtures/tests.py | 51 | ||||
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 14 |
2 files changed, 56 insertions, 9 deletions
diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py index 4facc6dee9..e818423b48 100644 --- a/tests/modeltests/fixtures/tests.py +++ b/tests/modeltests/fixtures/tests.py @@ -23,9 +23,14 @@ class TestCaseFixtureLoadingTests(TestCase): class FixtureLoadingTests(TestCase): - def _dumpdata_assert(self, args, output, format='json', natural_keys=False): + def _dumpdata_assert(self, args, output, format='json', natural_keys=False, + exclude_list=[]): new_io = StringIO.StringIO() - management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io, 'use_natural_keys':natural_keys}) + management.call_command('dumpdata', *args, **{'format':format, + 'stdout':new_io, + 'stderr':new_io, + 'use_natural_keys':natural_keys, + 'exclude': exclude_list}) command_output = new_io.getvalue().strip() self.assertEqual(command_output, output) @@ -150,6 +155,48 @@ class FixtureLoadingTests(TestCase): self._dumpdata_assert(['fixtures'], """<?xml version="1.0" encoding="utf-8"?> <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>""", format='xml', natural_keys=True) + def test_dumpdata_with_excludes(self): + # Load fixture1 which has a site, two articles, and a category + management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False) + + # Excluding fixtures app should only leave sites + self._dumpdata_assert( + ['sites', 'fixtures'], + '[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]', + exclude_list=['fixtures']) + + # Excluding fixtures.Article should leave fixtures.Category + self._dumpdata_assert( + ['sites', 'fixtures'], + '[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]', + exclude_list=['fixtures.Article']) + + # Excluding fixtures and fixtures.Article should be a no-op + self._dumpdata_assert( + ['sites', 'fixtures'], + '[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]', + exclude_list=['fixtures.Article']) + + # Excluding sites and fixtures.Article should only leave fixtures.Category + self._dumpdata_assert( + ['sites', 'fixtures'], + '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]', + exclude_list=['fixtures.Article', 'sites']) + + # Excluding a bogus app should throw an error + self.assertRaises(SystemExit, + self._dumpdata_assert, + ['fixtures', 'sites'], + '', + exclude_list=['foo_app']) + + # Excluding a bogus model should throw an error + self.assertRaises(SystemExit, + self._dumpdata_assert, + ['fixtures', 'sites'], + '', + exclude_list=['fixtures.FooModel']) + def test_compress_format_loading(self): # Load fixture 4 (compressed), using format specification management.call_command('loaddata', 'fixture4.json', verbosity=0, commit=False) diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 1087cf8795..7ded82bb7c 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -554,7 +554,7 @@ fields with the 'choices' attribute are represented by a ChoiceField. <option value="1">Entertainment</option> <option value="2">It's a test</option> <option value="3">Third test</option> -</select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr> +</select><br /><span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></td></tr> You can restrict a form to a subset of the complete list of fields by providing a 'fields' argument. If you try to save a @@ -579,7 +579,7 @@ inserted as 'initial' data in each Field. ... model = Writer >>> f = RoykoForm(auto_id=False, instance=w) >>> print f -<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br />Use both first and last names.</td></tr> +<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /><span class="helptext">Use both first and last names.</span></td></tr> >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.') >>> art.save() @@ -609,7 +609,7 @@ inserted as 'initial' data in each Field. <option value="1">Entertainment</option> <option value="2">It's a test</option> <option value="3">Third test</option> -</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> +</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': unicode(w_royko.pk), 'article': 'Hello.'}, instance=art) >>> f.errors {} @@ -672,7 +672,7 @@ Add some categories and test the many-to-many form output. <option value="1" selected="selected">Entertainment</option> <option value="2">It's a test</option> <option value="3">Third test</option> -</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> +</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> Initial values can be provided for model forms >>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': ['1','2']}) @@ -696,7 +696,7 @@ Initial values can be provided for model forms <option value="1" selected="selected">Entertainment</option> <option value="2" selected="selected">It's a test</option> <option value="3">Third test</option> -</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> +</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04', ... 'writer': unicode(w_royko.pk), 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art) @@ -812,7 +812,7 @@ the data in the database when the form is instantiated. <option value="1">Entertainment</option> <option value="2">It's a test</option> <option value="3">Third</option> -</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> +</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> >>> Category.objects.create(name='Fourth', url='4th') <Category: Fourth> >>> Writer.objects.create(name='Carl Bernstein') @@ -839,7 +839,7 @@ the data in the database when the form is instantiated. <option value="2">It's a test</option> <option value="3">Third</option> <option value="4">Fourth</option> -</select> Hold down "Control", or "Command" on a Mac, to select more than one.</li> +</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li> # ModelChoiceField ############################################################ |
