1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

[soc2010/query-refactor] Introduced tests to show that ForeignKeys work correctly.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13354 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-06-16 20:48:45 +00:00
parent f522555392
commit 9f53dbb246
2 changed files with 21 additions and 1 deletions

View File

@ -6,5 +6,12 @@ class Artist(models.Model):
name = models.CharField(max_length=255)
good = models.BooleanField()
current_group = models.ForeignKey("Group", null=True)
def __unicode__(self):
return self.name
class Group(models.Model):
id = models.NativeAutoField(primary_key=True)
name = models.CharField(max_length=255)

View File

@ -1,7 +1,7 @@
from django.db.models import Count
from django.test import TestCase
from models import Artist
from models import Artist, Group
class MongoTestCase(TestCase):
@ -44,3 +44,16 @@ class MongoTestCase(TestCase):
self.assertEqual(Artist.objects.filter(good=False).count(), 1)
self.assertEqual(Artist.objects.aggregate(c=Count("pk")), {"c": 6})
def test_foreignkey(self):
e = Group.objects.create(name="The E Street Band")
b = Artist.objects.create(name="Clarence Clemons", good=True,
current_group=e)
self.assertEqual(b.current_group, e)
self.assertEqual(b.current_group_id, e.pk)
b = Artist.objects.get(name="Clarence Clemons")
self.assertEqual(b.current_group_id, e.pk)
self.assertFalse(hasattr(b, "_current_group_cache"))
self.assertEqual(b.current_group, e)