Ejemplo n.º 1
0
Archivo: cli.py Proyecto: nawaflol/exch
def cli(base, target, amount):
    """
    Get the latetst currency exchange rates from:

    \b
        - fixer.io
    """

    output = fixer(base, target, amount)
    if isinstance(output, float):
        output = "{} {} = {} {}".format(amount, base, output, target)

    click.echo(output)
Ejemplo n.º 2
0
Archivo: cli.py Proyecto: chsqn/exch
def cli(ctx, base, target, amount, set_base, set_target):
    """
    Get the latetst currency exchange rates from:

    \b
        - fixer.io
    """

    if ctx.invoked_subcommand is None:
        output = fixer(base, target, amount, RATES_FIXER_JSON_FILE)
        if isinstance(output, float):
            # 2:.2f for two decimal values, manually specified
            output = "{0} {1} = {2:.2f} {3}".format(amount, base, output,
                                                    target)

        if set_base:
            set_default_base(base, DEFAULT_JSON_FILE)

        if set_target:
            set_default_target(target, DEFAULT_JSON_FILE)

        click.echo(output)
Ejemplo n.º 3
0
def test_fixer_same_currency_code():
    """ when the same currency is base as well as target """
    assert fixer('USD', 'USD', 1) == 1.00
    assert fixer('INR', 'INR', 1) == 1.00
Ejemplo n.º 4
0
def test_fixer_invalid_currency():
    """ when invalid currency is passed to fixer.io """
    assert fixer('USD', 'TTT', 1) == "Invalid currency"
    assert fixer('HHRR', 'TTT', 1) == "Invalid currency"
Ejemplo n.º 5
0
def test_fixer_gbp_to_php_value_99():
    """ fixer_io base: GBP, target: PHP, on date 2017-05-12, value: 99 """
    assert fixer('GBP', 'PHP', 99, date='2017-05-12') == round(63.942 * 99, 2)
Ejemplo n.º 6
0
def test_fixer_usd_to_jpy():
    """ fixer_io base: USD, target: JPY, on date 2017-05-12 """
    assert fixer('USD', 'JPY', 1, date='2017-05-12') == round(113.85, 2)
Ejemplo n.º 7
0
def test_fixer_usd_to_inr():
    """ fixer_io base: USD, target: INR, on date 2017-05-12 """
    assert fixer('USD', 'INR', 1, date='2017-05-12') == round(64.307, 2)
Ejemplo n.º 8
0
def test_fixer_invalid_currency():
    """ when invalid currency is passed to fixer.io """
    assert fixer('USD', 'TTT', 1,
                 FIXER_RATES_JSON_TEST) == "KeyError: Invalid curreny"
Ejemplo n.º 9
0
def test_fixer_nzd_to_eur_value():
    """ checking since stored values are in terms of EUR as base """
    assert fixer('NZD', 'EUR', 1, FIXER_RATES_JSON_TEST) > 0.5
Ejemplo n.º 10
0
def test_fixer_eur_to_aud_value_99():
    assert fixer('EUR', 'AUD', 99, FIXER_RATES_JSON_TEST) > 1.2 * 99
Ejemplo n.º 11
0
def test_fixer_gbp_to_php_value_99():
    """ fixer_io base: GBP, target: PHP, value: 99 """
    assert fixer('GBP', 'PHP', 99, FIXER_RATES_JSON_TEST) > 50
Ejemplo n.º 12
0
def test_fixer_usd_to_jpy():
    """ fixer_io base: USD, target: JPY """
    assert fixer('USD', 'JPY', 1, FIXER_RATES_JSON_TEST) > 90
Ejemplo n.º 13
0
def test_fixer_usd_to_inr():
    """ fixer_io base: USD, target: INR """
    assert fixer('USD', 'INR', 1, FIXER_RATES_JSON_TEST) > 60