Commits

Al...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed fefb438

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

  • Participants
  • Parent commits 447a8df
  • Branches soc2010/query-refactor

Comments (0)

Files changed (2)

File tests/regressiontests/mongodb/models.py

     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)

File tests/regressiontests/mongodb/tests.py

 from django.db.models import Count
 from django.test import TestCase
 
-from models import Artist
+from models import Artist, Group
 
 
 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)