1. Alex Burgel
  2. djangoappengine

Commits

Alex Burgel  committed 7d380ba

test case for foreignkeys

  • Participants
  • Parent commits 810ca31
  • Branches default

Comments (0)

Files changed (1)

File tests/keys.py

View file
  • Ignore whitespace
 class AnotherChildModel(models.Model):
     key = GAEKeyField(primary_key=True, parent_key_name='also_parent_key')
 
+class ForeignKeyModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    relation = models.ForeignKey(ParentModel)
+
 class KeysTest(TestCase):
+    def testGAEKeySave(self):
+        model = ParentModel()
+        model.save()
+        
+        self.assertIsNotNone(model.pk)
+
     def testUnsavedParent(self):
         parent = ParentModel()
 
         results = list(ChildModel.objects.filter(pk=parent2.pk.as_ancestor()))
         self.assertEquals(1, len(results))
         self.assertEquals(results[0].pk, child2.pk)
+
+    def testForeignKeyWithGAEKey(self):
+        parent = ParentModel()
+        parent.save()
+        
+        fkm = ForeignKeyModel()
+        fkm.relation = parent
+        fkm.save()
+        
+        results = list(ForeignKeyModel.objects.filter(relation=parent))
+        self.assertEquals(1, len(results))
+        self.assertEquals(results[0].pk, fkm.pk)
+