mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Major refactoring of django.core.management -- it's now a package rather than a 1730-line single module. All django-admin/manage.py commands are now stored in separate modules. This is backwards-incompatible for people who used django.core.management functions directly
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5898 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -26,54 +26,54 @@ __test__ = {'API_TESTS': """
|
||||
|
||||
# Reset the database representation of this app.
|
||||
# This will return the database to a clean initial state.
|
||||
>>> management.flush(verbosity=0, interactive=False)
|
||||
>>> management.call_command('flush', verbosity=0, interactive=False)
|
||||
|
||||
# Syncdb introduces 1 initial data object from initial_data.json.
|
||||
>>> Article.objects.all()
|
||||
[<Article: Python program becomes self aware>]
|
||||
|
||||
# Load fixture 1. Single JSON file, with two objects.
|
||||
>>> management.load_data(['fixture1.json'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'fixture1.json', verbosity=0)
|
||||
>>> Article.objects.all()
|
||||
[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
|
||||
|
||||
# Load fixture 2. JSON file imported by default. Overwrites some existing objects
|
||||
>>> management.load_data(['fixture2.json'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'fixture2.json', verbosity=0)
|
||||
>>> 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>]
|
||||
|
||||
# Load fixture 3, XML format.
|
||||
>>> management.load_data(['fixture3.xml'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'fixture3.xml', verbosity=0)
|
||||
>>> Article.objects.all()
|
||||
[<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>]
|
||||
|
||||
# Load a fixture that doesn't exist
|
||||
>>> management.load_data(['unknown.json'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'unknown.json', verbosity=0)
|
||||
|
||||
# object list is unaffected
|
||||
>>> Article.objects.all()
|
||||
[<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>]
|
||||
|
||||
# Reset the database representation of this app. This will delete all data.
|
||||
>>> management.flush(verbosity=0, interactive=False)
|
||||
>>> management.call_command('flush', verbosity=0, interactive=False)
|
||||
>>> Article.objects.all()
|
||||
[<Article: Python program becomes self aware>]
|
||||
|
||||
# Load fixture 1 again, using format discovery
|
||||
>>> management.load_data(['fixture1'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'fixture1', verbosity=0)
|
||||
>>> Article.objects.all()
|
||||
[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
|
||||
|
||||
# Try to load fixture 2 using format discovery; this will fail
|
||||
# because there are two fixture2's in the fixtures directory
|
||||
>>> management.load_data(['fixture2'], verbosity=0) # doctest: +ELLIPSIS
|
||||
>>> management.call_command('loaddata', 'fixture2', verbosity=0) # doctest: +ELLIPSIS
|
||||
Multiple fixtures named 'fixture2' in '...fixtures'. Aborting.
|
||||
|
||||
>>> Article.objects.all()
|
||||
[<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>]
|
||||
|
||||
# Dump the current contents of the database as a JSON fixture
|
||||
>>> print management.dump_data(['fixtures'], format='json')
|
||||
>>> print management.call_command('dumpdata', 'fixtures', format='json')
|
||||
[{"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"}}]
|
||||
"""}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ __test__ = {'API_TESTS':"""
|
||||
>>> from django.core import management
|
||||
|
||||
# Load a fixture that uses PK=1
|
||||
>>> management.load_data(['sequence'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'sequence', verbosity=0)
|
||||
|
||||
# Create a new animal. Without a sequence reset, this new object
|
||||
# will take a PK of 1 (on Postgres), and the save will fail.
|
||||
@@ -39,7 +39,7 @@ __test__ = {'API_TESTS':"""
|
||||
# doesn't affect parsing of None values.
|
||||
|
||||
# Load a pretty-printed XML fixture with Nulls.
|
||||
>>> management.load_data(['pretty.xml'], verbosity=0)
|
||||
>>> management.call_command('loaddata', 'pretty.xml', verbosity=0)
|
||||
>>> Stuff.objects.all()
|
||||
[<Stuff: None is owned by None>]
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ class SerializerTests(unittest.TestCase):
|
||||
|
||||
def serializerTest(format, self):
|
||||
# Clear the database first
|
||||
management.flush(verbosity=0, interactive=False)
|
||||
management.call_command('flush', verbosity=0, interactive=False)
|
||||
|
||||
# Create all the objects defined in the test data
|
||||
objects = []
|
||||
@@ -291,7 +291,7 @@ def serializerTest(format, self):
|
||||
serialized_data = serializers.serialize(format, objects, indent=2)
|
||||
|
||||
# Flush the database and recreate from the serialized data
|
||||
management.flush(verbosity=0, interactive=False)
|
||||
management.call_command('flush', verbosity=0, interactive=False)
|
||||
transaction.enter_transaction_management()
|
||||
transaction.managed(True)
|
||||
for obj in serializers.deserialize(format, serialized_data):
|
||||
@@ -306,7 +306,7 @@ def serializerTest(format, self):
|
||||
|
||||
def fieldsTest(format, self):
|
||||
# Clear the database first
|
||||
management.flush(verbosity=0, interactive=False)
|
||||
management.call_command('flush', verbosity=0, interactive=False)
|
||||
|
||||
obj = ComplexModel(field1='first',field2='second',field3='third')
|
||||
obj.save(raw=True)
|
||||
@@ -322,7 +322,7 @@ def fieldsTest(format, self):
|
||||
|
||||
def streamTest(format, self):
|
||||
# Clear the database first
|
||||
management.flush(verbosity=0, interactive=False)
|
||||
management.call_command('flush', verbosity=0, interactive=False)
|
||||
|
||||
obj = ComplexModel(field1='first',field2='second',field3='third')
|
||||
obj.save(raw=True)
|
||||
|
||||
@@ -51,7 +51,7 @@ class InvalidModelTestCase(unittest.TestCase):
|
||||
self.model_label = model_label
|
||||
|
||||
def runTest(self):
|
||||
from django.core import management
|
||||
from django.core.management.validation import get_validation_errors
|
||||
from django.db.models.loading import load_app
|
||||
from cStringIO import StringIO
|
||||
|
||||
@@ -61,7 +61,7 @@ class InvalidModelTestCase(unittest.TestCase):
|
||||
self.fail('Unable to load invalid model module')
|
||||
|
||||
s = StringIO()
|
||||
count = management.get_validation_errors(s, module)
|
||||
count = get_validation_errors(s, module)
|
||||
s.seek(0)
|
||||
error_log = s.read()
|
||||
actual = error_log.split('\n')
|
||||
|
||||
Reference in New Issue
Block a user