Ejemplo n.º 1
0
def test_localcommands_destroy(docker_helper_subprocess, patched_subprocess,
                               fake_cli_config):
    commands = LocalCommands(fake_cli_config)

    # Needed to fake call to docker-compose --version but not call
    # to docker-compose up
    def fake_normalize_name(self, project_shortname):
        return 'project_shortname'

    with patch.object(DockerHelper, '_normalize_name', fake_normalize_name):

        def docker_helper(project_shortname, local):
            return DockerHelper('project-shortname', local=True)

        patch_handle = patch('invenio_cli.helpers.commands.DockerHelper',
                             docker_helper)
        patch_handle.start()
        commands.destroy()
        patch_handle.stop()

    patched_subprocess.run.assert_called_with(['pipenv', '--rm'], check=True)
    docker_helper_subprocess.call.assert_called_with([
        'docker-compose', '--file', 'docker-compose.yml', 'down', '--volumes'
    ])
    assert fake_cli_config.services_setup is False
Ejemplo n.º 2
0
def test_localcommands_install_py_dependencies(patched_subprocess):
    commands = LocalCommands(Mock())

    commands._install_py_dependencies(pre=True, lock=True)

    patched_subprocess.run.assert_any_call(
        ['pipenv', 'install', '--dev', '--pre'],
        check=True
    )

    commands._install_py_dependencies(pre=True, lock=False)

    patched_subprocess.run.assert_any_call(
        ['pipenv', 'install', '--dev', '--pre', '--skip-lock'],
        check=True
    )

    commands._install_py_dependencies(pre=False, lock=True)

    patched_subprocess.run.assert_any_call(
        ['pipenv', 'install', '--dev'],
        check=True
    )

    commands._install_py_dependencies(pre=False, lock=False)

    patched_subprocess.run.assert_any_call(
        ['pipenv', 'install', '--dev', '--skip-lock'],
        check=True
    )
Ejemplo n.º 3
0
def test_localcommands_demo(patched_docker_helper, patched_time,
                            patched_subprocess, fake_cli_config):
    commands = LocalCommands(fake_cli_config)

    commands.demo()

    patched_subprocess.run.assert_called_with(
        ['pipenv', 'run', 'invenio', 'rdm-records', 'demo'], check=True)
Ejemplo n.º 4
0
def test_localcommands_symlink_assets_templates(patched_os, fake_cli_config):
    commands = LocalCommands(fake_cli_config)
    files_to_link = ['instance_dir/templates/template.js']

    commands._symlink_assets_templates(files_to_link)

    patched_os.symlink.assert_called_with(
        'project_dir/templates/template.js',
        'instance_dir/templates/template.js')
Ejemplo n.º 5
0
def test_localcommands_update_instance_path(patched_subprocess):
    cli_config = Mock()
    patched_subprocess.run.return_value = Mock(stdout='instance_dir')
    commands = LocalCommands(cli_config)

    commands._update_instance_path()

    patched_subprocess.run.assert_called_with(
        ['pipenv', 'run', 'invenio', 'shell', '--no-term-title',
            '-c', '"print(app.instance_path, end=\'\')"'],
        check=True, universal_newlines=True, stdout=patched_subprocess.PIPE
    )
    cli_config.update_instance_path.assert_called_with('instance_dir')
Ejemplo n.º 6
0
def test_localcommands_run(
        patched_docker_helper, patched_time, patched_subprocess,
        fake_cli_config):
    commands = LocalCommands(fake_cli_config)

    commands.run()

    run_env = os.environ.copy()
    run_env['FLASK_ENV'] = 'development'
    expected_calls = [
        call([
            'pipenv', 'run', 'celery', 'worker', '--app', 'invenio_app.celery'
        ]),
        call([
            'pipenv', 'run', 'invenio', 'run', '--cert',
            'docker/nginx/test.crt', '--key', 'docker/nginx/test.key'
        ], env=run_env),
        call().wait()
    ]
    assert patched_subprocess.Popen.mock_calls == expected_calls
Ejemplo n.º 7
0
def test_localcommands_update_statics_and_assets(
        patched_subprocess, patched_dir_util, fake_cli_config):

    commands = LocalCommands(fake_cli_config)

    commands.update_statics_and_assets(install=True)

    expected_calls = [
        call(['pipenv', 'run', 'invenio', 'collect', '--verbose'], check=True),
        call(['pipenv', 'run', 'invenio', 'webpack', 'create'], check=True),
        call(['pipenv', 'run', 'invenio', 'webpack', 'install'], check=True),
        call(['pipenv', 'run', 'invenio', 'webpack', 'build'], check=True),
    ]
    assert patched_subprocess.run.mock_calls == expected_calls
    patched_dir_util.copy_tree.assert_any_call(
        'project_dir/static', 'instance_dir/static'
    )
    patched_dir_util.copy_tree.assert_any_call(
        'project_dir/assets', 'instance_dir/assets'
    )

    # Reset for install=False assertions
    patched_subprocess.run.reset_mock()

    commands.update_statics_and_assets(install=False)

    expected_calls = [
        call(['pipenv', 'run', 'invenio', 'collect', '--verbose'], check=True),
        call(['pipenv', 'run', 'invenio', 'webpack', 'create'], check=True),
        call(['pipenv', 'run', 'invenio', 'webpack', 'build'], check=True)
    ]
    assert patched_subprocess.run.mock_calls == expected_calls
Ejemplo n.º 8
0
def test_localcommands_install():
    commands = LocalCommands(fake_cli_config)
    commands._install_py_dependencies = Mock()
    commands._update_instance_path = Mock()
    commands._symlink_project_file_or_folder = Mock()
    commands.update_statics_and_assets = Mock()

    commands.install(False, False)

    commands._install_py_dependencies.assert_called_with(False, False)
    commands._update_instance_path.assert_called()
    expected_symlink_calls = [
        call('invenio.cfg'),
        call('templates'),
        call('app_data')
    ]
    assert (commands._symlink_project_file_or_folder.mock_calls ==
            expected_symlink_calls)
    commands.update_statics_and_assets.assert_called_with(install=True)
Ejemplo n.º 9
0
def test_symlink_project_file_or_folder(patched_os, fake_cli_config):
    commands = LocalCommands(fake_cli_config)
    file = 'invenio.cfg'

    commands._symlink_project_file_or_folder(file)

    patched_os.symlink.assert_called_with(
        Path('project_dir/invenio.cfg'), Path('instance_dir/invenio.cfg'))

    folder = 'templates/'

    commands._symlink_project_file_or_folder(folder)

    patched_os.symlink.assert_called_with(
        Path('project_dir/templates'), Path('instance_dir/templates'))
Ejemplo n.º 10
0
def test_localcommands_services(
        patched_docker_helper, patched_time, patched_subprocess,
        fake_cli_config):
    commands = LocalCommands(fake_cli_config)

    commands.services(force=False)

    expected_setup_calls = [
        call(['pipenv', 'run', 'invenio', 'db', 'init', 'create'], check=True),
        call([
            'pipenv', 'run', 'invenio', 'files', 'location', 'create',
            '--default', 'default-location', 'instance_dir/data'
        ], check=True),
        call([
            'pipenv', 'run', 'invenio', 'roles', 'create', 'admin'
        ], check=True),
        call([
            'pipenv', 'run', 'invenio', 'access', 'allow',
            'superuser-access', 'role', 'admin'
        ], check=True),
        call(['pipenv', 'run', 'invenio', 'index', 'init'], check=True)
    ]
    assert patched_subprocess.run.mock_calls == expected_setup_calls

    # Reset for install=False assertions
    patched_subprocess.run.reset_mock()

    commands.services(force=True)

    expected_force_calls = [
        call([
            'pipenv', 'run', 'invenio', 'shell', '--no-term-title', '-c',
            "import redis; redis.StrictRedis.from_url(app.config['CACHE_REDIS_URL']).flushall(); print('Cache cleared')"  # noqa
        ], check=True),
        call([
            'pipenv', 'run', 'invenio', 'db', 'destroy', '--yes-i-know',
        ], check=True),
        call([
            'pipenv', 'run', 'invenio', 'index', 'destroy', '--force',
            '--yes-i-know'
        ], check=True),
        call([
            'pipenv', 'run', 'invenio', 'index', 'queue', 'init', 'purge',
        ], check=True)
    ]
    assert patched_subprocess.run.mock_calls == (
        expected_force_calls + expected_setup_calls
    )