Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_daily_forecast(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_daily_forecast
result = self.__test_instance.daily_forecast("London,uk", 2)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, Forecaster))
forecast = result.get_forecast()
self.assertTrue(isinstance(forecast, Forecast))
self.assertTrue(forecast.get_interval() is not None)
self.assertTrue(forecast.get_reception_time() is not None)
self.assertTrue(isinstance(forecast.get_location(), Location))
self.assertEqual(1, len(forecast))
for weather in forecast:
self.assertTrue(isinstance(weather, Weather))
def test_weather_around_coords(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_multiple_obs
result = self.__test_instance.weather_around_coords(57.0, -2.15)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, list))
for item in result:
self.assertTrue(item is not None)
self.assertTrue(item.get_reception_time() is not None)
loc = item.get_location()
self.assertTrue(loc is not None)
self.assertTrue(all(v is not None for v in loc.__dict__.values()))
weat = item.get_weather()
self.assertTrue(weat is not None)
def test_three_hours_forecast_at_coords(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_3h_forecast_at_coords
result = \
self.__test_instance\
.three_hours_forecast_at_coords(51.50853, -0.12574)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, Forecaster))
forecast = result.get_forecast()
self.assertTrue(isinstance(forecast, Forecast))
self.assertTrue(forecast.get_interval() is not None)
self.assertTrue(forecast.get_reception_time() is not None)
self.assertTrue(isinstance(forecast.get_location(), Location))
self.assertEqual(1, len(forecast))
for weather in forecast:
self.assertTrue(isinstance(weather, Weather))
def test_three_hours_forecast_when_forecast_not_found(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_3h_forecast_with_no_items
result = self.__test_instance.three_hours_forecast("London,uk")
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertIsNone(result)
def test_is_API_online(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_ping
result = self.__test_instance.is_API_online()
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(result)
def test_weather_at_id(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_single_obs
result = self.__test_instance.weather_at_id(5128581) # New York city, US
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, Observation))
self.assertTrue(result.get_reception_time() is not None)
loc = result.get_location()
self.assertTrue(loc is not None)
self.assertTrue(all(v is not None for v in loc.__dict__.values()))
weat = result.get_weather()
self.assertTrue(weat is not None)
def test_is_API_online(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_ping
result = self.__test_instance.is_API_online()
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(result)
def test_daily_forecast_at_id(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_daily_forecast_at_id
result = \
self.__test_instance.daily_forecast_at_id(2643743, 2)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, Forecaster))
forecast = result.get_forecast()
self.assertTrue(isinstance(forecast, Forecast))
self.assertTrue(forecast.get_interval() is not None)
self.assertTrue(forecast.get_reception_time() is not None)
self.assertTrue(isinstance(forecast.get_location(), Location))
self.assertEqual(1, len(forecast))
for weather in forecast:
self.assertTrue(isinstance(weather, Weather))
def test_weather_at_station_in_bbox(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_weather_at_stations_in_bbox
results = self.__test_instance\
.weather_at_stations_in_bbox(49.07,8.87,61.26,65.21)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(results, list))
for result in results:
self.assertTrue(isinstance(result, Observation))
self.assertTrue(isinstance(result.get_weather(), Weather))
self.assertTrue(isinstance(result.get_location(), Location))
self.assertTrue(result.get_reception_time() is not None)
def test_station_day_history(self):
ref_to_original_call_API = OWMHTTPClient.call_API
OWMHTTPClient.call_API = \
self.mock_httputils_call_API_returning_station_day_weather_history
result = self.__test_instance.station_day_history(1234, limit=4)
OWMHTTPClient.call_API = ref_to_original_call_API
self.assertTrue(isinstance(result, Historian))
station_history = result.get_station_history()
self.assertTrue(isinstance(station_history, StationHistory))
self.assertTrue(isinstance(station_history.get_measurements(), dict))