Commits

Anonymous committed fefb438

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

Comments (0)

Files changed (2)

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)

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.