def api_news(date): response = api_calls.get_news(date) """if type(response[0]) is int: if response[0][0] == 0: response = "Please give a valid date." elif response[0][0] == 2: response = "No articles about the date specified.""" return jsonify(response)
def get_api(date): api = {"favorites": favorites, "news" : api_calls.get_news(date), "apod" : api_calls.get_nasa_apod(date), "nasa-news": api_calls.get_nasa_news(date) # add more if necessary } return api
def test_output_format_news(self): date = "2020-05-25" response = api_calls.get_news(date) articleFileds = [ "author", "content", "description", "publishedAt", "source", "title", "url", "urlToImage" ] result = True for (keys, fields) in zip(response[0], articleFileds): if not keys in articleFileds: result = False if not fields in response[0]: result = False self.assertTrue(result, "wrong format")
def test_forward_date_news(self): date = "2022-07-17" response = api_calls.get_news(date) self.assertEqual(response[0], "Please give a valid date2.", "Late date control failed")
def test_recent_date_news(self): date = "2020-04-24" response = api_calls.get_news(date) self.assertEqual(response[0], "Please give a valid date1.", "Early day control failed")
def test_input_format_news(self): date = "1234567890" response = api_calls.get_news(date) self.assertEqual(response[0], "Wrong input format", "Input format test failed")
def test_early_date_news(self): date = "2019-03-17" response = api_calls.get_news(date) self.assertEqual(response[0], "Please give a valid date1.", "Early date control failed")
def api_news(): return jsonify(api_calls.get_news(utils.getTodayString()))
def get_api(date): api = {"favorites": favorites} api["news"] = api_calls.get_news(date) api["apod"] = api_calls.get_nasa_apod(date) # add more if necessary return api