~trufas/ledgeroni

239222f72da5a87f51085b1c558ca883b8420a12 — Rafael Castillo 1 year, 10 months ago d684671
Make ledger file parameter required
4 files changed, 87 insertions(+), 15 deletions(-)

M ledgeroni/cli.py
A tests/integration/test_balance.py
A tests/integration/test_print.py
R tests/{test_cli.py => integration/test_register.py}
M ledgeroni/cli.py => ledgeroni/cli.py +1 -1
@@ 14,7 14,7 @@ init()

@click.group()
@click.option('--ledger-files', '--file', '-f', multiple=True,
              help='ledger files')
              help='ledger files', required="true")
@click.option('--price-db', help='price database')
@click.option('--sort', '-S', type=str,
              help='specifies how transactions should be sorted')

A tests/integration/test_balance.py => tests/integration/test_balance.py +29 -0
@@ 0,0 1,29 @@
from click.testing import CliRunner
from ledgeroni.cli import cli


def test_balance():
    "Tests the balance command without any options"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'balance'])
    assert result.exit_code == 0


def test_bal_alias():
    "Makes sure the balance alias is registered"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'bal'])
    assert result.exit_code == 0
    assert "1.50 BTC  Asset:Bitcoin Wallet" in result.output


def test_without_ledger():
    "Throws an error when no ledger file is specified"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '--price-db', 'tests/sample_data/prices_db', 'balance'])
    assert result.exit_code == 2

A tests/integration/test_print.py => tests/integration/test_print.py +33 -0
@@ 0,0 1,33 @@
from click.testing import CliRunner
from ledgeroni.cli import cli


def test_printing():
    "Tests print command output without extra options"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'print'])
    assert result.exit_code == 0
    assert "Sold some bitcoins" in result.output
    assert "I owe Joe for a favor" in result.output


def test_filtering():
    "Tests print command output with a filter specified"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'print', 'Expense'])
    assert result.exit_code == 0
    assert 'Sold some bitcoins' not in result.output
    assert 'Purchased reddit gold for the year' in result.output
    assert 'I owe Joe for a favor' in result.output


def test_without_ledger():
    "Throws an error when no ledger file is specified"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '--price-db', 'tests/sample_data/prices_db', 'balance'])
    assert result.exit_code == 2

R tests/test_cli.py => tests/integration/test_register.py +24 -14
@@ 1,37 1,47 @@
from click.testing import CliRunner
from ledgeroni.cli import cli

def test_balance():

def test_register():
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'bal', 'Expense'])
    assert result.exit_code == 0
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'balance', 'Expense'])
        'tests/sample_data/prices_db', 'register'])
    assert result.exit_code == 0
    assert "Sold some bitcoins" in result.output
    assert "I owe Joe for a favor" in result.output


def test_print():
def test_r_alias():
    "Tests whether the r alias is registered properly"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'print', 'Expense'])
        'tests/sample_data/prices_db', 'r'])
    assert result.exit_code == 0
    assert "Sold some bitcoins" in result.output
    assert "I owe Joe for a favor" in result.output


def test_register():
def test_reg_alias():
    "Tests whether the reg alias is registered properly"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'register', 'Expense'])
        'tests/sample_data/prices_db', 'reg'])
    assert result.exit_code == 0
    assert "Sold some bitcoins" in result.output
    assert "I owe Joe for a favor" in result.output


def test_filtering():
    "Tests a simple filter for the reg command"
    runner = CliRunner()
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'reg', 'Expense'])
    assert result.exit_code == 0
    result = runner.invoke(cli, [
        '-f', 'tests/sample_data/index.ledger', '--price-db',
        'tests/sample_data/prices_db', 'r', 'Expense'])
    assert result.exit_code == 0
    assert 'Sold some bitcoins' not in result.output
    assert 'Purchased reddit gold for the year' in result.output
    assert 'I owe Joe for a favor' in result.output