def test_get_forecast_weather_data(requests_mock): temp_date = datetime.datetime.now() + datetime.timedelta(days=2) response_from_mock = RESPONSE_FROM_MOCK response_from_mock["locations"]["Tel Aviv"]["values"][0]["datetimeStr"] =\ temp_date.isoformat() requests_mock.get(FORECAST_URL, json=response_from_mock) output = get_weather_data(temp_date, "tel aviv") assert output['Status'] == 0
def test_forecast_exception_from_api(): requested_date = datetime.datetime.now() + datetime.timedelta(days=3) with pytest.raises(requests.exceptions.ConnectionError): requests.get(FORECAST_URL) output = get_weather_data(requested_date, "neo") assert output['Status'] == -1
def test_historical_exception_from_api(): requested_date = datetime.datetime(day=12, month=1, year=2020) with pytest.raises(requests.exceptions.ConnectionError): requests.get(HISTORY_URL) output = get_weather_data(requested_date, "neo") assert output['Status'] == -1
def test_historical_no_response_from_api(): requested_date = datetime.datetime(day=11, month=1, year=2020) responses.add(responses.GET, HISTORY_URL, status=500) requests.get(HISTORY_URL) output = get_weather_data(requested_date, "neo") assert output['Status'] == -1
def test_location_not_found(requests_mock): requested_date = datetime.datetime(day=10, month=1, year=2020) requests_mock.get(HISTORY_URL, json=ERROR_RESPONSE_FROM_MOCK) output = get_weather_data(requested_date, "neo") assert output['Status'] == -1
def test_get_weather_data(requested_date, location, expected, requests_mock): requests_mock.get(HISTORY_URL, json=RESPONSE_FROM_MOCK) output = get_weather_data(requested_date, location) assert output['Status'] == expected