summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-06-16 20:48:45 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-06-16 20:48:45 +0000
commit9f53dbb24653214ad6eae7a37a71558f04294f2c (patch)
tree0bb49613de774e3394c42b1b516bb00f73e4cbdf /tests
parentf522555392ed9e133431437dd815ba0e84bc2394 (diff)
[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
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/mongodb/models.py7
-rw-r--r--tests/regressiontests/mongodb/tests.py15
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/regressiontests/mongodb/models.py b/tests/regressiontests/mongodb/models.py
index e07e8f191c..b942d12e59 100644
--- a/tests/regressiontests/mongodb/models.py
+++ b/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)
diff --git a/tests/regressiontests/mongodb/tests.py b/tests/regressiontests/mongodb/tests.py
index bdc5a10727..bd9cd5981f 100644
--- a/tests/regressiontests/mongodb/tests.py
+++ b/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 @@ 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)