Skip to content

Commit

Permalink
cli: changed startproject command
Browse files Browse the repository at this point in the history
* Changed CLI command start project, which creates a skeleton
  of a new invenio site, to 'instance create'. (closes #28)

Signed-off-by: Javier Delgado <javier.delgado.fernandez@cern.ch>
  • Loading branch information
JavierDelgadoFernandez committed Nov 6, 2015
1 parent a273e8f commit 3661aac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
10 changes: 5 additions & 5 deletions invenio_base/__init__.py
Expand Up @@ -42,9 +42,9 @@
--help Show this message and exit.
Commands:
run Runs a development server.
shell Runs a shell in the app context.
startproject Create a new project from template.
run Runs a development server.
shell Runs a shell in the app context.
instance create Create a new project from template.
The ``run`` and ``shell`` commands only works if you have specified the
Expand All @@ -55,12 +55,12 @@
Starting a new project
~~~~~~~~~~~~~~~~~~~~~~
The ``startproject`` subcommand helps you bootstrap a minimal Invenio
The ``instance create`` subcommand helps you bootstrap a minimal Invenio
application:
.. code-block:: console
$ inveniomanage startproject mysite
$ inveniomanage instance create mysite
$ find mysite
Expand Down
4 changes: 2 additions & 2 deletions invenio_base/app.py
Expand Up @@ -35,7 +35,7 @@
from flask import Flask
from flask_cli import FlaskCLI, FlaskGroup

from .cmd import startproject
from .cmd import instance


def create_app_factory(app_name, conf_loader=None,
Expand Down Expand Up @@ -145,7 +145,7 @@ def cli(**params):
pass

# Add command for startin new Invenio instances.
cli.add_command(startproject)
cli.add_command(instance)

return cli

Expand Down
9 changes: 7 additions & 2 deletions invenio_base/cmd.py
Expand Up @@ -30,9 +30,14 @@
from pkg_resources import resource_filename


@click.command()
@click.group()
def instance():
"""Instance commands."""


@instance.command('create')
@click.argument('name')
def startproject(name):
def create(name):
"""Create a new project from template."""
path = resource_filename(__name__, "cookiecutter-invenio-base")

Expand Down
15 changes: 8 additions & 7 deletions tests/test_cmd.py
Expand Up @@ -30,35 +30,36 @@

from click.testing import CliRunner

from invenio_base.cmd import startproject
from invenio_base.cmd import instance


def test_startproject():
def test_instance_create():
"""Test startproject command."""
runner = CliRunner()

# Missing arg
result = runner.invoke(startproject, [])
result = runner.invoke(instance, ['create'])
assert result.exit_code != 0

# With arg
with runner.isolated_filesystem():
result = runner.invoke(startproject, ['mysite'])
result = runner.invoke(instance, ['create', 'mysite'])
assert result.exit_code == 0


def test_startproject_created_project():
def test_instance_create_created_project():
"""Test startproject command checking the result project."""
runner = CliRunner()

# Missing arg
result = runner.invoke(startproject, [])
result = runner.invoke(instance, ['create'])
assert result.exit_code != 0

# With arg
with runner.isolated_filesystem():
site_name = 'mysite2'
result = runner.invoke(startproject, [site_name])
result = runner.invoke(instance, ['create', site_name])
assert result.exit_code == 0
path_to_folder = os.path.join(os.getcwd(), site_name)
path_to_manage = os.path.join(path_to_folder, 'manage.py')
assert call(['python', path_to_manage]) == 0

0 comments on commit 3661aac

Please sign in to comment.