def setUp(self): self.request = testing.DummyRequest() self.request.user = None self.config = testing.setUp(request=self.request) self.config.include('pyconca') engine = create_engine('sqlite://') DBSession.configure(bind=engine) from pyconca.models import ( Base, User, UserGroup, Group, ) Base.metadata.create_all(engine) with transaction.manager: self._admin_id = 1 self._speaker_id = 2 for model in ( User(id=self._admin_id, username='******', password='', first_name='Admin', last_name='Istrator', email='*****@*****.**'), User(id=self._speaker_id, username='******', password='', first_name='Spe', last_name='Aker', email='*****@*****.**'), Group(id=1, name='admin'), UserGroup(user_id=self._admin_id, group_id=1), ): DBSession.add(model)
def setUp(self): self.request = testing.DummyRequest() self.request.user = None self.config = testing.setUp(request=self.request) self.config.include('pyconca') engine = create_engine('sqlite://') DBSession.configure(bind=engine) from pyconca.models import ( Base, User, UserGroup, Group, Talk ) Base.metadata.create_all(engine) with transaction.manager: self._admin_id = 1 self._speaker_id = 2 for model in ( User(id=self._admin_id, username='******', password='', first_name='Admin', last_name='Istrator', email='*****@*****.**'), User(id=self._speaker_id, username='******', password='', first_name='Spe', last_name='Aker', email='*****@*****.**'), Group(id=1, name='admin'), UserGroup(user_id=self._admin_id, group_id=1), Talk(id=self._admin_id, owner_id=self._admin_id, title='Admin Title', type='talk', level='experienced', abstract='Abstract', outline='Outline', reviewer_notes='Reviewed?'), Talk(id=self._speaker_id, owner_id=self._speaker_id, title='Speaker Title', type='tutorial', level='novice', abstract='Strabact', outline='Silhouette', reviewer_notes='Viewed again.'), ): DBSession.add(model)
def _loggedInAdmin(self): from pyconca.models import User # This plus the fixtures gives us info['is_admin'] == True self.request.user = DBSession.query(User).get(self._admin_id) # This gives us info['logged_in'] == 'pyramid_admin' self.config.testing_securitypolicy(userid='pyramid_admin', permissive=True)
def setUp(self): self.request = testing.DummyRequest() self.request.user = None self.config = testing.setUp(request=self.request) self.config.include('pyconca') engine = create_engine('sqlite://') DBSession.configure(bind=engine) from pyconca.models import (Base, User, UserGroup, Group, Talk) Base.metadata.create_all(engine) with transaction.manager: self._admin_id = 1 self._speaker_id = 2 for model in ( User(id=self._admin_id, username='******', password='', first_name='Admin', last_name='Istrator', email='*****@*****.**'), User(id=self._speaker_id, username='******', password='', first_name='Spe', last_name='Aker', email='*****@*****.**'), Group(id=1, name='admin'), UserGroup(user_id=self._admin_id, group_id=1), Talk(id=self._admin_id, owner_id=self._admin_id, title='Admin Title', type='talk', level='experienced', abstract='Abstract', outline='Outline', reviewer_notes='Reviewed?'), Talk(id=self._speaker_id, owner_id=self._speaker_id, title='Speaker Title', type='tutorial', level='novice', abstract='Strabact', outline='Silhouette', reviewer_notes='Viewed again.'), ): DBSession.add(model)
def _loggedInAdmin(self): from pyconca.models import User # This plus the fixtures gives us info['is_admin'] == True self.request.user = DBSession.query(User).get(self._admin_id) # This gives us info['logged_in'] == 'pyramid_admin' self.config.testing_securitypolicy( userid='pyramid_admin', permissive=True)
def schedule(request): from sqlalchemy.orm import joinedload from pyconca.models import DBSession, ScheduleSlot response = _build_response(request) response.update({ 'slots': dict((slot.code, slot) for slot in DBSession.query(ScheduleSlot).options( joinedload('talk'), joinedload('talk.owner'), )), }) return response
def schedule(request): from sqlalchemy.orm import joinedload from pyconca.models import DBSession, ScheduleSlot response = _build_response(request) response.update({ 'slots': dict( (slot.code, slot) for slot in DBSession.query(ScheduleSlot).options( joinedload('talk'), joinedload('talk.owner'), ) ), }) return response
def tearDown(self): DBSession.remove() testing.tearDown()
def _query(self): return DBSession.query(self.model)
def _query(self): query = DBSession.query(self.model) default_order_by = self._default_order_by() if default_order_by: query = query.order_by(*default_order_by) return query
def save(self, instance): DBSession.add(instance) DBSession.flush()
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot ignore_errors = False if "--ignore-errors" in argv: argv.remove("--ignore-errors") ignore_errors = True if len(argv) != 2: usage(argv) return 1 if "--dry-run" in argv: print "\n".join(map(str, parse_schedule(schedule))) return 0 config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) dumpdb = os.path.join(os.path.dirname(__file__), "../../prod_mysqldump") if os.path.exists(dumpdb): print "Running %r..." % (dumpdb, ) res = os.system(dumpdb) if res: return res with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") s.__dict__.update(vals) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: if ignore_errors: continue raise Exception("invalid talk: %r" % (talk, )) actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name) assert actual_talk_owner.lower() == talk.owner_name.lower(), \ "bad data? owners don't match: %r != %r" %( actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by( talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def _loggedInStaff(self): from pyconca.models import User self.request.user = DBSession.query(User).get(self._speaker_id) self.config.testing_securitypolicy( userid='pyramid_speaker', permissive=True)
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot ignore_errors = False if "--ignore-errors" in argv: argv.remove("--ignore-errors") ignore_errors = True if len(argv) != 2: usage(argv) return 1 if "--dry-run" in argv: print "\n".join(map(str, parse_schedule(schedule))) return 0 config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) dumpdb = os.path.join(os.path.dirname(__file__), "../../prod_mysqldump") if os.path.exists(dumpdb): print "Running %r..." %(dumpdb, ) res = os.system(dumpdb) if res: return res with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") for (k, v) in vals.items(): setattr(s, k, v) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: if ignore_errors: continue raise Exception("invalid talk: %r" %(talk, )) actual_talk_owner = "%s %s" %(t.owner.first_name, t.owner.last_name) assert actual_talk_owner.lower() == talk.owner_name.lower(), \ "bad data? owners don't match: %r != %r" %( actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by(talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def _loggedInStaff(self): from pyconca.models import User self.request.user = DBSession.query(User).get(self._speaker_id) self.config.testing_securitypolicy(userid='pyramid_speaker', permissive=True)
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot if len(argv) != 2: usage(argv) sys.exit(1) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, "sqlalchemy.") DBSession.configure(bind=engine) with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") s.__dict__.update(vals) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: raise Exception("invalid talk: %r" % (talk,)) actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name) assert ( actual_talk_owner.lower() == talk.owner_name.lower() ), "bad data? owners don't match: %r != %r" % (actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by(talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def main(argv=sys.argv): from pyconca.models import DBSession, ScheduleSlot, Talk, TalkScheduleSlot if len(argv) != 2: usage(argv) sys.exit(1) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) with transaction.manager: for slot in parse_schedule(schedule): s = DBSession.query(ScheduleSlot).filter_by(code=slot.code).first() if s is None: s = ScheduleSlot() vals = slot._asdict() talk = vals.pop("talk") s.__dict__.update(vals) DBSession.add(s) if talk: t = DBSession.query(Talk).filter_by(id=talk.id).first() if not t: raise Exception("invalid talk: %r" % (talk, )) actual_talk_owner = "%s %s" % (t.owner.first_name, t.owner.last_name) assert actual_talk_owner.lower() == talk.owner_name.lower(), \ "bad data? owners don't match: %r != %r" %( actual_talk_owner, talk.owner_name) ts = DBSession.query(TalkScheduleSlot).filter_by( talk_id=t.id).first() if not ts: ts = TalkScheduleSlot() ts.talk_id = t.id ts.schedule_slot = s DBSession.add(ts) DBSession.flush()
def delete(self, instance): DBSession.delete(instance)