Exemplo n.º 1
0
    def get_stock_realtime(stock_symbol):
        try:
            stock_data = api.get_stock_realtime(stock_symbol)

            return json.dumps(stock_data), 200, API_RESPONSE_HEADER
        except ValueError as value_error:
            return server._generate_error_response(value_error), 400, API_RESPONSE_HEADER
        except Exception as exception:
            return server._generate_error_response(exception), 500, API_RESPONSE_HEADER
 def test_get_stock_realtime_happy_case(self):
     test_stock = get_stock_realtime('amzn')
     
     self.assertTrue(test_stock['stock_name'] == 'Amazon.com, Inc.')
     self.assertTrue(_is_float(test_stock['stock_open']))
     self.assertTrue(_is_float(test_stock['stock_price']))
 def test_get_stock_realtime_malformed_stock_symbol(self):
     with self.assertRaises(ValueError):
         get_stock_realtime('!@')
 def test_get_stock_realtime_nonexistant_stock_symbol(self):
     with self.assertRaises(ValueError):
         get_stock_realtime('foo')
 def test_get_stock_realtime_none_stock_symbol(self):
     with self.assertRaises(ValueError):
         get_stock_realtime(None)