Пример #1
0
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)
Пример #2
0
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
Пример #3
0
    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")
Пример #4
0
 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")
Пример #5
0
 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")
Пример #6
0
 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")
Пример #7
0
 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")
Пример #8
0
def api_news():
    return jsonify(api_calls.get_news(utils.getTodayString()))
Пример #9
0
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