def town_app(postgres_dsn, temporary_directory, town_password, smtpserver): config = setup() config.scan(more.webassets) config.scan(onegov.core) config.scan(onegov.town) config.commit() app = onegov.town.TownApp() app.namespace = 'test_' + uuid4().hex app.configure_application( dsn=postgres_dsn, filestorage='fs.osfs.OSFS', filestorage_options={ 'root_path': os.path.join(temporary_directory, 'file-storage'), 'create': True }, identity_secure=False, disable_memcached=True ) app.set_application_id(app.namespace + '/' + 'test') session = app.session() add_initial_content(session, 'Govikon') town = session.query(Town).one() town.meta['reply_to'] = '*****@*****.**' app.mail_host, app.mail_port = smtpserver.addr app.mail_sender = '*****@*****.**' app.mail_force_tls = False app.mail_username = None app.mail_password = None app.mail_use_directory = False app.smtpserver = smtpserver # usually we don't want to create the users directly, anywhere else you # *need* to go through the UserCollection. Here however, we can improve # the test speed by not hashing the password for every test. session.add(User( username='******', password_hash=town_password, role='admin' )) session.add(User( username='******', password_hash=town_password, role='editor' )) transaction.commit() yield app
def add(ctx, name): """ Adds a town with the given name to the database. """ session = ctx.obj["session"] if session.query(Town).first(): click.secho("The schema {} already contains a town".format(ctx.obj["schema"]), fg="red") sys.exit(1) add_initial_content(session, town_name=name) transaction.commit() click.secho("{} was added to the {} schema".format(name, ctx.obj["schema"]), fg="green")
def add(ctx, name): """ Adds a town with the given name to the database. """ session = ctx.obj['session'] if session.query(Town).first(): click.secho( "The schema {} already contains a town".format(ctx.obj['schema']), fg='red' ) sys.exit(1) add_initial_content( ctx.obj['libres_registry'], ctx.obj['session_manager'], town_name=name ) transaction.commit() click.secho( "{} was added to the {} schema".format(name, ctx.obj['schema']), fg='green' )
def new_town_app(postgres_dsn, filestorage, town_password, smtp, form_definitions, es_url=None): config = setup() scan_morepath_modules(onegov.town.TownApp, config) config.commit() app = onegov.town.TownApp() app.namespace = 'test_' + uuid4().hex app.configure_application( dsn=postgres_dsn, filestorage='fs.osfs.OSFS', filestorage_options={ 'root_path': filestorage, 'create': True }, identity_secure=False, disable_memcached=True, enable_elasticsearch=es_url and True or False, elasticsearch_hosts=[es_url] ) app.set_application_id(app.namespace + '/' + 'test') add_initial_content( app.libres_registry, app.session_manager, 'Govikon', form_definitions ) # cronjobs leave lingering sessions open, in real life this is not a # problem, but in testing it leads to connection pool exhaustion app.registry.settings.cronjobs = Bunch(enabled=False) session = app.session() town = session.query(Town).one() town.meta['reply_to'] = '*****@*****.**' app.mail_host, app.mail_port = smtp.address app.mail_sender = '*****@*****.**' app.mail_force_tls = False app.mail_username = None app.mail_password = None app.mail_use_directory = False app.smtp = smtp # usually we don't want to create the users directly, anywhere else you # *need* to go through the UserCollection. Here however, we can improve # the test speed by not hashing the password for every test. session.add(User( username='******', password_hash=town_password, role='admin' )) session.add(User( username='******', password_hash=town_password, role='editor' )) transaction.commit() session.close_all() return app