Skip to content

Commit

Permalink
fix imports and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed Nov 30, 2015
1 parent 4a014db commit 1b276a2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
8 changes: 4 additions & 4 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
FillOrderStage,
BuyOrder,
SellOrder,
Owner,
Exchange,
Security,
Tick,
Expand All @@ -16,6 +15,7 @@
)
from pyStock.models.account import (
Account,
Owner,
Broker,
)
from pyStock.models.money import (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
54 changes: 32 additions & 22 deletions tests/test_money.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
Currency,
Money,
)
from pyStock.models.account import (
Account,
Broker,
Owner
)

from . import DatabaseTest

Expand All @@ -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):
Expand All @@ -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

Expand All @@ -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

Expand All @@ -102,37 +112,37 @@ 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)

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)

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)

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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
SecurityQuote,
BuyOrder,
SellOrder,
Owner,
Exchange,
FillOrderStage,
CancelOrderStage,
)
from pyStock.models.account import (
Owner,
Account,
Broker,
)
Expand Down

0 comments on commit 1b276a2

Please sign in to comment.