Skip to content

Commit

Permalink
Test "unable" exception, add help
Browse files Browse the repository at this point in the history
  • Loading branch information
dmiwell committed Jul 6, 2020
1 parent 2ac6d0f commit 5677b3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions peewee_migrate/cli.py
Expand Up @@ -86,9 +86,16 @@ def create(name, database=None, auto=False, auto_source=False, directory=None, v

@cli.command()
@click.argument('name', required=False)
@click.option('--count', required=False, default=1, type=int)
@click.option('--count',
required=False,
default=1,
type=int,
help="Number of last migrations to be rolled back."
"Ignored in case of non-empty name")
@click.option('--database', default=None, help="Database connection")
@click.option('--directory', default='migrations', help="Directory where migrations are stored")
@click.option('--directory',
default='migrations',
help="Directory where migrations are stored")
@click.option('-v', '--verbose', count=True)
def rollback(name, count, database=None, directory=None, verbose=None):
"""
Expand Down
10 changes: 8 additions & 2 deletions tests/test_cli.py
@@ -1,8 +1,7 @@
from click.testing import CliRunner
import pytest

from peewee_migrate.cli import cli
from peewee_migrate.cli import get_router
from peewee_migrate.cli import cli, get_router

runner = CliRunner()

Expand Down Expand Up @@ -72,6 +71,12 @@ def test_list(dir_option, db_option, migrations):
def test_rollback(dir_option, db_option, router, migrations):
router().run()

count_overflow = len(migrations) + 1
result = runner.invoke(cli, ['rollback', dir_option, db_option, '--count=%s' % count_overflow])
assert result.exception
assert 'Unable to rollback %s migrations' % count_overflow in result.exception.args[0]
assert router().done == migrations

result = runner.invoke(cli, ['rollback', dir_option, db_option])
assert not result.exception
assert router().done == migrations[:-1]
Expand All @@ -87,6 +92,7 @@ def test_rollback(dir_option, db_option, router, migrations):
result = runner.invoke(cli, ['rollback', dir_option, db_option, '005_test'])
assert result.exception
assert result.exception.args[0] == 'Only last migration can be canceled.'
assert router().done == migrations[:-4]


def test_fake(dir_option, db_option, migrations_str, router):
Expand Down

0 comments on commit 5677b3d

Please sign in to comment.