@@ -17,48 +17,49 @@ def setUp(self):
1717 open (Path (__file__ ).parent / 'weather_data.json' , 'r' ))
1818 self .lat = 35.640432
1919 self .lon = 139.728833
20+ self .city = 'Tokyo'
2021 event_input = {
2122 'lat' : self .lat ,
2223 'lon' : self .lon ,
23- 'city' : 'Tokyo' ,
24+ 'city' : self . city ,
2425 'access_token' : 'token' ,
2526 'access_token_secret' : 'secret' ,
2627 }
2728 event_template = json .load (
28- open (Path (__file__ ).parent / 'weather_data .json' , 'r' ))
29+ open (Path (__file__ ).parent / 'cloudwatch_event .json' , 'r' ))
2930 self .event = {** event_template , ** event_input }
3031
3132 def testTestEnv (self ):
3233 '''Test that we have proper environment variables setup.'''
3334 self .assertEqual (service .HOT_THRESHOLD , 35 )
34- self .assertEqual (service .DARKSKY_SECRET_KEY , 'darkskysecret ' )
35+ self .assertEqual (service .WEATHER_SECRET_KEY , 'secretkey ' )
3536
3637 def testWeatherGet (self ):
37- '''Test that we can grab data from Darksky and format it.'''
38+ '''Test that we can grab data from weather API and format it.'''
3839 with requests_mock .Mocker () as mock :
3940 mock .get (
40- f"https://api.darksky.net/forecast/ { os .getenv ('DARKSKY_SECRET_KEY ' )} / { self . lat } , { self . lon } ?units=si&exclude=hourly " ,
41+ f"https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/ { self . city } ?unitGroup=metric&key= { os .getenv ('WEATHER_SECRET_KEY ' )} &contentType=json " ,
4142 json = self .weather_data
4243 )
43- weather = service .get_weather (self .lat , self .lon )
44- self .assertEqual (weather .temperatureHigh , 26.4 )
45- self .assertEqual (weather .apparentTemperatureHigh , 28 .0 )
46- self .assertEqual (weather .humidity , 85 )
44+ weather = service .get_weather (self .lat , self .lon , self . city )
45+ self .assertEqual (weather .temperatureHigh , 28.1 )
46+ self .assertEqual (weather .apparentTemperatureHigh , 29 .0 )
47+ self .assertEqual (weather .humidity , 78 )
4748
4849 def testColdMessage (self ):
4950 '''Test message creation when too cold.'''
5051 w = service .Weather ({
51- 'temperatureHigh ' : 23.4 ,
52- 'apparentTemperatureHigh ' : 24.0 ,
52+ 'tempmax ' : 23.4 ,
53+ 'feelslikemax ' : 24.0 ,
5354 'humidity' : 85 ,
5455 })
5556 self .assertEqual (service .generate_message (w , 'Tokyo' ), None )
5657
5758 def testWarmMessage (self ):
5859 '''Test message creation when just warm.'''
5960 w = service .Weather ({
60- 'temperatureHigh ' : 23.4 ,
61- 'apparentTemperatureHigh ' : 29.3 ,
61+ 'tempmax ' : 23.4 ,
62+ 'feelslikemax ' : 29.3 ,
6263 'humidity' : 85 ,
6364 })
6465 message = service .generate_message (w , 'Tokyo' )
@@ -68,8 +69,8 @@ def testWarmMessage(self):
6869 def testHotMessage (self ):
6970 '''Test message creation when it's hot as balls.'''
7071 w = service .Weather ({
71- 'temperatureHigh ' : 35.8 ,
72- 'apparentTemperatureHigh ' : 36.3 ,
72+ 'tempmax ' : 35.8 ,
73+ 'feelslikemax ' : 36.3 ,
7374 'humidity' : 85 ,
7475 })
7576 message = service .generate_message (w , 'Tokyo' )
@@ -80,8 +81,8 @@ def testHotMessage(self):
8081 def testHotFeltMessage (self ):
8182 '''Test message creation when it's hot as balls and apparent temp gap.'''
8283 w = service .Weather ({
83- 'temperatureHigh ' : 29.4 ,
84- 'apparentTemperatureHigh ' : 36.3 ,
84+ 'tempmax ' : 29.4 ,
85+ 'feelslikemax ' : 36.3 ,
8586 'humidity' : 85 ,
8687 })
8788 message = service .generate_message (w , 'Tokyo' )
@@ -94,7 +95,7 @@ def testFullHandler(self, mock_update_status):
9495 '''Test the full handler including twitter.'''
9596 with requests_mock .Mocker () as mock :
9697 mock .get (
97- f"https://api.darksky.net/forecast/ { os .getenv ('DARKSKY_SECRET_KEY ' )} / { self . lat } , { self . lon } ?units=si&exclude=hourly " ,
98+ f"https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/ { self . city } ?unitGroup=metric&key= { os .getenv ('WEATHER_SECRET_KEY ' )} &contentType=json " ,
9899 json = self .weather_data
99100 )
100101 output = service .handler (self .event , None )
0 commit comments