def test_main_null_ticker(self): request = TestRequest({ 'tickers': None, }) 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)) self.assertTrue(return_value_from_main[1], 400) self.assertTrue('error' in json.loads(return_value_from_main[0]))
def test_main_invalid_time_since(self): request = TestRequest({ 'tickers': ['SPY'], 'time_since': 'gibberish', }) 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)) self.assertTrue(return_value_from_main[1], 400) self.assertTrue('error' in json.loads(return_value_from_main[0]))
def test_main_simple(self): request = TestRequest({ 'tickers': 'SPY', }) 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)
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)