def add(self, **kw): statistic = model.Statistic() statistic.km = kw['km'] statistic.lng = kw['lng'] statistic.lat = kw['lat'] statistic.device_id = kw['device_id'] DBSession.add(statistic)
def add(self, **kw): statistic = model.Statistic() statistic.km = kw["km"] statistic.lng = kw["lng"] statistic.lat = kw["lat"] statistic.device_id = kw["device_id"] DBSession.add(statistic)
def setUp(self): """Prepare model test fixture.""" try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def by_email_address(cls, email): """Return the user object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()
def me(self, device_id): query = DBSession.query(func.sum(model.Statistic.km)).filter(model.Statistic.device_id == device_id) distance = query.scalar() return str(round(distance * 1000))
def test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.iteritems(): assert_equals(getattr(obj, key), value)
def tearDown(self): """Finish model test fixture.""" DBSession.rollback()
def me(self, device_id): query = DBSession.query(func.sum( model.Statistic.km)).filter(model.Statistic.device_id == device_id) distance = query.scalar() return str(round(distance * 1000))