def test_get_financial_data__keystats(self): class MockResponse(object): """ HTTP response from accessing the API URL """ def json(self): return { "query": { "count": 2, "created": "2014-05-02T14:16:42Z", "lang": "en-US", "results": { "stats": [ {"symbol": "C6L.SI"}, {"symbol": "ZZZ.SI"} ] } } } with patch("fa.miner.yahoo._construct_yql", MagicMock(return_value="yql")) as mock_construct_yql, \ patch("fa.miner.yahoo.requests.get", MagicMock(return_value=MockResponse())): result = yahoo.get_financial_data(("C6L", "ZZZ"), "quarterly", "keystats") mock_construct_yql.assert_called_once_with(("C6L", "ZZZ"), "yahoo.finance.keystats", None) self.assertEqual(result, {"C6L": {"symbol": "C6L.SI"}, "ZZZ": {"symbol": "ZZZ.SI"}})
def test_get_financial_data(self): class MockResponse(object): """ HTTP response from accessing the API URL """ def json(self): return { "query": { "count": 2, "created": "2014-05-02T14:09:49Z", "lang": "en-US", "results": { "balancesheet": [ {"symbol": "C6L.SI"}, {"symbol": "ZZZ.SI"} ] } } } with patch("fa.miner.yahoo._construct_yql", MagicMock(return_value="yql")) as mock_construct_yql, \ patch("fa.miner.yahoo.requests.get", MagicMock(return_value=MockResponse())) as mock_get: result = yahoo.get_financial_data(("C6L", "ZZZ"), "annual", "balancesheet") mock_construct_yql.assert_called_once_with(("C6L", "ZZZ"), "yahoo.finance.balancesheet", "annual") mock_get.assert_called_once_with(yahoo.YQL_API_URL, params={ "q": "yql", "format": "json", "env": "store://datatables.org/alltableswithkeys", }) self.assertEqual(result, {"C6L": {"symbol": "C6L.SI"}, "ZZZ": {"symbol": "ZZZ.SI"}})
def test_get_financial_data__single_symbol(self): class MockResponse(object): """ HTTP response from accessing the API URL """ def json(self): return { "query": { "count": 1, "created": "2014-05-02T14:29:42Z", "lang": "en-US", "results": { "balancesheet": {"symbol": "C6L.SI"} } } } with patch("fa.miner.yahoo._construct_yql", MagicMock(return_value="yql")), \ patch("fa.miner.yahoo.requests.get", MagicMock(return_value=MockResponse())): result = yahoo.get_financial_data(("C6L",), "annual", "balancesheet") self.assertEqual(result, {"C6L": {"symbol": "C6L.SI"}})