diff --git a/isthisstockgood/DataFetcher.py b/isthisstockgood/DataFetcher.py index 3b2b1ad..e7caa7f 100644 --- a/isthisstockgood/DataFetcher.py +++ b/isthisstockgood/DataFetcher.py @@ -71,7 +71,7 @@ def fetchDataForTickerSymbol(ticker): 'cash': msn_money.free_cash_flow_growth_rates if msn_money and msn_money.free_cash_flow_growth_rates else [], 'total_debt' : msn_money.total_debt, 'free_cash_flow' : computed_free_cash_flow, - 'ten_cap_price' : ten_cap_price, + 'ten_cap_price' : round(ten_cap_price, 2), 'debt_payoff_time' : round(float(msn_money.total_debt) / computed_free_cash_flow), 'debt_equity_ratio' : msn_money.debt_equity_ratio if msn_money and msn_money.debt_equity_ratio >= 0 else -1, 'margin_of_safety_price' : margin_of_safety_price if margin_of_safety_price else 'null', diff --git a/tests/test_api.py b/tests/test_api.py index 36b289f..c5c6c14 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -18,11 +18,12 @@ def test_get_data(): with app.test_client() as test_client: test_client = app.test_client() + res = test_client.get('/api/ticker/nvda') - data = res.text - assert json.loads(data)['debt_payoff_time'] >= 0 assert res.status_code == 200 + assert res.json['debt_payoff_time'] >= 0 + def test_get_ten_cap_price(): app = create_app(fetchDataForTickerSymbol) @@ -30,3 +31,14 @@ def test_get_ten_cap_price(): test_client = app.test_client() res = test_client.get('/api/ticker/nvda') assert res.json['ten_cap_price'] > 0 + +def test_ten_cap_price_has_two_places_precision(): + app = create_app(fetchDataForTickerSymbol) + + with app.test_client() as test_client: + test_client = app.test_client() + res = test_client.get('/api/ticker/nvda') + + price = res.json['ten_cap_price'] + + assert round(price, 2) == price