1#!/usr/bin/env python 2# 3# Copyright (c) 2013,2016 Corey Goldberg (cgoldberg@gmail.com) 4# 5# license: GNU LGPL 6# 7# This library is free software; you can redistribute it and/or 8# modify it under the terms of the GNU Lesser General Public 9# License as published by the Free Software Foundation; either 10# version 2.1 of the License, or (at your option) any later version. 11# 12# Requires: Python 2.7/3.3+ 13 14 15import unittest 16 17import ystockquote 18 19 20class YStockQuoteTestCase(unittest.TestCase): 21 22 def test_get_all(self): 23 symbol = 'GOOG' 24 all_info = ystockquote.get_all(symbol) 25 self.assertIsInstance(all_info, dict) 26 pc = all_info['previous_close'] 27 self.assertNotEqual(pc, 'N/A') 28 self.assertGreater(float(pc), 0) 29 30 def test_get_historical_prices(self): 31 symbol = 'GOOG' 32 start_date = '2013-01-02' 33 end_date = '2013-01-15' 34 prices = ystockquote.get_historical_prices( 35 symbol, start_date, end_date) 36 self.assertIsInstance(prices, dict) 37 self.assertEqual(len(prices), 10) 38 self.assertEqual(sorted(prices.keys())[0], '2013-01-02') 39 self.assertEqual(sorted(prices.keys())[-1], end_date) 40 self.assertGreater(float(prices[start_date]['Open']), 0.0) 41 self.assertGreater(float(prices[start_date]['High']), 0.0) 42 self.assertGreater(float(prices[start_date]['Low']), 0.0) 43 self.assertGreater(float(prices[start_date]['Close']), 0.0) 44 self.assertGreater(float(prices[start_date]['Volume']), 0.0) 45 self.assertGreater(float(prices[start_date]['Adj Close']), 0.0) 46 self.assertGreater(float(prices[end_date]['Open']), 0.0) 47 self.assertGreater(float(prices[end_date]['High']), 0.0) 48 self.assertGreater(float(prices[end_date]['Low']), 0.0) 49 self.assertGreater(float(prices[end_date]['Close']), 0.0) 50 self.assertGreater(float(prices[end_date]['Volume']), 0.0) 51 self.assertGreater(float(prices[end_date]['Adj Close']), 0.0) 52 53 54if __name__ == '__main__': 55 unittest.main() 56