Esempio n. 1
0
 def test_api_limit_when_less_than_10min(self):
     '''
     A Weather object with last call time less than 10 mins should return
     False
     '''
     w = Weather(datetime.datetime.now())
     self.assertFalse(w.check_if_within_limit())
Esempio n. 2
0
 def test_api_limit_when_greater_than_10min(self):
     '''
     A Weather object with last call time greater than 10 mins should return
     True
     '''
     w = Weather(datetime.datetime(1970, 1, 1))
     self.assertTrue(w.check_if_within_limit())
Esempio n. 3
0
class TestWeatherCityList(unittest.TestCase):
    def setUp(self):
        self.w = Weather()

    def test_get_id_by_city_name_where_name_is_included(self):
        city = self.w.get_city_id_by_name('Atlanta')
        self.assertEqual(city, 4180439)

    def test_get_id_by_city_name_where_name_isnot_included(self):
        city = self.w.get_city_id_by_name('ZZZZZ')
        self.assertEqual(city, None)
Esempio n. 4
0
def get_weather(city_name, forecast=None, indent=2, show_json=False, dt=None):
    '''Makes a Weather object'''
    w = Weather(dt)

    cur_city = w.get_the_weather(city_name, forecast)

    visual_space = ' ' * indent
    if forecast:
        display_forecast_weather(cur_city, visual_space, show_json)
    else:
        display_current_weather(cur_city, visual_space, show_json)
Esempio n. 5
0
 def test_unsuccessful_request_to_api(self, mock_request):
     '''
     A Weather object whose last call time should not be able to make an
     api request
     '''
     w = Weather(datetime.datetime.now())
     w.WeatherData = False
     id = 1
     # api_key = w.api_key
     w.request_weather_with_id(id)
     # http = 'http://api.openweathermap.org/data/2.5/weather?id=1&APPID='
     # arg = f'{http}{api_key}'
     self.assertFalse(w.WeatherData)
Esempio n. 6
0
 def test_successful_request_to_api(self, mock_request, mock_store):
     '''
     A Weather object whose last call time is greater than the rate limit
     should be able to make an api call
     '''
     w = Weather(datetime.datetime(1970, 1, 1))
     id = 1
     api_key = w.api_key
     w.request_weather_with_id(id)
     http = 'http://api.openweathermap.org/data/2.5/weather?id=1&APPID='
     arg = f'{http}{api_key}'
     assert mock_request.called_with(arg)
     self.assertTrue(w.wthr_data_dict)
Esempio n. 7
0
 def setUp(self):
     self.w = Weather()
Esempio n. 8
0
 def test_unsuccessful_weather_request_with_id(self):
     w = Weather(datetime.datetime.now())
     with self.assertRaises(KeyError):
         w.get_the_weather('zzzzzz')
Esempio n. 9
0
 def test_weather_has_api_rate_limit_of_timedetla(self):
     w = Weather()
     self.assertTrue(isinstance(w.api_limit, datetime.timedelta))
Esempio n. 10
0
 def test_weather_has_last_call_time_of_datetime(self):
     w = Weather()
     self.assertTrue(isinstance(w.last_call_time, datetime.datetime))
Esempio n. 11
0
 def test_weather_has_city_list(self):
     w = Weather()
     self.assertTrue(w.city_list)
Esempio n. 12
0
 def test_weather_has_API(self):
     w = Weather()
     self.assertTrue(w.api_key)
Esempio n. 13
0
 def test_make_weather_object(self):
     w = Weather()
     self.assertTrue(isinstance(w, Weather))