Skip to content
Browse files

[soc2010/query-refactor] Introduced tests to show that ForeignKeys wo…

…rk correctly.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13354 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent f522555 commit 9f53dbb24653214ad6eae7a37a71558f04294f2c @alex alex committed Jun 16, 2010
Showing with 21 additions and 1 deletion.
  1. +7 −0 tests/regressiontests/mongodb/models.py
  2. +14 −1 tests/regressiontests/mongodb/tests.py
View
7 tests/regressiontests/mongodb/models.py
@@ -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
15 tests/regressiontests/mongodb/tests.py
@@ -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 @@ def test_count(self):
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)

0 comments on commit 9f53dbb

Please sign in to comment.
Something went wrong with that request. Please try again.