def test_search(self): a = A() a.b = [B(), B(), B()] for b in a.b: b.c = [C(field1=1.0, field2=1.2), C(field1=1.0, field2=1.2)] self.assertEquals([1.0] * 6, [x for x in search(a, 'b.c.field1')])
def test_run_suite_fron_inlined_classes(self): from pynch.db import DB class WorkingGardener(Model): _meta = {'database': DB(name='mygarden'), 'write_concern': 1} name = StringField(primary_key=True) instructor = ReferenceField('self') def __str__(self): return self.name class TeachingGarden(Model): _meta = {'database': DB(name='mygarden'), 'write_concern': 1} _id = PrimaryKey() acres = FloatField() gardeners = ListField(ReferenceField(WorkingGardener)) botanist = WorkingGardener(name='MrJones') person = WorkingGardener(name='me', instructor=botanist) garden = TeachingGarden(acres=0.25, gardeners=[person, botanist]) garden.save() g = TeachingGarden.pynch.get(_id=garden.pk) self.assertEquals(g.pk, garden.pk) names = list(name for name in search(g, 'gardeners.name')) self.assertEquals(names, ['me', 'MrJones']) self.assertEquals(g, garden) botanist2 = WorkingGardener(name='MrJones2') person2 = WorkingGardener(name='me2', instructor=botanist2) garden2 = TeachingGarden(acres=0.25, gardeners=[person2, botanist2]) garden2.save() to_raise = lambda: TeachingGarden.pynch.get(acres=0.25) self.assertRaises(QueryException, to_raise) garden2.delete() garden.delete()