1+ import datetime
12import os
23from types import *
34from nose .tools import *
@@ -13,3 +14,91 @@ def test_site(self):
1314 site = self .manager .get_nearest_site (- 0.124626 , 51.500728 )
1415 assert site .name == 'London'
1516
17+ def test_get_all_sites (self ):
18+ sites = self .manager .get_all_sites ()
19+ assert isinstance (sites , list )
20+ assert sites
21+
22+ def test_get_daily_forecast (self ):
23+ site = self .manager .get_nearest_site (- 0.124626 , 51.500728 )
24+ forecast = self .manager .get_forecast_for_site (site .id , 'daily' )
25+ assert isinstance (forecast , datapoint .Forecast .Forecast )
26+ assert forecast .continent .upper () == 'EUROPE'
27+ assert forecast .country .upper () == 'ENGLAND'
28+ assert forecast .name .upper () == 'LONDON'
29+ assert abs (float (forecast .longitude ) - (- 0.124626 )) < 0.1
30+ assert abs (float (forecast .latitude ) - 51.500728 ) < 0.1
31+ # Forecast should have been made within last 3 hours
32+ tz = forecast .data_date .tzinfo
33+ assert (forecast .data_date
34+ - datetime .datetime .now (tz = tz ) < datetime .timedelta (hours = 3 ))
35+ # First forecast should be less than 12 hours away
36+ tz = forecast .days [0 ].timesteps [0 ].date .tzinfo
37+ assert (forecast .days [0 ].timesteps [0 ].date -
38+ datetime .datetime .now (tz = tz ) < datetime .timedelta (hours = 12 ))
39+ for day in forecast .days :
40+ for timestep in day .timesteps :
41+ assert timestep .name in ['Day' , 'Night' ]
42+ assert self .manager ._weather_to_text (
43+ int (timestep .weather .value )) == timestep .weather .text
44+ assert - 100 < timestep .temperature .value < 100
45+ assert timestep .temperature .units == 'C'
46+ assert - 100 < timestep .feels_like_temperature .value < 100
47+ assert timestep .feels_like_temperature .units == 'C'
48+ assert 0 <= timestep .wind_speed .value < 300
49+ assert timestep .wind_speed .units == 'mph'
50+ for char in timestep .wind_direction .value :
51+ assert char in ['N' , 'E' , 'S' , 'W' ]
52+ assert timestep .wind_direction .units == 'compass'
53+ assert 0 <= timestep .wind_gust .value < 300
54+ assert timestep .wind_gust .units == 'mph'
55+ assert (timestep .visibility .value in
56+ ['UN' , 'VP' , 'PO' , 'MO' , 'GO' , 'VG' , 'EX' ])
57+ assert 0 <= timestep .precipitation .value <= 100
58+ assert timestep .precipitation .units == '%'
59+ assert 0 <= timestep .humidity .value <= 100
60+ assert timestep .humidity .units == '%'
61+ if hasattr (timestep .uv , 'value' ):
62+ assert 0 < int (timestep .uv .value ) < 20
63+
64+ def test_get_3hour_forecast (self ):
65+ site = self .manager .get_nearest_site (- 0.124626 , 51.500728 )
66+ forecast = self .manager .get_forecast_for_site (site .id , '3hourly' )
67+ assert isinstance (forecast , datapoint .Forecast .Forecast )
68+ assert forecast .continent .upper () == 'EUROPE'
69+ assert forecast .country .upper () == 'ENGLAND'
70+ assert forecast .name .upper () == 'LONDON'
71+ assert abs (float (forecast .longitude ) - (- 0.124626 )) < 0.1
72+ assert abs (float (forecast .latitude ) - 51.500728 ) < 0.1
73+ # Forecast should have been made within last 3 hours
74+ tz = forecast .data_date .tzinfo
75+ assert (forecast .data_date
76+ - datetime .datetime .now (tz = tz ) < datetime .timedelta (hours = 3 ))
77+ # First forecast should be less than 12 hours away
78+ tz = forecast .days [0 ].timesteps [0 ].date .tzinfo
79+ assert (forecast .days [0 ].timesteps [0 ].date -
80+ datetime .datetime .now (tz = tz ) < datetime .timedelta (hours = 3 ))
81+ for day in forecast .days :
82+ for timestep in day .timesteps :
83+ assert isinstance (timestep .name , int )
84+ assert self .manager ._weather_to_text (
85+ int (timestep .weather .value )) == timestep .weather .text
86+ assert - 100 < timestep .temperature .value < 100
87+ assert timestep .temperature .units == 'C'
88+ assert - 100 < timestep .feels_like_temperature .value < 100
89+ assert timestep .feels_like_temperature .units == 'C'
90+ assert 0 <= timestep .wind_speed .value < 300
91+ assert timestep .wind_speed .units == 'mph'
92+ for char in timestep .wind_direction .value :
93+ assert char in ['N' , 'E' , 'S' , 'W' ]
94+ assert timestep .wind_direction .units == 'compass'
95+ assert 0 <= timestep .wind_gust .value < 300
96+ assert timestep .wind_gust .units == 'mph'
97+ assert (timestep .visibility .value in
98+ ['UN' , 'VP' , 'PO' , 'MO' , 'GO' , 'VG' , 'EX' ])
99+ assert 0 <= timestep .precipitation .value <= 100
100+ assert timestep .precipitation .units == '%'
101+ assert 0 <= timestep .humidity .value <= 100
102+ assert timestep .humidity .units == '%'
103+ if hasattr (timestep .uv , 'value' ):
104+ assert 0 <= int (timestep .uv .value ) < 20
0 commit comments