diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 3158d65841..090e26357a 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -5,7 +5,6 @@ from importlib import import_module from django.apps import apps from django.db import connections, router, transaction, DEFAULT_DB_ALIAS -from django.core.management import call_command from django.core.management.base import BaseCommand, CommandError from django.core.management.color import no_style from django.core.management.sql import sql_flush, emit_post_migrate_signal @@ -15,8 +14,7 @@ from django.utils import six class Command(BaseCommand): help = ('Removes ALL DATA from the database, including data added during ' - 'migrations. Unmigrated apps will also have their initial_data ' - 'fixture reloaded. Does not achieve a "fresh install" state.') + 'migrations. Does not achieve a "fresh install" state.') def add_arguments(self, parser): parser.add_argument('--noinput', action='store_false', dest='interactive', default=True, @@ -24,9 +22,6 @@ class Command(BaseCommand): parser.add_argument('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS, help='Nominates a database to flush. Defaults to the "default" database.') - parser.add_argument('--no-initial-data', action='store_false', - dest='load_initial_data', default=True, - help='Tells Django not to load any initial data after database synchronization.') def handle(self, **options): database = options.get('database') @@ -82,16 +77,6 @@ Are you sure you want to do this? if not inhibit_post_migrate: self.emit_post_migrate(verbosity, interactive, database) - - # Reinstall the initial_data fixture. - if options.get('load_initial_data'): - # Reinstall the initial_data fixture for apps without migrations. - from django.db.migrations.executor import MigrationExecutor - executor = MigrationExecutor(connection) - app_options = options.copy() - for app_label in executor.loader.unmigrated_apps: - app_options['app_label'] = app_label - call_command('loaddata', 'initial_data', **app_options) else: self.stdout.write("Flush cancelled.\n") diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index aae69afc9b..15a90d727b 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -18,7 +18,6 @@ from django.utils import lru_cache from django.utils.encoding import force_text from django.utils.functional import cached_property from django.utils._os import upath -from django.utils.deprecation import RemovedInDjango19Warning from itertools import product try: @@ -218,14 +217,9 @@ class Command(BaseCommand): (fixture_name, humanize(fixture_dir))) fixture_files.extend(fixture_files_in_dir) - if fixture_name != 'initial_data' and not fixture_files: + if not fixture_files: # Warning kept for backwards-compatibility; why not an exception? warnings.warn("No fixture named '%s' found." % fixture_name) - elif fixture_name == 'initial_data' and fixture_files: - warnings.warn( - 'initial_data fixtures are deprecated. Use data migrations instead.', - RemovedInDjango19Warning - ) return fixture_files diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index c8fdde2b01..54d3617368 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -35,8 +35,6 @@ class Command(BaseCommand): ) parser.add_argument('--noinput', action='store_false', dest='interactive', default=True, help='Tells Django to NOT prompt the user for input of any kind.') - parser.add_argument('--no-initial-data', action='store_false', dest='load_initial_data', default=True, - help='Tells Django not to load any initial data after database synchronization.') parser.add_argument('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. ' 'Defaults to the "default" database.') @@ -50,7 +48,6 @@ class Command(BaseCommand): self.verbosity = options.get('verbosity') self.interactive = options.get('interactive') self.show_traceback = options.get('traceback') - self.load_initial_data = options.get('load_initial_data') # Import the 'management' module within each installed app, to register # dispatcher events. @@ -339,13 +336,4 @@ class Command(BaseCommand): finally: cursor.close() - # Load initial_data fixtures (unless that has been disabled) - if self.load_initial_data: - for app_label in app_labels: - call_command( - 'loaddata', 'initial_data', verbosity=self.verbosity, - database=connection.alias, app_label=app_label, - hide_empty=True, - ) - return created_models diff --git a/docs/howto/initial-data.txt b/docs/howto/initial-data.txt index b7e00d1346..6b40c5a5d8 100644 --- a/docs/howto/initial-data.txt +++ b/docs/howto/initial-data.txt @@ -76,21 +76,6 @@ from the fixture and re-loaded into the database. Note this means that if you change one of the rows created by a fixture and then run :djadmin:`loaddata` again, you'll wipe out any changes you've made. -Automatically loading initial data fixtures -------------------------------------------- - -.. deprecated:: 1.7 - - If an application uses migrations, there is no automatic loading of - fixtures. Since migrations will be required for applications in Django 1.9, - this behavior is considered deprecated. If you want to load initial data - for an app, consider doing it in a :ref:`data migration `. - -If you create a fixture named ``initial_data.[xml/yaml/json]``, that fixture will -be loaded every time you run :djadmin:`migrate`. This is extremely convenient, -but be careful: remember that the data will be refreshed *every time* you run -:djadmin:`migrate`. So don't use ``initial_data`` for data you'll want to edit. - Where Django finds fixture files -------------------------------- diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index 728432eecc..29c9537dad 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -341,12 +341,6 @@ prompts. The :djadminopt:`--database` option may be used to specify the database to flush. -``--no-initial-data`` -~~~~~~~~~~~~~~~~~~~~~ - -Use ``--no-initial-data`` to avoid loading the initial_data fixture. - - inspectdb --------- diff --git a/docs/topics/testing/overview.txt b/docs/topics/testing/overview.txt index 0aca7fb0a4..57bdfaa0ca 100644 --- a/docs/topics/testing/overview.txt +++ b/docs/topics/testing/overview.txt @@ -260,9 +260,6 @@ The initial serialization is usually very quick, but if you wish to exclude some apps from this process (and speed up test runs slightly), you may add those apps to :setting:`TEST_NON_SERIALIZED_APPS`. -Apps without migrations are not affected; ``initial_data`` fixtures are -reloaded as usual. - Other test conditions --------------------- @@ -288,8 +285,6 @@ prepares itself. You can control the level of detail of these messages with the Creating test database... Creating table myapp_animal Creating table myapp_mineral - Loading 'initial_data' fixtures... - No fixtures found. This tells you that the test runner is creating a test database, as described in the previous section. diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index b9755305cb..1f794701be 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -984,18 +984,6 @@ The most straightforward way of creating a fixture is to use the already have some data in your database. See the :djadmin:`dumpdata documentation` for more details. -.. note:: - - If you've ever run :djadmin:`manage.py migrate`, you've - already used a fixture without even knowing it! When you call - :djadmin:`migrate` in the database for the first time, Django - installs a fixture called ``initial_data``. This gives you a way - of populating a new database with any initial data, such as a - default set of categories. - - Fixtures with other names can always be installed manually using - the :djadmin:`manage.py loaddata` command. - .. admonition:: Initial SQL data and testing Django provides a second way to insert initial data into models -- diff --git a/tests/fixtures/fixtures/initial_data.json b/tests/fixtures/fixtures/initial_data.json deleted file mode 100644 index 8458bb9f0e..0000000000 --- a/tests/fixtures/fixtures/initial_data.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "pk": "10", - "model": "fixtures.book", - "fields": { - "name": "Achieving self-awareness of Python programs" - } - } -] diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 0201693dba..109d98bec3 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -11,7 +11,7 @@ from django.test import TestCase, TransactionTestCase, ignore_warnings, skipUnle from django.utils.encoding import force_text from django.utils import six -from .models import Article, Book, Spy, Tag, Visa +from .models import Article, Spy, Tag, Visa class TestCaseFixtureLoadingTests(TestCase): @@ -69,13 +69,6 @@ class DumpDataAssertMixin(object): class FixtureLoadingTests(DumpDataAssertMixin, TestCase): - def test_initial_data(self): - # migrate introduces 1 initial data object from initial_data.json. - # this behavior is deprecated and will be removed in Django 1.9 - self.assertQuerysetEqual(Book.objects.all(), [ - '' - ]) - def test_loading_and_dumping(self): apps.clear_cache() Site.objects.all().delete() @@ -87,7 +80,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): ]) # Dump the current contents of the database as a JSON fixture - self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Try just dumping the contents of fixtures.Category self._dumpdata_assert(['fixtures.Category'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]') @@ -102,14 +95,14 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): self._dumpdata_assert(['fixtures.Article', 'fixtures.Article'], '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Specify a dump that specifies Article both explicitly and implicitly - self._dumpdata_assert(['fixtures.Article', 'fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + self._dumpdata_assert(['fixtures.Article', 'fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Specify a dump that specifies Article both explicitly and implicitly, # but lists the app first (#22025). - self._dumpdata_assert(['fixtures', 'fixtures.Article'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + self._dumpdata_assert(['fixtures', 'fixtures.Article'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Same again, but specify in the reverse order - self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Specify one model from one application, and an entire other application. self._dumpdata_assert(['fixtures.Category', 'sites'], '[{"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"}}]') @@ -163,11 +156,6 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): '' ], ordered=False) - self.assertQuerysetEqual(Book.objects.all(), [ - '', - '' - ]) - # object list is unaffected self.assertQuerysetEqual(Article.objects.all(), [ '', @@ -177,20 +165,20 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): ]) # By default, you get raw keys on dumpdata - self._dumpdata_assert(['fixtures.book'], '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + self._dumpdata_assert(['fixtures.book'], '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}]') # But you can get natural keys if you ask for them and they are available - self._dumpdata_assert(['fixtures.book'], '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', natural_foreign_keys=True) + self._dumpdata_assert(['fixtures.book'], '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}]', natural_foreign_keys=True) # You can also omit the primary keys for models that we can get later with natural keys. self._dumpdata_assert(['fixtures.person'], '[{"fields": {"name": "Django Reinhardt"}, "model": "fixtures.person"}, {"fields": {"name": "Stephane Grappelli"}, "model": "fixtures.person"}, {"fields": {"name": "Artist formerly known as \\"Prince\\""}, "model": "fixtures.person"}]', natural_primary_keys=True) # Dump the current contents of the database as a JSON fixture - self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker on TV is great!", "pub_date": "2006-06-16T11:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}, {"pk": 4, "model": "fixtures.article", "fields": {"headline": "Django conquers world!", "pub_date": "2006-06-16T15:00:00"}}, {"pk": 5, "model": "fixtures.article", "fields": {"headline": "XML identified as leading cause of cancer", "pub_date": "2006-06-16T16: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": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Artist formerly known as \\"Prince\\""}}, {"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"]]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', natural_foreign_keys=True) + self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker on TV is great!", "pub_date": "2006-06-16T11:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}, {"pk": 4, "model": "fixtures.article", "fields": {"headline": "Django conquers world!", "pub_date": "2006-06-16T15:00:00"}}, {"pk": 5, "model": "fixtures.article", "fields": {"headline": "XML identified as leading cause of cancer", "pub_date": "2006-06-16T16: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": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Artist formerly known as \\"Prince\\""}}, {"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"]]}}]', natural_foreign_keys=True) # Dump the current contents of the database as an XML fixture self._dumpdata_assert(['fixtures'], """ -News StoriesLatest news storiesPoker on TV is great!2006-06-16T11:00:00Copyright is fine the way it is2006-06-16T14:00:00Django conquers world!2006-06-16T15:00:00XML identified as leading cause of cancer2006-06-16T16:00:00copyrightfixturesarticle3legalfixturesarticle3djangofixturesarticle4world dominationfixturesarticle4Django ReinhardtStephane GrappelliArtist formerly known as "Prince"Django Reinhardtadd_userauthuserchange_userauthuserdelete_userauthuserStephane Grappelliadd_userauthuserdelete_userauthuserArtist formerly known as "Prince"change_userauthuserMusic for all agesArtist formerly known as "Prince"Django ReinhardtAchieving self-awareness of Python programs""", format='xml', natural_foreign_keys=True) +News StoriesLatest news storiesPoker on TV is great!2006-06-16T11:00:00Copyright is fine the way it is2006-06-16T14:00:00Django conquers world!2006-06-16T15:00:00XML identified as leading cause of cancer2006-06-16T16:00:00copyrightfixturesarticle3legalfixturesarticle3djangofixturesarticle4world dominationfixturesarticle4Django ReinhardtStephane GrappelliArtist formerly known as "Prince"Django Reinhardtadd_userauthuserchange_userauthuserdelete_userauthuserStephane Grappelliadd_userauthuserdelete_userauthuserArtist formerly known as "Prince"change_userauthuserMusic for all agesArtist formerly known as "Prince"Django Reinhardt""", format='xml', natural_foreign_keys=True) def test_dumpdata_with_excludes(self): # Load fixture1 which has a site, two articles, and a category @@ -283,7 +271,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): def test_dumpdata_with_file_output(self): management.call_command('loaddata', 'fixture1.json', verbosity=0) - self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', + self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]', filename='dumpdata.json') def test_compress_format_loading(self): @@ -377,11 +365,11 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): ], ordered=False) # Dump the current contents of the database as a JSON fixture - self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13: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": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Prince"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', natural_foreign_keys=True) + self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13: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": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Prince"}}]', natural_foreign_keys=True) # Dump the current contents of the database as an XML fixture self._dumpdata_assert(['fixtures'], """ -News StoriesLatest news storiesPoker has no place on ESPN2006-06-16T12:00:00Time to reform copyright2006-06-16T13:00:00copyrightfixturesarticle3lawfixturesarticle3Django ReinhardtStephane GrappelliPrinceAchieving self-awareness of Python programs""", format='xml', natural_foreign_keys=True) +News StoriesLatest news storiesPoker has no place on ESPN2006-06-16T12:00:00Time to reform copyright2006-06-16T13:00:00copyrightfixturesarticle3lawfixturesarticle3Django ReinhardtStephane GrappelliPrince""", format='xml', natural_foreign_keys=True) class NonExistentFixtureTests(TestCase): @@ -407,11 +395,6 @@ class NonExistentFixtureTests(TestCase): 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): @@ -444,7 +427,7 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase): ]) # Dump the current contents of the database as a JSON fixture - self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') + self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Load fixture 4 (compressed), using format discovery management.call_command('loaddata', 'fixture4', verbosity=0) diff --git a/tests/fixtures_migration/__init__.py b/tests/fixtures_migration/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/fixtures_migration/fixtures/initial_data.json b/tests/fixtures_migration/fixtures/initial_data.json deleted file mode 100644 index 2e979fc842..0000000000 --- a/tests/fixtures_migration/fixtures/initial_data.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "pk": "10", - "model": "fixtures_migration.book", - "fields": { - "name": "Achieving self-awareness of Python programs" - } - } -] diff --git a/tests/fixtures_migration/migrations/0001_initial.py b/tests/fixtures_migration/migrations/0001_initial.py deleted file mode 100644 index f1db74a874..0000000000 --- a/tests/fixtures_migration/migrations/0001_initial.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - operations = [ - migrations.CreateModel( - "Book", - [ - ("name", models.CharField(max_length=100)), - ], - ), - ] diff --git a/tests/fixtures_migration/migrations/__init__.py b/tests/fixtures_migration/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/fixtures_migration/models.py b/tests/fixtures_migration/models.py deleted file mode 100644 index 3c1d9b63fd..0000000000 --- a/tests/fixtures_migration/models.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.db import models - - -class Book(models.Model): - name = models.CharField(max_length=100) diff --git a/tests/fixtures_migration/tests.py b/tests/fixtures_migration/tests.py deleted file mode 100644 index 1dcc443c85..0000000000 --- a/tests/fixtures_migration/tests.py +++ /dev/null @@ -1,31 +0,0 @@ -from django.test import TransactionTestCase -from django.core import management - -from .models import Book - - -class TestNoInitialDataLoading(TransactionTestCase): - """ - Apps with migrations should ignore initial data. This test can be removed - in Django 1.9 when migrations become required and initial data is no longer - supported. - """ - available_apps = ['fixtures_migration'] - - def test_migrate(self): - self.assertQuerysetEqual(Book.objects.all(), []) - management.call_command( - 'migrate', - verbosity=0, - ) - self.assertQuerysetEqual(Book.objects.all(), []) - - def test_flush(self): - self.assertQuerysetEqual(Book.objects.all(), []) - management.call_command( - 'flush', - verbosity=0, - interactive=False, - load_initial_data=False - ) - self.assertQuerysetEqual(Book.objects.all(), []) diff --git a/tests/fixtures_model_package/fixtures/initial_data.json b/tests/fixtures_model_package/fixtures/initial_data.json deleted file mode 100644 index 1d1cf15e03..0000000000 --- a/tests/fixtures_model_package/fixtures/initial_data.json +++ /dev/null @@ -1,9 +0,0 @@ -[ - { - "pk": "10", - "model": "fixtures_model_package.book", - "fields": { - "name": "Achieving self-awareness of Python programs" - } - } -] diff --git a/tests/fixtures_model_package/tests.py b/tests/fixtures_model_package/tests.py index fd48dc1f9c..431bf8fa47 100644 --- a/tests/fixtures_model_package/tests.py +++ b/tests/fixtures_model_package/tests.py @@ -3,11 +3,10 @@ from __future__ import unicode_literals import warnings from django.core import management -from django.db import transaction -from django.test import TestCase, TransactionTestCase +from django.test import TestCase from django.utils.six import StringIO -from .models import Article, Book +from .models import Article class SampleTestCase(TestCase): @@ -26,51 +25,7 @@ class SampleTestCase(TestCase): ) -class TestNoInitialDataLoading(TransactionTestCase): - - available_apps = ['fixtures_model_package'] - - def test_migrate(self): - with transaction.atomic(): - Book.objects.all().delete() - - management.call_command( - 'migrate', - verbosity=0, - load_initial_data=False - ) - self.assertQuerysetEqual(Book.objects.all(), []) - - def test_flush(self): - # Test presence of fixture (flush called by TransactionTestCase) - self.assertQuerysetEqual( - Book.objects.all(), [ - 'Achieving self-awareness of Python programs' - ], - lambda a: a.name - ) - - with transaction.atomic(): - management.call_command( - 'flush', - verbosity=0, - interactive=False, - load_initial_data=False - ) - self.assertQuerysetEqual(Book.objects.all(), []) - - class FixtureTestCase(TestCase): - def test_initial_data(self): - "Fixtures can load initial data into models defined in packages" - # migrate introduces 1 initial data object from initial_data.json - # this behavior is deprecated and will be removed in Django 1.9 - self.assertQuerysetEqual( - Book.objects.all(), [ - 'Achieving self-awareness of Python programs' - ], - lambda a: a.name - ) def test_loaddata(self): "Fixtures can load data into models defined in packages" diff --git a/tests/migrate_signals/tests.py b/tests/migrate_signals/tests.py index cacf39888c..adb721e074 100644 --- a/tests/migrate_signals/tests.py +++ b/tests/migrate_signals/tests.py @@ -66,7 +66,7 @@ class MigrateSignalTests(TestCase): signals.pre_migrate.connect(r, sender=APP_CONFIG) management.call_command('migrate', database=MIGRATE_DATABASE, verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE, - load_initial_data=False, stdout=six.StringIO()) + stdout=six.StringIO()) args = r.call_args self.assertEqual(r.call_counter, 1) @@ -86,7 +86,7 @@ class MigrateSignalTests(TestCase): stdout = six.StringIO() management.call_command('migrate', database=MIGRATE_DATABASE, verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE, - load_initial_data=False, stdout=stdout) + stdout=stdout) args = r.call_args self.assertEqual(r.call_counter, 1) self.assertEqual(set(args), set(PRE_MIGRATE_ARGS)) diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 44a01f8fde..e0fc431dd0 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -1778,8 +1778,7 @@ class MigrateTestCase(TestCase): self.assertGreater(count, 0) cts.delete() - management.call_command('migrate', verbosity=0, interactive=False, - load_initial_data=False, database='other') + management.call_command('migrate', verbosity=0, interactive=False, database='other') self.assertEqual(cts.count(), count) def test_migrate_to_other_database_with_router(self): @@ -1788,8 +1787,7 @@ class MigrateTestCase(TestCase): cts.delete() with override_settings(DATABASE_ROUTERS=[SyncOnlyDefaultDatabaseRouter()]): - management.call_command('migrate', verbosity=0, interactive=False, - load_initial_data=False, database='other') + management.call_command('migrate', verbosity=0, interactive=False, database='other') self.assertEqual(cts.count(), 0) diff --git a/tests/runtests.py b/tests/runtests.py index f3ec6407c9..9be4460307 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -239,11 +239,6 @@ def django_tests(verbosity, interactive, failfast, keepdb, reverse, test_labels, "use '/sql' instead.", RemovedInDjango19Warning ) - warnings.filterwarnings( - 'ignore', - 'initial_data fixtures are deprecated. Use data migrations instead.', - RemovedInDjango19Warning - ) failures = test_runner.run_tests( test_labels or get_installed(), extra_tests=extra_tests) diff --git a/tests/swappable_models/tests.py b/tests/swappable_models/tests.py index de2105d2ec..246d456f20 100644 --- a/tests/swappable_models/tests.py +++ b/tests/swappable_models/tests.py @@ -28,7 +28,7 @@ class SwappableModelTests(TestCase): # Re-run migrate. This will re-build the permissions and content types. new_io = StringIO() - management.call_command('migrate', load_initial_data=False, interactive=False, stdout=new_io) + management.call_command('migrate', interactive=False, stdout=new_io) # Check that content types and permissions exist for the swapped model, # but not for the swappable model.