Example #1
0
 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)
Example #2
0
 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)
Example #4
0
 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')
Example #5
0
    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)
Example #6
0
 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)
Example #7
0
 def mutate(root, info, id):
     person = PersonModel(id=id)
     person.delete()
     return RemovePerson(person=person)
Example #8
0
 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)
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
 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)
Example #13
0
 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)
Example #14
0
 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)
Example #15
0
 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)