def test_no_destination_amount(self): form = CurrencyTradeForm(dict( source_account=self.account_gbp.uuid, source_amount_0='100', source_amount_1='GBP', trading_account=self.trading_gbp_eur.uuid, destination_account=self.account_eur.uuid, destination_amount_0='', destination_amount_1='', )) self.assertFalse(form.is_valid())
def test_trading_account_no_destination_currency(self): form = CurrencyTradeForm(dict( source_account=self.account_gbp.uuid, source_amount_0='100', source_amount_1='GBP', trading_account=self.account(name='trading', type=Account.TYPES.trading, currencies=['GBP', 'USD']).uuid, destination_account=self.account_eur.uuid, destination_amount_0='110', destination_amount_1='EUR', )) self.assertFalse(form.is_valid())
def test_no_destination_account(self): form = CurrencyTradeForm( dict( source_account=self.account_gbp.uuid, source_amount_0="100", source_amount_1="GBP", trading_account=self.trading_gbp_eur.uuid, destination_account="", destination_amount_0="110", destination_amount_1="EUR", ) ) self.assertFalse(form.is_valid())
def test_trading_account_no_destination_currency(self): form = CurrencyTradeForm( dict( source_account=self.account_gbp.uuid, source_amount_0="100", source_amount_1="GBP", trading_account=self.account( name="trading", type=Account.TYPES.trading, currencies=["GBP", "USD"] ).uuid, destination_account=self.account_eur.uuid, destination_amount_0="110", destination_amount_1="EUR", ) ) self.assertFalse(form.is_valid())
def test_valid(self): form = CurrencyTradeForm(dict( source_account=self.account_gbp.uuid, source_amount_0='100', source_amount_1='GBP', trading_account=self.trading_gbp_eur.uuid, destination_account=self.account_eur.uuid, destination_amount_0='110', destination_amount_1='EUR', )) self.assertTrue(form.is_valid(), form.errors) form.save() self.assertEqual(self.account_gbp.balance(), Balance('-100', 'GBP')) self.assertEqual(self.trading_gbp_eur.balance(), Balance('-100', 'GBP', '110', 'EUR')) self.assertEqual(self.account_eur.balance(), Balance('110', 'EUR'))
def test_valid(self): form = CurrencyTradeForm( dict( source_account=self.account_gbp.uuid, source_amount_0="100", source_amount_1="GBP", trading_account=self.trading_gbp_eur.uuid, destination_account=self.account_eur.uuid, destination_amount_0="110", destination_amount_1="EUR", ) ) self.assertTrue(form.is_valid(), form.errors) form.save() self.assertEqual(self.account_gbp.balance(), Balance("-100", "GBP")) self.assertEqual(self.trading_gbp_eur.balance(), Balance("-100", "GBP", "110", "EUR")) self.assertEqual(self.account_eur.balance(), Balance("110", "EUR"))