def test_bulk_save(self): #make sure that we replace objects when they are updated o1 = PersonModel(_id=1, name="Alfredo", age=17) o2 = PersonModel(_id=2, name="Colette", age=16) PersonModel.bulk_save([o1, o2]) people = self._read_log() self.failUnlessEqual(17, people[1].age) self.failUnlessEqual("Colette", people[2].name)
def test_bulk_save(self): #make sure that we replace objects when they are updated o1 = PersonModel(_id=1, name="Alfredo", age=17) o2 = PersonModel(_id=2, name="Colette", age=16) PersonModel.bulk_save([o1,o2]) people = self._read_log() self.failUnlessEqual(17, people[1].age) self.failUnlessEqual("Colette", people[2].name)
def mutate(self, info, input): data = utils.input_to_dictionary(input) person = PersonModel(**data) db_session.add(person) db_session.commit() return CreatePerson(person=person)
def test_fun_model(self): fun = FunModel() fun.part = PersonModel() self.assertRaises(TypeError, setattr, fun, 'enum', 'green') self.assertRaises(ValueError, setattr, fun, 'real', 'i') self.assertRaises(TypeError, setattr, fun, 'dic', [2,3]) self.assertRaises(TypeError, setattr, fun, 'created', []) self.assertRaises(TypeError, setattr, fun, 'names', [7,8]) self.assertRaises(TypeError, setattr, fun, 'names', 13) self.assertEqual(fun.enum, None) self.assertEqual(fun.part.age, 7) fun.part.age=100 self.assertEqual(fun.part.age, 100) fun.part = {'n':'jeff'} self.assertEqual(fun.part.age, 7) self.assertEqual(fun.part.name, 'jeff')
def test_get_all(self): for name in ['pumba','zazu','rafiki']: m = PersonModel(name=name, age=(10+len(name))) m.save() people = sorted(PersonModel.get_all(),key=attrgetter('age')) self.failUnlessEqual( people[0].name, 'zazu') self.failUnlessEqual( people[0].age, 14) self.failUnlessEqual( people[1].name, 'pumba') self.failUnlessEqual( people[1].age, 15) self.failUnlessEqual( people[2].name, 'rafiki') self.failUnlessEqual( people[2].age, 16) people = list(PersonModel.get_all(limit=2)) self.failUnlessEqual( len(people), 2)
def test_fun_model(self): dic = {"one":2, 'three':"four", 'five':["six",7]} names = ['Shenzi', 'Banzai', 'ed'] now = datetime.datetime.utcnow() fun = FunModel( _id="fun", enum="red", real=3.14, dic=dic, names=names, ) fun.part=PersonModel(name="scar", age=32) fun.save() fun = FunModel.get_id("fun") self.failUnlessEqual( fun.enum, 'red') self.failUnlessEqual( fun.real, 3.14) self.failUnlessEqual( fun.dic, dic) dt = abs(fun.created-now) self.failUnless( dt.days==0 and dt.seconds==0 ) self.failUnlessEqual( fun.names, names) self.failUnlessEqual( fun.part.name, "scar") self.failUnlessEqual( fun.part.age, 32)
def mutate(root, info, id): person = PersonModel(id=id) person.delete() return RemovePerson(person=person)
def mutate(root, info, first, last=None, id=None): person = PersonModel(id=id, first_name=first, last_name=last) person.save() return UpdatePerson(person=person)
def test_load_json(self): res = PersonModel.get_all() self.failUnlessEqual(len(res),2) darby = PersonModel.find(PersonModel.age==3)[0] self.failUnlessEqual(darby.name,"Darby") self.failUnlessEqual(darby.age,3)
def test_other_method(self): o = PersonModel(_id=3, name="Skinner", age=50) o.save() g = PersonModel.get_id(3) self.failUnlessEqual(50, g.age)
def test_simple_save(self): o1 = PersonModel(_id=0, name="Remy", age=2) o1.save() people = self._read_log() self.failUnlessEqual(2, people[0].age)
def test_load_json(self): res = PersonModel.get_all() self.failUnlessEqual(len(res), 2) darby = PersonModel.find(PersonModel.age == 3)[0] self.failUnlessEqual(darby.name, "Darby") self.failUnlessEqual(darby.age, 3)
def _read_log(self): people = (PersonModel(from_dict=json.loads(line)) for line in open(self.path)) return dict((p._id, p) for p in people)
def mutate(self, info, **kwargs): original_kwargs = get_mapped_kwargs(personas_mapping, kwargs) persona = PersonModel(**original_kwargs) persona.save() return CreatePersona(persona=persona)