Пример #1
0
    def test_nowcast_valid_end_time(self, mock_get):
        client = Client('apikey')
        lat = 52.446023244274045
        lon = 4.819207798979252
        timestep = 30
        fields = [FIELD_TEMP]
        start_time = 'now'
        end_time = '2021-01-14T21:00:00.000Z'

        response = client.nowcast(lat=lat,
                                  lon=lon,
                                  fields=fields,
                                  timestep=timestep,
                                  start_time=start_time,
                                  end_time=end_time)

        self.assertFalse(response.has_error)

        expected_params = {
            'lat': 52.446023244274045,
            'lon': 4.819207798979252,
            'timestep': 30,
            'start_time': 'now',
            'unit_system': 'si',
            'fields': join_fields(fields),
            'end_time': end_time
        }

        mock_get.assert_called_with(
            'https://api.climacell.co/v3/weather/nowcast',
            params=expected_params,
            headers={'apikey': 'apikey'})
Пример #2
0
    def test_hourly_valid_end_time(self, mock_get):
        client = Client('apikey')
        lat = 52.446023244274045
        lon = 4.819207798979252
        fields = [FIELD_TEMP, FIELD_DEW_POINT, FIELD_HUMIDITY]
        start_time = 'now'
        end_time = '2021-01-14T21:00:00.000Z'

        response = client.hourly(lat, lon, fields, start_time, end_time)
        self.assertFalse(response.has_error)

        expected_params = {
            'lat': 52.446023244274045,
            'lon': 4.819207798979252,
            'start_time': 'now',
            'unit_system': 'si',
            'fields':
            join_fields([FIELD_TEMP, FIELD_DEW_POINT, FIELD_HUMIDITY]),
            'end_time': '2021-01-14T21:00:00.000Z',
        }

        mock_get.assert_called_with(
            'https://api.climacell.co/v3/weather/forecast/hourly',
            params=expected_params,
            headers={'apikey': 'apikey'})
Пример #3
0
    def test_hourly_invalid_start_time(self):
        client = Client('apikey')
        lat = 52.446023244274045
        lon = 4.819207798979252
        fields = [FIELD_TEMP, FIELD_DEW_POINT, FIELD_HUMIDITY]
        start_time = 'yesterday'

        self.assertRaises(ValueError, client.hourly, lat, lon, fields,
                          start_time)
Пример #4
0
    def test_nowcast_invalid_start_time(self):
        client = Client('apikey')
        lat = 52.446023244274045
        lon = 4.819207798979252
        timestep = 30
        fields = [FIELD_TEMP]
        start_time = 'yesterday'

        self.assertRaises(ValueError, client.nowcast, lat, lon, fields,
                          timestep, start_time)
Пример #5
0
    def test_nowcast(self, mock_get):
        client = Client('apikey')
        lat = 52.446023244274045
        lon = 4.819207798979252
        timestep = 30
        fields = [
            FIELD_TEMP,
            FIELD_DEW_POINT,
            FIELD_HUMIDITY,
            FIELD_WIND_SPEED,
            FIELD_WIND_GUST,
            FIELD_WIND_DIRECTION,
            FIELD_SUNRISE,
            FIELD_SUNSET,
        ]

        response = client.nowcast(lat=lat,
                                  lon=lon,
                                  fields=fields,
                                  timestep=timestep)
        measurements = response.get_measurements()

        expected_params = {
            'lat': 52.446023244274045,
            'lon': 4.819207798979252,
            'timestep': 30,
            'start_time': 'now',
            'unit_system': 'si',
            'fields': join_fields(fields),
        }

        mock_get.assert_called_with(
            'https://api.climacell.co/v3/weather/nowcast',
            params=expected_params,
            headers={'apikey': 'apikey'})
        # 13 timesteps, 8 measurements per timestep
        self.assertEqual(13 * 8, len(measurements))
Пример #6
0
    def test_hourly(self, mock_get):
        client = Client('apikey')
        lat = 52.446023244274045
        lon = 4.819207798979252
        fields = [FIELD_TEMP, FIELD_DEW_POINT, FIELD_HUMIDITY]

        response = client.hourly(lat=lat, lon=lon, fields=fields)
        measurements = response.get_measurements()

        expected_params = {
            'lat': 52.446023244274045,
            'lon': 4.819207798979252,
            'start_time': 'now',
            'unit_system': 'si',
            'fields':
            join_fields([FIELD_TEMP, FIELD_DEW_POINT, FIELD_HUMIDITY]),
        }

        mock_get.assert_called_with(
            'https://api.climacell.co/v3/weather/forecast/hourly',
            params=expected_params,
            headers={'apikey': 'apikey'})

        self.assertEqual(6, len(measurements))