def test_yahoo_keystats_success200(self, mockget): mockget.return_value = ResponseStatus200(self.yahoo_finance_html_path, 'aci') screen = StockScreen(100) expected_screen_output = "price to book ratio: aci, 0.05\nPEG ration: aci -0.01\n" output = screen.yahooKeyStats('aci') self.assertEqual(expected_screen_output, output)
def test_yahoo_keystats_fail500(self, mockget): mockget.return_value = ResponseStatus500() screen = StockScreen(100) test = False try: screen.yahooKeyStats('aa') except HTTPError: test = True self.assertEqual(test, True)
def test_screen_parse_underfilter_by_3_(self): ''' verify that a certain number does not filter correctly when our target is over the filter ''' # ARRANGE test_stock = 'a' screen = StockScreen(3.0) yahoo_finance_html = open(self.yahoo_finance_html_path%test_stock,"r").read() # ACT screen_output = screen._parse(test_stock,yahoo_finance_html) # ASSERT self.assertEqual(screen_output, "")
def test_screen_parse_underfilter_by_3_(self): ''' verify that a certain number does not filter correctly when our target is over the filter ''' # ARRANGE test_stock = 'a' screen = StockScreen(3.0) yahoo_finance_html = open(self.yahoo_finance_html_path % test_stock, "r").read() # ACT screen_output = screen._parse(test_stock, yahoo_finance_html) # ASSERT self.assertEqual(screen_output, "")
def test_screen_parse_filter_by_5(self): ''' verify that a certain number filters and stock returns the results from out static html :return: ''' # ARRANGE test_stock = 'aci' screen = StockScreen(5) yahoo_finance_html = open(self.yahoo_finance_html_path%test_stock,"r").read() expected_screen_output = "price to book ratio: aci, 0.05\nPEG ration: aci -0.01\n" # ACT screen_output = screen._parse(test_stock,yahoo_finance_html) print screen_output # ASSERT self.assertEqual(expected_screen_output,screen_output)
def test_screen_parse_filter_by_100_all_test_sps(self): ''' pick a number filter that is really big and make sure that all our test indexes return a value from their respective html files that is not an empty string :return: ''' # ARRANGE screen = StockScreen(100) for test_stock in self.sp500_test_set: yahoo_finance_html = open(self.yahoo_finance_html_path%test_stock,"r").read() # ACT screen_output = screen._parse(test_stock,yahoo_finance_html) # ASSERT self.assertTrue(screen_output)
def test_screen_parse_filter_by_5(self): ''' verify that a certain number filters and stock returns the results from out static html :return: ''' # ARRANGE test_stock = 'aci' screen = StockScreen(5) yahoo_finance_html = open(self.yahoo_finance_html_path % test_stock, "r").read() expected_screen_output = "price to book ratio: aci, 0.05\nPEG ration: aci -0.01\n" # ACT screen_output = screen._parse(test_stock, yahoo_finance_html) print screen_output # ASSERT self.assertEqual(expected_screen_output, screen_output)
def test_screen_parse_filter_by_100_all_test_sps(self): ''' pick a number filter that is really big and make sure that all our test indexes return a value from their respective html files that is not an empty string :return: ''' # ARRANGE screen = StockScreen(100) for test_stock in self.sp500_test_set: yahoo_finance_html = open( self.yahoo_finance_html_path % test_stock, "r").read() # ACT screen_output = screen._parse(test_stock, yahoo_finance_html) # ASSERT self.assertTrue(screen_output)
def test_yahoo_keystats_fail400(self, mockget): mockget.return_value = ResponseStatus400() screen = StockScreen(100) self.assertRaises(HTTPError, screen.yahooKeyStats, *('aa', ))