diff --git a/tests/test_account.py b/tests/test_account.py index a0c4b9f..c9475b3 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -6,7 +6,6 @@ FillOrderStage, BuyOrder, SellOrder, - Owner, Exchange, Security, Tick, @@ -16,6 +15,7 @@ ) from pyStock.models.account import ( Account, + Owner, Broker, ) from pyStock.models.money import ( @@ -83,8 +83,7 @@ def test_holding_value(self): def test_total_value(self): account=Account(owner=self.owner, broker=self.free_broker) - money = Money(amount=1000, currency=self.pesos) - account.deposit(money) + account.deposit(self.money) share=10 price = 9.1 @@ -234,7 +233,8 @@ def _buy_stock(self): pesos = Currency(name='Pesos', code='ARG') broker = Broker(name='Cheap') self.account = Account(broker=broker) - self.account.deposit(Money(amount=Decimal(10000), currency=pesos)) + ten_thousand_pesos = Money(amount=Decimal(10000), currency=pesos) + self.account.deposit(ten_thousand_pesos) exchange = Exchange(name='Merval', currency=pesos) self.security = Stock(symbol='PBR', description='Petrobras BR', ISIN='US71654V4086', exchange=exchange) filled_stage = FillOrderStage(executed_on=datetime.datetime.now()) diff --git a/tests/test_money.py b/tests/test_money.py index 6e1a71b..1582640 100644 --- a/tests/test_money.py +++ b/tests/test_money.py @@ -8,6 +8,11 @@ Currency, Money, ) +from pyStock.models.account import ( + Account, + Broker, + Owner +) from . import DatabaseTest @@ -28,33 +33,38 @@ def test_not_equals(self): class TestMoney(DatabaseTest): + def setup(self): + self.owner = Owner(name='lucky') + self.free_broker = Broker(name='Free Broker') + self.account = Account(broker=self.broker, owner=self.owner) + def test_money_compare_currencies(self): currency_arg, created = get_or_create(self.session, Currency, name='Peso', code='ARG') currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - ar_10, created = get_or_create(self.session, Money, amount=10, currency=currency_arg) - usd_10, created = get_or_create(self.session, Money, amount=10, currency=currency_usd) + ar_10 = Money(amount=10, currency=currency_arg) + usd_10 = Money(amount=10, currency=currency_usd) def test_money_gt(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=10, currency=currency_usd) - usd_11, created = get_or_create(self.session, Money, amount=11, currency=currency_usd) + usd_10 = Money(amount=10, currency=currency_usd) + usd_11 = Money(amount=11, currency=currency_usd) self.assertTrue(usd_11 > usd_10) def test_money_lt(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=10, currency=currency_usd) - usd_11, created = get_or_create(self.session, Money, amount=11, currency=currency_usd) + usd_10 = Money(amount=10, currency=currency_usd) + usd_11 = Money(amount=11, currency=currency_usd) self.assertFalse(usd_11 < usd_10) def test_money_equals(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=10, currency=currency_usd) - other_usd_10, created = get_or_create(self.session, Money, amount=10, currency=currency_usd) + usd_10 = Money(amount=10, currency=currency_usd) + other_usd_10 = Money(amount=10, currency=currency_usd) self.assertTrue(other_usd_10 == usd_10) def test_repr(self): @@ -80,8 +90,8 @@ def test_unicode(self): def test_add_money(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - usd_20, created = get_or_create(self.session, Money, amount=Decimal(20), currency=currency_usd) + usd_10 = Money(amount=Decimal(10), currency=currency_usd) + usd_20 = Money(amount=Decimal(20), currency=currency_usd) usd_30 = usd_10 + usd_20 @@ -91,8 +101,8 @@ def test_add_money(self): def test_sub(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - usd_20, created = get_or_create(self.session, Money, amount=Decimal(20), currency=currency_usd) + usd_10 = Money(amount=Decimal(10), currency=currency_usd) + usd_20 = Money(amount=Decimal(20), currency=currency_usd) usd_sub = usd_20 - usd_10 @@ -102,9 +112,9 @@ def test_sub(self): def test_less_or_equal(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - other_usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - usd_20, created = get_or_create(self.session, Money, amount=Decimal(20), currency=currency_usd) + usd_10 = Money(amount=Decimal(10), currency=currency_usd) + other_usd_10 = Money(amount=Decimal(10), currency=currency_usd) + usd_20 = Money(amount=Decimal(20), currency=currency_usd) self.assertTrue(usd_10 <= usd_20) self.assertTrue(usd_10 <= other_usd_10) @@ -112,9 +122,9 @@ def test_less_or_equal(self): def test_great_or_equal(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - other_usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - usd_20, created = get_or_create(self.session, Money, amount=Decimal(20), currency=currency_usd) + usd_10 = Money(amount=Decimal(10), currency=currency_usd) + other_usd_10 = Money(amount=Decimal(10), currency=currency_usd) + usd_20 = Money(amount=Decimal(20), currency=currency_usd) self.assertTrue(usd_20 >= usd_10) self.assertTrue(usd_20 >= other_usd_10) @@ -122,8 +132,8 @@ def test_great_or_equal(self): def test_not_equal_by_amount(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') - usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - usd_20, created = get_or_create(self.session, Money, amount=Decimal(20), currency=currency_usd) + usd_10 = Money(amount=Decimal(10), currency=currency_usd) + usd_20 = Money(amount=Decimal(20), currency=currency_usd) self.assertTrue(usd_10 != usd_20) @@ -131,8 +141,8 @@ def test_not_equal_by_currency(self): currency_usd, created = get_or_create(self.session, Currency, name='Dollar', code='USD') currency_ar, created = get_or_create(self.session, Currency, name='Peso', code='ARG') - usd_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_usd) - ar_10, created = get_or_create(self.session, Money, amount=Decimal(10), currency=currency_ar) + usd_10 = Money(amount=Decimal(10), currency=currency_usd) + ar_10 = Money(amount=Decimal(10), currency=currency_ar) self.assertTrue(usd_10 != ar_10) diff --git a/tests/test_order.py b/tests/test_order.py index de2a586..295a5d7 100644 --- a/tests/test_order.py +++ b/tests/test_order.py @@ -4,12 +4,12 @@ SecurityQuote, BuyOrder, SellOrder, - Owner, Exchange, FillOrderStage, CancelOrderStage, ) from pyStock.models.account import ( + Owner, Account, Broker, )