Skip to content

Commit 9f53dbb

Browse files
committed
[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
1 parent f522555 commit 9f53dbb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tests/regressiontests/mongodb/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ class Artist(models.Model):
66
name = models.CharField(max_length=255)
77
good = models.BooleanField()
88

9+
current_group = models.ForeignKey("Group", null=True)
10+
911
def __unicode__(self):
1012
return self.name
13+
14+
15+
class Group(models.Model):
16+
id = models.NativeAutoField(primary_key=True)
17+
name = models.CharField(max_length=255)

tests/regressiontests/mongodb/tests.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.db.models import Count
22
from django.test import TestCase
33

4-
from models import Artist
4+
from models import Artist, Group
55

66

77
class MongoTestCase(TestCase):
@@ -44,3 +44,16 @@ def test_count(self):
4444
self.assertEqual(Artist.objects.filter(good=False).count(), 1)
4545

4646
self.assertEqual(Artist.objects.aggregate(c=Count("pk")), {"c": 6})
47+
48+
def test_foreignkey(self):
49+
e = Group.objects.create(name="The E Street Band")
50+
b = Artist.objects.create(name="Clarence Clemons", good=True,
51+
current_group=e)
52+
53+
self.assertEqual(b.current_group, e)
54+
self.assertEqual(b.current_group_id, e.pk)
55+
56+
b = Artist.objects.get(name="Clarence Clemons")
57+
self.assertEqual(b.current_group_id, e.pk)
58+
self.assertFalse(hasattr(b, "_current_group_cache"))
59+
self.assertEqual(b.current_group, e)

0 commit comments

Comments
 (0)