def testing_db(): from gateway.models import initialize_sql drop_and_create_db('testing') config = ConfigParser.ConfigParser() config.readfp(open('testing.ini')) db_string = config.get('app:gateway', 'db_string') initialize_sql(db_string) with pushd('migrations'): puts('--------------------') puts('Creating test tables') puts('Loading test data') sh('psql -d testing -f load_testing_env.sql')
def setUp(self): self.config = testing.setUp() import ConfigParser from gateway.models import DBSession from gateway.models import initialize_sql config = ConfigParser.ConfigParser() config.readfp(open('testing.ini')) db_string = config.get('app:gateway', 'db_string') initialize_sql(db_string) from gateway import main from webtest import TestApp app = main(None, **{'db_string': db_string, 'mako.directories': config.get('app:gateway', 'mako.directories')}) self.testapp = TestApp(app) self.session = DBSession()
def setUp(self): from pyramid.config import Configurator from gateway.models import initialize_sql self.session = initialize_sql('sqlite://') self.config = Configurator(autocommit=True) self.config.begin() from gateway.models import DBSession self.session = DBSession()
import transaction from shapely.geometry import Point from gateway.models import DBSession from gateway.models import Meter from gateway.models import SystemLog from gateway.models import initialize_sql import csv db_string = "postgresql://*****:*****@localhost:5432/gateway" initialize_sql(db_string) session = DBSession() if __name__ == '__main__': query = session.query(Meter) try: locations = csv.reader(open("locations.csv")) for line in locations: with transaction: point = Point(float(line[2]), float(line[1])) print point.wkt meter = query.filter_by(name= line[0]).first() meter.geometry = point.wkt session.flush() except Exception as error: print error
def main(global_config, **settings): """ This function returns a Pylons WSGI application. """ from paste.deploy.converters import asbool from pyramid.config import Configurator from gateway.models import initialize_sql from gateway.security import groupfinder db_string = settings.get('db_string') if db_string is None: raise ValueError("No 'db_string' value in application " "configuration.") initialize_sql(db_string, asbool(settings.get('db_echo'))) authn_policy = AuthTktAuthenticationPolicy( 'sosecret', callback=groupfinder) authz_policy = ACLAuthorizationPolicy() config = Configurator(settings=settings, autocommit=True, root_factory='gateway.security.RootFactory', authentication_policy=authn_policy, authorization_policy=authz_policy) config.begin() session_factory = session_factory_from_settings(settings) config.include(pyramid_handlers.includeme) config.set_session_factory(session_factory) config.add_static_view('static', 'gateway:static/') config.include('pyramid_mailer') config.add_view(view='gateway.handlers.forbidden_view', renderer='forbidden.mako', context=Forbidden) config.add_view(view='gateway.handlers.not_found', context=NotFound) config.add_route('add', '/add/{class}', renderer='add.mako', permission='admin', view='gateway.handlers.AddClass') config.add_route('delete', '/delete/jobs', permission='view', view='gateway.handlers.DeleteJobs') config.add_route('edit', '/edit/{class}/{id}', renderer='edit.mako', permission='admin', view='gateway.handlers.EditModel',) config.add_route('index', '/', renderer='index.mako', view='gateway.handlers.Index') config.add_handler('twilio', 'twilio/{action}', handler='gateway.handlers:TwilioHandler') config.add_handler('alerts', '/alerts/{action}', 'gateway.handlers:AlertHandler') config.add_handler('dashboard', '/dashboard', 'gateway.handlers:Dashboard', action='index') config.add_handler('main', '/:action', handler='gateway.handlers:Dashboard') config.add_handler('manage', '/manage/:action', handler='gateway.handlers:ManageHandler') config.add_handler('interfaces', '/interface/:action/:id', handler='gateway.handlers:InterfaceHandler'), config.add_handler('export-load', 'system/:action', handler='gateway.sys:ExportLoadHandler') config.add_handler('users', 'user/:action', handler='gateway.handlers:UserHandler') config.add_handler('meter', 'meter/:action/:id', handler='gateway.handlers:MeterHandler') config.add_handler('circuit', 'circuit/:action/:id', handler='gateway.handlers:CircuitHandler') config.add_handler('logs', 'logs/:action/:meter/', handler='gateway.handlers:LoggingHandler') config.add_handler('jobs', 'jobs/:action/:id/', handler='gateway.handlers:JobHandler') config.add_handler('sms', 'sms/:action', handler='gateway.handlers:SMSHandler') config.add_handler('message', 'message/:action/:id', handler='gateway.handlers:MessageHandler') config.add_handler('account', 'account/:action/:id', handler='gateway.handlers:AccountHandler') config.add_handler('token', 'token/:action/:id', handler='gateway.handlers:TokenHandler') config.add_subscriber('gateway.subscribers.add_renderer_globals', 'pyramid.events.BeforeRender') config.include('pyramid_formalchemy') config.include('fa.jquery') config.formalchemy_admin('admin', package='gateway', view='fa.jquery.pyramid.ModelView') config.end() return config.make_wsgi_app()
def main(global_config, **settings): """ This function returns a Pylons WSGI application. """ from paste.deploy.converters import asbool from pyramid.config import Configurator from gateway.models import initialize_sql from gateway.security import groupfinder db_string = settings.get('db_string') if db_string is None: raise ValueError("No 'db_string' value in application " "configuration.") initialize_sql(db_string, asbool(settings.get('db_echo'))) authn_policy = AuthTktAuthenticationPolicy( 'sosecret', callback=groupfinder) authz_policy = ACLAuthorizationPolicy() config = Configurator(settings=settings, autocommit=True, root_factory='gateway.models.RootFactory', authentication_policy=authn_policy, authorization_policy=authz_policy) config.begin() session_factory = session_factory_from_settings(settings) config.include(pyramid_handlers.includeme) config.set_session_factory(session_factory) config.add_static_view('static', 'gateway:static/') config.add_static_view('deform-static', 'deform:static') config.add_handler('dashboard', '/', 'gateway.handlers:Dashboard', action='index') config.add_handler('main', '/:action', handler='gateway.handlers:Dashboard') config.add_handler('manage', '/manage/:action', handler='gateway.handlers:ManageHandler') config.add_handler('interfaces', '/interface/:action/:id', handler='gateway.handlers:InterfaceHandler'), config.add_handler('export-load', 'sys/:action', handler='gateway.sys:ExportLoadHandler') config.add_handler('users', 'user/:action', handler='gateway.handlers:UserHandler') config.add_handler('meter', 'meter/:action/:slug', handler='gateway.handlers:MeterHandler') config.add_handler('circuit', 'circuit/:action/:id', handler='gateway.handlers:CircuitHandler') config.add_handler('logs', 'logs/:action/:meter/:circuit/', handler='gateway.handlers:LoggingHandler') config.add_handler('jobs', 'jobs/:action/:id/', handler='gateway.handlers:JobHandler') config.add_handler('sms', 'sms/:action', handler='gateway.handlers:SMSHandler') config.add_handler('message', 'message/:action/:id', handler='gateway.handlers:MessageHandler') config.add_handler('account', 'account/:action/:id', handler='gateway.handlers:AccountHandler') config.add_handler('token', 'token/:action/:id', handler='gateway.handlers:TokenHandler') config.add_subscriber('gateway.subscribers.add_renderer_globals', 'pyramid.events.BeforeRender') config.end() return config.make_wsgi_app()