Skip to content

Commit

Permalink
Reached full testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinali1 committed Jun 2, 2016
1 parent 12dc034 commit e921379
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion forex/models.py
Expand Up @@ -61,7 +61,7 @@ def compute_return(self, start_date, end_date, rate="MID"):
Compute the return of the currency between two dates
"""
if rate not in ["MID", "ASK", "BID"]:
raise ValueError("Unknown rate type - must be 'MID', 'ASK' or 'BID'")
raise ValueError("Unknown rate type (%s)- must be 'MID', 'ASK' or 'BID'" % str(rate))

if end_date <= start_date:
raise ValueError("End date must be on or after start date")
Expand Down
34 changes: 22 additions & 12 deletions forex/tests/models_tests.py
Expand Up @@ -195,6 +195,14 @@ def setUp(self):
CurrencyPrice.objects.create(currency=test_curr2, date=date(2015, 2, 1), ask_price=10, bid_price=9)
CurrencyPrice.objects.create(currency=test_curr2, date=date(2015, 2, 15), ask_price=11, bid_price=7)

def test_correct_rate_input(self):
self.assertRaisesMessage(ValueError,
"Incorrect price_type (*BAD*) must be on of 'ask', 'bid' or 'mid'",
CurrencyPrice.objects.generate_dataframe,
symbols=None,
date_index=None,
price_type="*BAD*")

def test_no_symbols_no_dates(self):
df = CurrencyPrice.objects.generate_dataframe(symbols=None, date_index=None)
self.assertEqual(set(df.columns), set(["TEST1", "TEST2", "TEST3"]))
Expand Down Expand Up @@ -242,19 +250,21 @@ def setUp(self):

def test_bad_input_rate(self):
test_curr1 = Currency.objects.get(symbol="TEST1")
try:
test_curr1.compute_return(start_date=date(2015, 1, 2), end_date=date(2015, 1, 5), rate="*BAD*")
raise AssertionError("Bad input should fail")
except ValueError:
pass

def bad_input_dates(self):
self.assertRaisesMessage(ValueError,
"Unknown rate type (*BAD*)- must be 'MID', 'ASK' or 'BID'",
test_curr1.compute_return,
date(2015, 1, 2),
date(2015, 1, 5),
rate="*BAD*")

def test_bad_input_dates(self):
test_curr1 = Currency.objects.get(symbol="TEST1")
try:
test_curr1.compute_return(start_date=date(2015, 1, 10), end_date=date(2015, 1, 5), rate="*BAD*")
raise AssertionError("Bad input should fail")
except ValueError:
pass
self.assertRaisesMessage(ValueError,
"End date must be on or after start date",
test_curr1.compute_return,
date(2015, 1, 10),
date(2015, 1, 5),
rate="MID")

def test_computation(self):
test_curr1 = Currency.objects.get(symbol="TEST1")
Expand Down

0 comments on commit e921379

Please sign in to comment.