mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #6961 - loaddata fails if models is a package instead of a module
Thanks to pmd for report, zhaoz, mmalone and justinlilly for patch git-svn-id: http://code.djangoproject.com/svn/django/trunk@11914 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f1ea26dd99
commit
01acd99947
7 changed files with 124 additions and 1 deletions
2
tests/modeltests/fixtures_model_package/__init__.py
Normal file
2
tests/modeltests/fixtures_model_package/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"pk": "2",
|
||||
"model": "fixtures_model_package.article",
|
||||
"fields": {
|
||||
"headline": "Poker has no place on ESPN",
|
||||
"pub_date": "2006-06-16 12:00:00"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": "3",
|
||||
"model": "fixtures_model_package.article",
|
||||
"fields": {
|
||||
"headline": "Time to reform copyright",
|
||||
"pub_date": "2006-06-16 13:00:00"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"pk": "3",
|
||||
"model": "fixtures_model_package.article",
|
||||
"fields": {
|
||||
"headline": "Copyright is fine the way it is",
|
||||
"pub_date": "2006-06-16 14:00:00"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": "4",
|
||||
"model": "fixtures_model_package.article",
|
||||
"fields": {
|
||||
"headline": "Django conquers world!",
|
||||
"pub_date": "2006-06-16 15:00:00"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<django-objects version="1.0">
|
||||
<object pk="2" model="fixtures_model_package.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="5" model="fixtures_model_package.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>
|
||||
</django-objects>
|
|
@ -0,0 +1,10 @@
|
|||
[
|
||||
{
|
||||
"pk": "1",
|
||||
"model": "fixtures_model_package.article",
|
||||
"fields": {
|
||||
"headline": "Python program becomes self aware",
|
||||
"pub_date": "2006-06-16 11:00:00"
|
||||
}
|
||||
}
|
||||
]
|
54
tests/modeltests/fixtures_model_package/models/__init__.py
Normal file
54
tests/modeltests/fixtures_model_package/models/__init__.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
class Article(models.Model):
|
||||
headline = models.CharField(max_length=100, default='Default headline')
|
||||
pub_date = models.DateTimeField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.headline
|
||||
|
||||
class Meta:
|
||||
app_label = 'fixtures_model_package'
|
||||
ordering = ('-pub_date', 'headline')
|
||||
|
||||
__test__ = {'API_TESTS': """
|
||||
>>> from django.core import management
|
||||
>>> from django.db.models import get_app
|
||||
|
||||
# Reset the database representation of this app.
|
||||
# This will return the database to a clean initial state.
|
||||
>>> 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.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.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 a fixture that doesn't exist
|
||||
>>> management.call_command('loaddata', 'unknown.json', verbosity=0)
|
||||
|
||||
# object list is unaffected
|
||||
>>> 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>]
|
||||
"""}
|
||||
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
class SampleTestCase(TestCase):
|
||||
fixtures = ['fixture1.json', 'fixture2.json']
|
||||
|
||||
def testClassFixtures(self):
|
||||
"Check that test case has installed 4 fixture objects"
|
||||
self.assertEqual(Article.objects.count(), 4)
|
||||
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>]")
|
Loading…
Add table
Add a link
Reference in a new issue