Exemplo n.º 1
0
    def test_embedded_model(self):
        em = EModel(title="1", pos=1)
        em2 = EModel(title="2", pos=2)
        t1 = TestFieldModel(title="p1", mlist=[em, em2], slist=[em, em2], mdict={"a": em, "b": em2}, mset=[em, em, em])
        t1.save()

        t = TestFieldModel.objects.get(id=t1.id)
        self.assertEqual(len(t.mlist), 2)
        self.assertEqual(t.mlist[0].test_func(), 1)
        self.assertEqual(t.mlist[1].test_func(), 2)
Exemplo n.º 2
0
 def test_lazy_model_instance_in_list(self):
     obj = TestFieldModel()
     related = DynamicModel(gen=42)
     obj.mlist.append(related)
     obj.save()
     self.assertNotEqual(related.id, None)
     obj = TestFieldModel.objects.get()
     self.assertEqual(obj.mlist[0]._wrapped, None)
     # query will be done NOW:
     self.assertEqual(obj.mlist[0].gen, 42)
     self.assertNotEqual(obj.mlist[0]._wrapped, None)
Exemplo n.º 3
0
 def test_fields(self):
     t1 = TestFieldModel(title="p1", 
                         mlist=["ab", "bc"],
                         slist=["bc", "ab"],
                         mdict = {'a':23, "b":True  },
                         mset=["a", 'b', "b"]
                         )
     t1.save()
     
     t = TestFieldModel.objects.get(id=t1.id)
     self.assertEqual(t.mlist, ["ab", "bc"])
     self.assertEqual(t.mlist_default, ["a", "b"])
     self.assertEqual(t.slist, ["ab", "bc"])
     self.assertEqual(t.slist_default, ["a", "b"])
     self.assertEqual(t.mdict, {'a':23, "b":True  })
     self.assertEqual(t.mdict_default, {"a": "a", 'b':1})
     self.assertEqual(sorted(t.mset), ["a", 'b'])
     self.assertEqual(sorted(t.mset_default), ["a", 'b'])
Exemplo n.º 4
0
    def test_fields(self):
        t1 = TestFieldModel(title="p1",
                            mlist=["ab", {'a':23, "b":True  }],
                            slist=["bc", "ab"],
                            mdict = {'a':23, "b":True  },
                            mset=["a", 'b', "b"]
                            )
        t1.save()

        t = TestFieldModel.objects.get(id=t1.id)
        self.assertEqual(t.mlist, ["ab", {'a':23, "b":True  }])
        self.assertEqual(t.mlist_default, ["a", "b"])
        self.assertEqual(t.slist, ["ab", "bc"])
        self.assertEqual(t.slist_default, ["a", "b"])
        self.assertEqual(t.mdict, {'a':23, "b":True  })
        self.assertEqual(t.mdict_default, {"a": "a", 'b':1})
        self.assertEqual(sorted(t.mset), ["a", 'b'])
        self.assertEqual(sorted(t.mset_default), ["a", 'b'])

        from django_mongodb_engine.query import A
        t2 = TestFieldModel.objects.get(mlist=A("a", 23))
        self.assertEqual(t1.pk, t2.pk)