def test103_trans_move(self): finac.asset_create('UAH') finac.asset_set_rate('UAH/USD', value=0.04) finac.account_create('move.test', 'usd', 'current', 'Test move acc') finac.account_create('move1.TEST', 'UAH', 'current', 'Test move acc2') finac.transaction_create('move.test', 100, 'for move test') self.assertEqual(finac.account_balance('move.test'), 100) target_ct = 80 target_dt = 1200 finac.transaction_move('move1.TEST', 'move.test', target_ct=target_ct, tag='go ahead', note='cross currency: target_ct') self.assertEqual(finac.account_balance('move.test'), target_ct) finac.transaction_move('move1.TEST', 'move.test', target_dt=target_dt, tag='ahead', note='cross currency: target_dt') self.assertEqual(finac.account_balance('move1.test'), target_dt) self.assertRaises(ValueError, finac.transaction_move, 'move1.TEST', 'move.test', target_dt=100) print() finac.ls('move.test') finac.ls('move1.test') print()
def test062_asset_rate_delete(self): finac.asset_set_rate('EUR', 'USD', value=1.8, date='2018-12-01') self.assertEqual(finac.asset_rate('EUR', 'USD', date='2019-01-05'), 1.5) time.sleep(0.6) finac.asset_delete_rate('EUR', 'USD', date='2019-01-01') self.assertEqual(finac.asset_rate('EUR', 'USD', date='2019-01-05'), 1.8)
def test007_list_summary_and_passive(self): finac.core.config_set('base_asset', 'eur') finac.asset_set_rate('eur/usd', 1.11) self.assertEqual(finac.account_list_summary()['total'], 100) finac.account_create('supplier1', 'eur', tp='supplier') finac.account_create('taxes1', 'eur', tp='tax') finac.tr('supplier1', 10) finac.tr('taxes1', 10) self.assertEqual(finac.account_list_summary()['total'], 80) finac.ls(group_by='asset')
def test700_passive_prepare(self): sys.stdout.write('\n\n-----Starting passive block------\n\n') for a in finac.asset_list(): finac.asset_delete(a['asset']) finac.asset_create('usd') finac.asset_create('eur') finac.asset_set_rate('eur/usd', value=1.1) finac.account_create('active1', 'usd') finac.account_create('active2', 'eur') finac.account_create('passive1', 'usd', tp='finagent') finac.account_create('passive3', 'usd', tp='finagent') finac.account_create('passive2', 'eur', tp='finagent')
def test402_transaction_copy(self): finac.account_create('test.usd', 'usd') finac.account_create('test.eur', 'eur') finac.asset_set_rate('eur/usd', value=1.1) t = finac.transaction_create('test.usd', 100, tag='test', note='for move test') t1 = finac.transaction_move(dt='move.test', ct='test.usd', tag='copy 1', amount=10) t_cros = finac.transaction_move(dt='test.eur', ct='test.usd', amount=10) self.assertRaises(ValueError, finac.tc, transaction_ids=t_cros[1], amount=100) finac.tc(transaction_ids=t1, date='2019-11-15', amount=30) finac.tc(transaction_ids=[t, t_cros[1]])
def test901_rate_cache(self): if config.remote: return from cachetools import TTLCache finac.core._cache.rate = TTLCache(maxsize=1024, ttl=10) finac.core.config.rate_cache_ttl = 10 finac.core._CacheRateKeyError = RuntimeError finac.asset_set_rate('EUR/USD', 1.99, date='2019-05-05 11:00:00') try: self.assertEqual( finac.asset_rate('EUR/USD', date='2019-05-05 11:00:00'), 1.99) raise RuntimeError('Cache key error not raised') except KeyError: pass finac.core._CacheRateKeyError = KeyError self.assertEqual( finac.asset_rate('EUR/USD', date='2019-05-05 11:00:00'), 1.99) finac.core._CacheRateKeyError = RuntimeError self.assertEqual( finac.asset_rate('EUR/USD', date='2019-05-05 11:00:00'), 1.99) try: self.assertEqual( finac.asset_rate('EUR/USD', date='2019-05-05 11:00:01'), 1.99) raise RuntimeError('Cache key error not raised') except KeyError: pass finac.asset_create('CAT') finac.asset_set_rate('EUR/CAT', 1.11) try: self.assertEqual(finac.asset_rate('EUR/CAT'), 1.11) raise RuntimeError('Cache key error not raised') except KeyError: pass finac.core._CacheRateKeyError = KeyError self.assertEqual(finac.asset_rate('EUR/CAT'), 1.11) finac.core._CacheRateKeyError = RuntimeError time.sleep(0.1) self.assertEqual(finac.asset_rate('EUR/CAT'), 1.11) finac.core._CacheRateKeyError = KeyError
def test080_lazy_exchange(self): finac.account_create('eur1', 'eur') finac.account_create('usd1', 'usd') if not config.remote: finac.core.config_set('lazy_exchange', False) try: finac.transaction_move('usd1', 'eur1', 20) raise RuntimeError( 'Lazy exchange is off but asset mismatch not detected') except ValueError: pass finac.core.config_set('lazy_exchange', True) time.sleep(0.6) finac.asset_set_rate('EUR/USD', value=1.1) finac.transaction_move('usd1', 'eur1', 20, xdt=False) self.assertEqual(finac.account_balance('eur1'), -20) self.assertEqual(finac.account_balance('usd1'), 22) finac.transaction_move('usd1', 'eur1', 20) self.assertEqual(finac.account_balance('eur1'), -38.18) self.assertEqual(finac.account_balance('usd1'), 42) t1, t2 = finac.transaction_move('usd1', 'eur1', 20, rate=1.25) self.assertEqual(finac.account_balance('eur1'), -54.18) self.assertEqual(finac.account_balance('usd1'), 62) finac.transaction_delete(t1) self.assertEqual(finac.account_balance('eur1'), -38.18) self.assertEqual(finac.account_balance('usd1'), 42) t1, t2 = finac.transaction_move('usd1', 'eur1', 20, rate=1.25) self.assertEqual(finac.account_balance('eur1'), -54.18) self.assertEqual(finac.account_balance('usd1'), 62) finac.transaction_delete(t2) self.assertEqual(finac.account_balance('eur1'), -38.18) self.assertEqual(finac.account_balance('usd1'), 42)
def test081_test_cross(self): finac.asset_create('NZD') finac.asset_create('BZD') finac.asset_create('FKP') finac.asset_create('KPW') finac.asset_set_rate('NZD/BZD', value=2) finac.asset_set_rate('BZD/FKP', value=2.5) finac.asset_set_rate('FKP/KPW', value=3) self.assertEqual(finac.asset_rate('NZD/KPW'), 15) self.assertEqual(round(finac.asset_rate('KPW/NZD') * 100, 2), 6.67)
def test060_asset_rate_set(self): finac.asset_create('AUD') finac.asset_set_rate('EUR', 'USD', '1,5', date='2019-01-01') finac.asset_set_rate('EUR/USD', value=2) finac.asset_set_rate('AUD/USD', value='0,69') try: print(finac.asset_rate('EUR', 'USD', date='2018-01-01')) raise RuntimeError('Rate not found not raised') except finac.RateNotFound: pass self.assertEqual(finac.asset_rate('EUR', 'USD', date='2019-01-05'), 1.5) self.assertEqual(finac.asset_rate('EUR', 'USD'), 2)
def test901_rate_list_cache(self): if config.remote: return finac.asset_create('CA1') finac.asset_create('CA2') finac.asset_create('CA3') finac.asset_set_rate('CA1/CA2', 2, date='2019-05-05 11:00:00') finac.asset_set_rate('CA2/CA3', 4, date='2019-05-05 11:00:00') finac.core._CacheRateListKeyError = RuntimeError try: self.assertEqual( finac.asset_rate('CA1/CA3', date='2019-05-05 11:00:00'), 8) raise RuntimeError('Cache key error not raised') except KeyError: pass finac.core._CacheRateListKeyError = KeyError self.assertEqual( finac.asset_rate('CA1/CA3', date='2019-05-05 11:00:00'), 8) finac.core._CacheRateListKeyError = RuntimeError self.assertEqual( finac.asset_rate('CA1/CA3', date='2019-05-05 11:00:00'), 8) try: self.assertEqual( finac.asset_rate('CA1/CA3', date='2019-05-05 11:00:01'), 8) raise RuntimeError('Cache key error not raised') except KeyError: pass finac.asset_set_rate('CA1/CA2', 2) finac.asset_set_rate('CA2/CA3', 3) try: self.assertEqual(finac.asset_rate('CA1/CA3'), 6) raise RuntimeError('Cache key error not raised') except KeyError: pass finac.core._CacheRateListKeyError = KeyError self.assertEqual(finac.asset_rate('CA1/CA3'), 6) finac.core._CacheRateListKeyError = RuntimeError time.sleep(0.1) self.assertEqual(finac.asset_rate('CA1/CA3'), 6) finac.core._CacheRateListKeyError = KeyError