def vocabularies(): """Create vocabularies fake records.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False, verbose=True): click.secho("ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) vocabularies_dir = os.path.join( os.path.realpath("."), "cds_ils", "vocabularies", "data", ) json_files = " ".join( os.path.join(vocabularies_dir, name) for name in os.listdir(vocabularies_dir) if name.endswith(".json")) run_command("vocabulary index json --force {}".format(json_files)) run_command("vocabulary index opendefinition spdx --force") run_command("vocabulary index opendefinition opendefinition --force") # index languages run_command("vocabulary index languages --force")
def test_import_ddb_file(self): runner = current_app.test_cli_runner() result = runner.invoke(import_file, [os.path.dirname(__file__) + "/../custom_ddb.txt"]) self.assertEqual(result.exit_code, 0) device_infos = db.session.query(DeviceInfo).all() self.assertEqual(len(device_infos), 6)
def index_ldap_users(): """Index ldap users in ES.""" from invenio_base.app import create_cli cli = create_cli() runner = current_app.test_cli_runner() command = "ils patrons index" click.secho('ils {}...'.format(command), fg='green') runner.invoke(cli, command, catch_exceptions=True)
def test_import_ddb(self): runner = current_app.test_cli_runner() ddb_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "../custom_ddb.txt")) result = runner.invoke(import_ddb, ['--path', ddb_path]) self.assertEqual(result.exit_code, 0) sender_infos = db.session.query(SenderInfo).all() self.assertEqual(len(sender_infos), 6)
def index_ldap_users(): """Index ldap users in ES.""" from invenio_base.app import create_cli cli = create_cli() runner = current_app.test_cli_runner() command = "ils patrons index" runner.invoke(cli, command, catch_exceptions=True) _log_info("command_executed", dict(command=command))
def reindex_pidtype(pid_type): """Reindex records with the specified pid_type.""" click.echo('Indexing pid type "{}"...'.format(pid_type)) cli = create_cli() runner = current_app.test_cli_runner() runner.invoke(cli, 'index reindex --pid-type {} --yes-i-know'.format(pid_type), catch_exceptions=False) runner.invoke(cli, 'index run', catch_exceptions=False) click.echo('Indexing completed!')
def _build_local_assets(log_config, statics=True, webpack=True): """Build assets locally.""" cli = create_cli() runner = current_app.test_cli_runner() if statics: # Collect run_command(cli, runner, "collect -v", message="Collecting assets...", verbose=log_config.verbose) if webpack: # Build using webpack run_command(cli, runner, "webpack buildall", message="Building assets...", verbose=log_config.verbose)
def clean(user_email, given_date, verbose): """Remove loans of user.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("cds-ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) if not given_date: given_date = arrow.utcnow().format("YYYY-MM-DD") run_command("user-testing clean-loans --user-email " + user_email + " --given-date " + given_date)
def prepare(user_email, verbose): """Create loans for user.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("cds-ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # create ongoing loan run_command("user-testing create-loan --user-email " + user_email) # create past loan run_command("user-testing create-loan --is-past-loan --user-email " + user_email)
def import_demo_data(path, are_docs, are_items, verbose): """Import real demo data.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("cds-ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) if are_docs: command = "create-demo-docs" elif are_items: command = "create-demo-items" run_command("user-testing " + command + " --json-path " + path)
def setup(log_config, local=True, force=False, stop_containers=False, docker_helper=None, project_shortname='invenio-rdm'): """Bootstrap server.""" click.secho('Setting up server...', fg='green') click.secho("Starting containers...", fg="green") docker_helper.start_containers() time.sleep(60) # Give time to the containers to start properly if local: cli = create_cli() runner = current_app.test_cli_runner() _setup_local(force, cli, runner, log_config) else: _setup_containers(force, docker_helper, project_shortname, log_config) if stop_containers: click.secho("Stopping containers...", fg="green") docker_helper.stop_containers() time.sleep(30)
def demo_patrons(): """Create demo patrons.""" cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False, verbose=True): click.secho("ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Create roles to restrict access run_command("roles create admin") run_command("roles create librarian") # Create users run_command("users create [email protected] -a --password=123456") # ID 1 create_userprofile_for("*****@*****.**", "patron1", "Yannic Vilma") run_command("users create [email protected] -a --password=123456") # ID 2 create_userprofile_for("*****@*****.**", "patron2", "Diana Adi") run_command("users create [email protected] -a --password=123456") # ID 3 create_userprofile_for("*****@*****.**", "admin", "Zeki Ryoichi") run_command("users create [email protected] -a --password=123456") # ID 4 create_userprofile_for("*****@*****.**", "librarian", "Hector Nabu") run_command("users create [email protected] -a --password=123456") # ID 5 create_userprofile_for("*****@*****.**", "patron3", "Medrod Tara") run_command("users create [email protected] -a --password=123456") # ID 6 create_userprofile_for("*****@*****.**", "patron4", "Devi Cupid") # Assign roles run_command("roles add [email protected] admin") run_command("roles add [email protected] librarian") # Assign actions run_command("access allow superuser-access role admin") run_command("access allow ils-backoffice-access role librarian") run_command("patrons index")
def populate_demo_records(local, docker_helper, project_shortname, log_config, stop_containers=False): """Add demo records into the instance.""" click.secho('Setting up server...', fg='green') cli = create_cli() runner = current_app.test_cli_runner() click.secho("Starting containers...", fg="green") docker_helper.start_containers() time.sleep(60) # Give time to the containers to start properly if local: run_command(cli, runner, 'rdm-records demo', message="Populating instance with demo records...", verbose=log_config.verbose) else: click.secho("Populating instance with demo records...", fg="green") docker_helper.execute_cli_command(project_shortname, 'invenio rdm-records demo') if stop_containers: docker_helper.stop_containers() time.sleep(30)
def setup(recreate_db, skip_demo_data, skip_file_location, skip_patrons, skip_vocabularies, verbose): """ILS setup command.""" from flask import current_app from invenio_base.app import create_cli import redis click.secho("ils setup started...", fg="blue") # Clean redis redis.StrictRedis.from_url( current_app.config["CACHE_REDIS_URL"]).flushall() click.secho("redis cache cleared...", fg="red") cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho("ils {}...".format(command), fg="green") res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Remove and create db and indexes if recreate_db: run_command("db destroy --yes-i-know", catch_exceptions=True) run_command("db init") else: run_command("db drop --yes-i-know") run_command("db create") run_command("index destroy --force --yes-i-know") run_command("index init --force") run_command("index queue init purge") # Create roles to restrict access run_command("roles create admin") run_command("roles create librarian") if not skip_patrons: # Create users run_command( "users create [email protected] -a --password=123456") # ID 1 create_userprofile_for("*****@*****.**", "patron1", "Yannic Vilma") run_command( "users create [email protected] -a --password=123456") # ID 2 create_userprofile_for("*****@*****.**", "patron2", "Diana Adi") run_command("users create [email protected] -a --password=123456") # ID 3 create_userprofile_for("*****@*****.**", "admin", "Zeki Ryoichi") run_command( "users create [email protected] -a --password=123456") # ID 4 create_userprofile_for("*****@*****.**", "librarian", "Hector Nabu") run_command( "users create [email protected] -a --password=123456") # ID 5 create_userprofile_for("*****@*****.**", "patron3", "Medrod Tara") run_command( "users create [email protected] -a --password=123456") # ID 6 create_userprofile_for("*****@*****.**", "patron4", "Devi Cupid") # Assign roles run_command("roles add [email protected] admin") run_command("roles add [email protected] librarian") if not skip_vocabularies: vocabularies_dir = os.path.join(os.path.realpath("."), "invenio_app_ils", "vocabularies", "data") json_files = " ".join( os.path.join(vocabularies_dir, name) for name in os.listdir(vocabularies_dir) if name.endswith(".json")) run_command("vocabulary index json --force {}".format(json_files)) run_command("vocabulary index opendefinition spdx --force") run_command("vocabulary index opendefinition opendefinition --force") # Assign actions run_command("access allow superuser-access role admin") run_command("access allow ils-backoffice-access role librarian") # Index patrons run_command("patrons index") # Create files location if not skip_file_location: run_command("files location --default ils /tmp/ils-files") # Generate demo data if not skip_demo_data: run_command("demo data") click.secho("ils setup finished successfully", fg="blue")
def setup(skip_db_destroy, skip_demo_data, skip_patrons, verbose): """ILS setup command.""" from flask import current_app from invenio_base.app import create_cli import redis click.secho('ils setup started...', fg='blue') # Clean redis redis.StrictRedis.from_url( current_app.config['CACHE_REDIS_URL']).flushall() click.secho('redis cache cleared...', fg='red') cli = create_cli() runner = current_app.test_cli_runner() def run_command(command, catch_exceptions=False): click.secho('ils {}...'.format(command), fg='green') res = runner.invoke(cli, command, catch_exceptions=catch_exceptions) if verbose: click.secho(res.output) # Remove and create db and indexes if not skip_db_destroy: run_command('db destroy --yes-i-know', catch_exceptions=True) run_command('db init create') run_command('index destroy --force --yes-i-know') run_command('index init --force') run_command('index queue init purge') # Create roles to restrict access run_command('roles create admin') run_command('roles create librarian') if not skip_patrons: # Create users run_command( 'users create [email protected] -a --password=123456') # ID 1 run_command( 'users create [email protected] -a --password=123456') # ID 2 run_command('users create [email protected] -a --password=123456') # ID 3 run_command( 'users create [email protected] -a --password=123456') # ID 4 run_command( 'users create [email protected] -a --password=123456') # ID 5 run_command( 'users create [email protected] -a --password=123456') # ID 6 # Assign roles run_command('roles add [email protected] admin') run_command('roles add [email protected] librarian') # Assign actions run_command('access allow superuser-access role admin') run_command('access allow ils-backoffice-access role librarian') # Index patrons run_command('patrons index') # Generate demo data if not skip_demo_data: run_command('demo data') click.secho('ils setup finished successfully', fg='blue')