def test_historical_data_7_and_5d(self): requested_tickers = ['SPY'] first = server_function.get_time_since_stock_data( requested_tickers, int((datetime.now(tz=server_function.EST5EDT()).replace( hour=16, minute=0, second=0, microsecond=0) - timedelta(days=7)).timestamp()))[0] second = server_function.get_time_since_stock_data( requested_tickers, '5d')[0] self.assertTrue( len(first) == len(requested_tickers) and are_all_fields_in_return_stock_data(first)) self.assertTrue( len(second) == len(requested_tickers) and are_all_fields_in_return_stock_data(second))
def test_historical_data_ytd(self): """""" requested_tickers = ['SPY'] first = server_function.get_time_since_stock_data( requested_tickers, int((datetime.now(tz=server_function.EST5EDT()).replace( month=1, day=1, hour=16, minute=0, second=0, microsecond=0)).timestamp()))[0] second = server_function.get_time_since_stock_data( requested_tickers, 'ytd')[0] self.assertTrue( len(first) == len(requested_tickers) and are_all_fields_in_return_stock_data(first), ) self.assertTrue( len(second) == len(requested_tickers) and are_all_fields_in_return_stock_data(second), )
def test_main_time_since_1(self): request = TestRequest({ 'tickers': ['SPY'], 'time_since': int((datetime.now(tz=server_function.EST5EDT()).replace( hour=16, minute=0, second=0, microsecond=0) - timedelta(days=1)).timestamp()), }) return_value_from_main = server_function.main(request) self.assertTrue(len(return_value_from_main) > 0) self.assertTrue(isinstance(return_value_from_main[0], str)) body = json.loads(return_value_from_main[0]) self.assertTrue( len(body['stock_data']) == request.get_tickers_length()) self.assertTrue(are_all_fields_in_return_stock_data( body['stock_data'])) self.assertTrue(body['market_time'] is not None)