Loading tests/fixtures/tests.py +30 −12 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ from django.contrib.sites.models import Site from django.core import management from django.db import connection, IntegrityError from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.utils.encoding import force_text from django.utils import six from .models import Article, Book, Spy, Tag, Visa Loading Loading @@ -165,18 +166,6 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): '<Book: Music for all ages by Artist formerly known as "Prince" and Django Reinhardt>' ]) # Loading a fixture that doesn't exist emits a warning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") management.call_command('loaddata', 'unknown.json', verbosity=0) self.assertEqual(len(w), 1) self.assertTrue(w[0].message, "No fixture named 'unknown' found.") # An attempt to load a nonexistent 'initial_data' fixture isn't an error with warnings.catch_warnings(record=True) as w: management.call_command('loaddata', 'initial_data.json', verbosity=0) self.assertEqual(len(w), 0) # object list is unaffected self.assertQuerysetEqual(Article.objects.all(), [ '<Article: XML identified as leading cause of cancer>', Loading Loading @@ -396,6 +385,35 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): <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="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</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-16T13: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="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>""", format='xml', natural_foreign_keys=True) class NonExistentFixtureTests(TestCase): """ Custom class to limit fixture dirs. """ available_apps = ['django.contrib.auth', 'django.contrib.contenttypes'] def test_loaddata_not_existent_fixture_file(self): stdout_output = six.StringIO() with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") # With verbosity=2, we get both stdout output and a warning management.call_command( 'loaddata', 'this_fixture_doesnt_exist', verbosity=2, stdout=stdout_output, ) self.assertIn("No fixture 'this_fixture_doesnt_exist' in", force_text(stdout_output.getvalue())) self.assertEqual(len(w), 1) self.assertEqual(force_text(w[0].message), "No fixture named 'this_fixture_doesnt_exist' found.") # An attempt to load a non-existent 'initial_data' fixture doesn't produce any warning with warnings.catch_warnings(record=True) as w: management.call_command('loaddata', 'initial_data.json', verbosity=0) self.assertEqual(len(w), 0) class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase): available_apps = [ Loading tests/fixtures_regress/tests.py +0 −13 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ from django.db.models import signals from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature) from django.test import override_settings from django.utils.encoding import force_text from django.utils._os import upath from django.utils import six from django.utils.six import PY3, StringIO Loading Loading @@ -465,18 +464,6 @@ class TestFixtures(TestCase): verbosity=0, ) def test_loaddata_not_existant_fixture_file(self): stdout_output = StringIO() with warnings.catch_warnings(record=True): management.call_command( 'loaddata', 'this_fixture_doesnt_exist', verbosity=2, stdout=stdout_output, ) self.assertTrue("No fixture 'this_fixture_doesnt_exist' in" in force_text(stdout_output.getvalue())) def test_ticket_20820(self): """ Regression for ticket #20820 -- loaddata on a model that inherits Loading Loading
tests/fixtures/tests.py +30 −12 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ from django.contrib.sites.models import Site from django.core import management from django.db import connection, IntegrityError from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.utils.encoding import force_text from django.utils import six from .models import Article, Book, Spy, Tag, Visa Loading Loading @@ -165,18 +166,6 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): '<Book: Music for all ages by Artist formerly known as "Prince" and Django Reinhardt>' ]) # Loading a fixture that doesn't exist emits a warning with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") management.call_command('loaddata', 'unknown.json', verbosity=0) self.assertEqual(len(w), 1) self.assertTrue(w[0].message, "No fixture named 'unknown' found.") # An attempt to load a nonexistent 'initial_data' fixture isn't an error with warnings.catch_warnings(record=True) as w: management.call_command('loaddata', 'initial_data.json', verbosity=0) self.assertEqual(len(w), 0) # object list is unaffected self.assertQuerysetEqual(Article.objects.all(), [ '<Article: XML identified as leading cause of cancer>', Loading Loading @@ -396,6 +385,35 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): <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="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</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-16T13: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="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>""", format='xml', natural_foreign_keys=True) class NonExistentFixtureTests(TestCase): """ Custom class to limit fixture dirs. """ available_apps = ['django.contrib.auth', 'django.contrib.contenttypes'] def test_loaddata_not_existent_fixture_file(self): stdout_output = six.StringIO() with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") # With verbosity=2, we get both stdout output and a warning management.call_command( 'loaddata', 'this_fixture_doesnt_exist', verbosity=2, stdout=stdout_output, ) self.assertIn("No fixture 'this_fixture_doesnt_exist' in", force_text(stdout_output.getvalue())) self.assertEqual(len(w), 1) self.assertEqual(force_text(w[0].message), "No fixture named 'this_fixture_doesnt_exist' found.") # An attempt to load a non-existent 'initial_data' fixture doesn't produce any warning with warnings.catch_warnings(record=True) as w: management.call_command('loaddata', 'initial_data.json', verbosity=0) self.assertEqual(len(w), 0) class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase): available_apps = [ Loading
tests/fixtures_regress/tests.py +0 −13 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ from django.db.models import signals from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature) from django.test import override_settings from django.utils.encoding import force_text from django.utils._os import upath from django.utils import six from django.utils.six import PY3, StringIO Loading Loading @@ -465,18 +464,6 @@ class TestFixtures(TestCase): verbosity=0, ) def test_loaddata_not_existant_fixture_file(self): stdout_output = StringIO() with warnings.catch_warnings(record=True): management.call_command( 'loaddata', 'this_fixture_doesnt_exist', verbosity=2, stdout=stdout_output, ) self.assertTrue("No fixture 'this_fixture_doesnt_exist' in" in force_text(stdout_output.getvalue())) def test_ticket_20820(self): """ Regression for ticket #20820 -- loaddata on a model that inherits Loading