Permalink
Browse files

Changed the fixtures used to test the 'initial_data' feature so they …

…don't contain datetimes. Refs #17275.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17154 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 02bc523 commit fb7ab7730d8381bd7a7aa0b1266757f02a5d4990 @aaugustin aaugustin committed Nov 27, 2011
@@ -1,10 +1,9 @@
[
{
- "pk": "1",
- "model": "fixtures.article",
+ "pk": "10",
+ "model": "fixtures.book",
"fields": {
- "headline": "Python program becomes self aware",
- "pub_date": "2006-06-16 11:00:00"
+ "name": "Achieving self-awareness of Python programs"
}
}
-]
+]
@@ -92,8 +92,8 @@ class Book(models.Model):
authors = models.ManyToManyField(Person)
def __unicode__(self):
- return '%s by %s' % (self.name,
- ' and '.join(a.name for a in self.authors.all()))
+ authors = ' and '.join(a.name for a in self.authors.all())
+ return '%s by %s' % (self.name, authors) if authors else self.name
class Meta:
ordering = ('name',)
Oops, something went wrong.
@@ -1,10 +1,9 @@
[
{
- "pk": "1",
- "model": "fixtures_model_package.article",
+ "pk": "10",
+ "model": "fixtures_model_package.book",
"fields": {
- "headline": "Python program becomes self aware",
- "pub_date": "2006-06-16 11:00:00"
+ "name": "Achieving self-awareness of Python programs"
}
}
]
@@ -12,3 +12,8 @@ class Meta:
app_label = 'fixtures_model_package'
ordering = ('-pub_date', 'headline')
+class Book(models.Model):
+ name = models.CharField(max_length=100)
+
+ class Meta:
+ ordering = ('name',)
@@ -1,21 +1,20 @@
from django.core import management
from django.test import TestCase
-from .models import Article
+from .models import Article, Book
class SampleTestCase(TestCase):
fixtures = ['fixture1.json', 'fixture2.json']
def testClassFixtures(self):
"Test cases can load fixture objects into models defined in packages"
- self.assertEqual(Article.objects.count(), 4)
+ self.assertEqual(Article.objects.count(), 3)
self.assertQuerysetEqual(
Article.objects.all(),[
- "Django conquers world!",
- "Copyright is fine the way it is",
- "Poker has no place on ESPN",
- "Python program becomes self aware"
+ u"Django conquers world!",
+ u"Copyright is fine the way it is",
+ u"Poker has no place on ESPN",
],
lambda a: a.headline
)
@@ -24,12 +23,12 @@ def testClassFixtures(self):
class FixtureTestCase(TestCase):
def test_initial_data(self):
"Fixtures can load initial data into models defined in packages"
- #Syncdb introduces 1 initial data object from initial_data.json
+ # syncdb introduces 1 initial data object from initial_data.json
self.assertQuerysetEqual(
- Article.objects.all(), [
- "Python program becomes self aware"
+ Book.objects.all(), [
+ u'Achieving self-awareness of Python programs'
],
- lambda a: a.headline
+ lambda a: a.name
)
def test_loaddata(self):
@@ -38,9 +37,8 @@ def test_loaddata(self):
management.call_command("loaddata", "fixture1.json", verbosity=0, commit=False)
self.assertQuerysetEqual(
Article.objects.all(), [
- "Time to reform copyright",
- "Poker has no place on ESPN",
- "Python program becomes self aware",
+ u"Time to reform copyright",
+ u"Poker has no place on ESPN",
],
lambda a: a.headline,
)
@@ -50,10 +48,9 @@ def test_loaddata(self):
management.call_command("loaddata", "fixture2.json", verbosity=0, commit=False)
self.assertQuerysetEqual(
Article.objects.all(), [
- "Django conquers world!",
- "Copyright is fine the way it is",
- "Poker has no place on ESPN",
- "Python program becomes self aware",
+ u"Django conquers world!",
+ u"Copyright is fine the way it is",
+ u"Poker has no place on ESPN",
],
lambda a: a.headline,
)
@@ -62,10 +59,9 @@ def test_loaddata(self):
management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
self.assertQuerysetEqual(
Article.objects.all(), [
- "Django conquers world!",
- "Copyright is fine the way it is",
- "Poker has no place on ESPN",
- "Python program becomes self aware",
+ u"Django conquers world!",
+ u"Copyright is fine the way it is",
+ u"Poker has no place on ESPN",
],
lambda a: a.headline,
)

0 comments on commit fb7ab77

Please sign in to comment.