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)
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)
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
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"
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)
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)
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)
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"
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
def test_fixer_eur_to_aud_value_99(): assert fixer('EUR', 'AUD', 99, FIXER_RATES_JSON_TEST) > 1.2 * 99
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
def test_fixer_usd_to_jpy(): """ fixer_io base: USD, target: JPY """ assert fixer('USD', 'JPY', 1, FIXER_RATES_JSON_TEST) > 90
def test_fixer_usd_to_inr(): """ fixer_io base: USD, target: INR """ assert fixer('USD', 'INR', 1, FIXER_RATES_JSON_TEST) > 60