Skip to content

Commit

Permalink
Merge pull request #4703 from smotornyuk/cli-seed
Browse files Browse the repository at this point in the history
CLI. Implement `seed` command
  • Loading branch information
Konstantin Sivakov committed Apr 16, 2019
2 parents 4ffbd46 + c18d60b commit 8ec368a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ckan/cli/cli.py
Expand Up @@ -10,7 +10,7 @@
)

from ckan.config.middleware import make_app

from ckan.cli import seed

log = logging.getLogger(__name__)

Expand All @@ -32,6 +32,7 @@ def ckan(ctx, config, *args, **kwargs):

ckan.add_command(config_tool.config_tool)
ckan.add_command(server.run)
ckan.add_command(seed.seed)
ckan.add_command(db.db)
ckan.add_command(search_index.search_index)
ckan.add_command(translation.translation)
85 changes: 85 additions & 0 deletions ckan/cli/seed.py
@@ -0,0 +1,85 @@
# encoding: utf-8

import logging

import click

from ckan.lib.create_test_data import CreateTestData

log = logging.getLogger(__name__)


@click.group(short_help=u'Create test data in the database.')
def seed():
u'''Create test data in the database.
Tests can also delete the created objects easily with the delete() method.
'''
pass


@seed.command(short_help=u'Annakarenina and warandpeace.')
@click.pass_context
def basic(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_basic_test_data()


@seed.command(short_help=u'Realistic data to test search.')
@click.pass_context
def search(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_search_test_data()


@seed.command(short_help=u'Government style data.')
@click.pass_context
def gov(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_gov_test_data()


@seed.command(short_help=u'Package relationships data.')
@click.pass_context
def family(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_family_test_data()


@seed.command(short_help=u'Create a user "tester" with api key "tester".')
@click.pass_context
def user(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_test_user()
click.echo(
u'Created user {0} with password {0} and apikey {0}'.format(u'tester')
)


@seed.command(short_help=u'Test translations of terms.')
@click.pass_context
def translations(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_translations_test_data()


@seed.command(short_help=u'Some test vocabularies.')
@click.pass_context
def vocabs(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_vocabs_test_data()


@seed.command(short_help=u'Hierarchy of groups.')
@click.pass_context
def hierarchy(ctx):
flask_app = ctx.obj.app.apps[u'flask_app']._wsgi_app
with flask_app.test_request_context():
CreateTestData.create_group_hierarchy_test_data()
2 changes: 1 addition & 1 deletion ckan/lib/create_test_data.py
Expand Up @@ -61,7 +61,6 @@ def create_test_user(cls):
cls.user_refs.append(u'tester')

@classmethod

def create_translations_test_data(cls):
import ckan.model
CreateTestData.create()
Expand Down Expand Up @@ -99,6 +98,7 @@ def create_translations_test_data(cls):

ckan.model.Session.commit()

@classmethod
def create_vocabs_test_data(cls):
import ckan.model
CreateTestData.create()
Expand Down

0 comments on commit 8ec368a

Please sign in to comment.