def test_only_uses_three_day_forecast(muddy_forecast_service, dark_sky_api):
    dark_sky_api.get_daily_forecasts.return_value = \
        [Forecast(30, 'rain'), Forecast(30, 'snow'), Forecast(30, None), Forecast(40, 'rain')]

    assert muddy_forecast_service.is_three_day_forecast_muddy() is False

    dark_sky_api.get_daily_forecasts.assert_called_once()
def test_returns_true_for_a_muddy_forecast(muddy_forecast_service,
                                           dark_sky_api):
    dark_sky_api.get_daily_forecasts.return_value = [
        Forecast(40, 'rain'),
        Forecast(30, 'snow'),
        Forecast(30, None)
    ]

    assert muddy_forecast_service.is_three_day_forecast_muddy() is True

    dark_sky_api.get_daily_forecasts.assert_called_once()
示例#3
0
    def get_daily_forecasts(self, latitude: float,
                            longitude: float) -> List[Forecast]:
        """
        Gets daily weather forecasts for the next week.
        :param latitude: Latitude (positive or negative) to retrieve forecasts for.
        :param longitude: Longitude (positive or negative) to retrieve forecasts for.
        :return: Weather forecasts for the next week.
        """
        response = requests.get(
            f'https://api.darksky.net/forecast/{self._api_key}/{latitude},{longitude}'
        )

        if response.status_code != 200:
            raise Exception(response.text)

        json = response.json()
        daily_forecasts = json['daily']['data']

        return [
            Forecast(forecast.get('temperatureMax'),
                     forecast.get('precipType'))
            for forecast in daily_forecasts
        ]
示例#4
0
def test_is_not_muddy_with_no_rain_above_freezing():
    assert Forecast(40, None).is_muddy() is False
示例#5
0
def test_is_muddy_with_rain_above_freezing():
    assert Forecast(40, 'rain').is_muddy() is True
示例#6
0
def test_is_not_muddy_with_other_precip_type():
    assert Forecast(30, 'snow').is_muddy() is False
示例#7
0
def test_is_not_muddy_with_no_rain_below_freezing():
    assert Forecast(30, None).is_muddy() is False