Files
@ baa2e883cdfe
Branch filter:
Location: NPO-Accounting/oxrlib/tests/test_Configuration.py - annotation
baa2e883cdfe
3.8 KiB
text/x-python
config: historical command accepts just two currency arguments.
This shows the rates between two currencies without converting a specific
amount.
This shows the rates between two currencies without converting a specific
amount.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | 385a492ae735 08073f752bc8 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 18f7ea7038d3 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 18f7ea7038d3 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 0120e4ce5a5a 08073f752bc8 08073f752bc8 08073f752bc8 baa2e883cdfe baa2e883cdfe 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 baa2e883cdfe baa2e883cdfe 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 08073f752bc8 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 385a492ae735 | import datetime
import decimal
import os
import pytest
from . import any_date, relpath
import oxrlib.cache
import oxrlib.config
import oxrlib.loaders
INI_DIR_PATH = relpath('config_ini')
def config_from(ini_filename, arglist=None):
if arglist is None:
arglist = ['historical', any_date().isoformat()]
ini_path = INI_DIR_PATH / ini_filename
return oxrlib.config.Configuration(['--config-file', ini_path.as_posix()] + arglist)
def test_full_config():
config = config_from('full.ini')
loaders = config.get_loaders().loaders
assert type(loaders[0]) is oxrlib.loaders.FileCache
assert type(loaders[1]) is oxrlib.loaders.OXRAPIRequest
assert len(loaders) == 2
assert type(config.cache) is oxrlib.cache.CacheWriter
def test_incomplete_config():
config = config_from('incomplete.ini')
assert not config.get_loaders().loaders
def test_empty_config():
config = config_from(os.devnull)
assert not config.get_loaders().loaders
@pytest.mark.parametrize('ini_filename,expected_currency,use_switch', [
(os.devnull, 'USD', False),
('full.ini', 'INI', False),
('full.ini', 'EUR', True),
])
def test_historical_default_base(ini_filename, expected_currency, use_switch, any_date):
arglist = ['historical']
if use_switch:
arglist.extend(['--base', expected_currency])
arglist.append(any_date.isoformat())
config = config_from(ini_filename, arglist)
assert config.args.base == expected_currency
@pytest.mark.parametrize('amount,from_curr,preposition,to_curr', [
(None, 'JPY', None, None),
(None, 'gbp', None, 'Aud'),
(None, 'CHF', 'to', 'eur'),
(decimal.Decimal('1000'), 'chf', None, None),
(decimal.Decimal('999'), 'Eur', None, 'Chf'),
(decimal.Decimal('12.34'), 'gbp', 'IN', 'eur'),
])
def test_historical_argparsing_success(amount, from_curr, preposition, to_curr, any_date):
arglist = ['historical', any_date.isoformat()]
arglist.extend(str(s) for s in [amount, from_curr, preposition, to_curr]
if s is not None)
config = config_from(os.devnull, arglist)
assert config.args.amount == amount
assert config.args.from_currency == from_curr.upper()
if to_curr is not None:
assert config.args.to_currency == to_curr.upper()
@pytest.mark.parametrize('arglist', [
['100'],
['120', 'dollars'],
['to', '42', 'usd'],
['99', 'usd', 'minus', 'jpy'],
['usdjpy'],
['44', 'eur', 'in', 'chf', 'pronto'],
['eur', 'into'],
['50', 'jpy', 'in'],
])
def test_historical_argparsing_failure(arglist, any_date):
arglist = ['historical', any_date.isoformat()] + arglist
try:
config = config_from(os.devnull, arglist)
except SystemExit:
pass
else:
assert not vars(config.args), "bad arglist succeeded"
@pytest.mark.parametrize('date_s,expect_year,expect_month,expect_day', [
('5', 1965, 4, 5),
('05', 1965, 4, 5),
('3-6', 1965, 3, 6),
('5.10', 1965, 5, 10),
('06-09', 1965, 6, 9),
('917/12/12', 917, 12, 12),
('2017-11-1', 2017, 11, 1),
])
def test_good_date_parsing(date_s, expect_year, expect_month, expect_day):
oxrlib.config.Configuration.TODAY = datetime.date(1965, 4, 3)
config = config_from(os.devnull, ['historical', date_s])
actual_date = config.args.date
assert actual_date.year == expect_year
assert actual_date.month == expect_month
assert actual_date.day == expect_day
@pytest.mark.parametrize('date_s', [
'99',
'8-88',
'77-7',
'0xf-1-2',
'0b1-3-4',
'2017/5.9',
'2018-6/10',
'1-2-3-4',
'12/11/10',
])
def test_bad_date_parsing(date_s):
try:
config = config_from(os.devnull, ['historical', date_s])
except SystemExit:
pass
else:
assert not config.args.date, "date parsed from {!r}".format(date_s)
|