@@ -23,7 +23,7 @@ class TestClient(base.IOTestCase):
2323 # If your IP isn't put on the list of non-throttled IPs, uncomment the
2424 # function below to waste time between tests to prevent throttling.
2525 #def tearDown(self):
26- time .sleep (30.0 )
26+ # time.sleep(30.0)
2727
2828 # Helper Methods
2929 def get_client (self ):
@@ -154,7 +154,7 @@ def test_create_data(self):
154154 data = Data (value = 42 )
155155 result = aio .create_data ('testfeed' , data )
156156 self .assertEqual (int (result .value ), 42 )
157-
157+
158158 def test_location_data (self ):
159159 """receive_location
160160 """
@@ -176,11 +176,41 @@ def test_time_data(self):
176176 """receive_time
177177 """
178178 aio = self .get_client ()
179- time = aio .receive_time ()
179+ server_time = aio .receive_time ()
180180 # Check that each value is rx'd properly
181181 # (should never be None type)
182- for time_data in time :
182+ for time_data in server_time :
183183 self .assertIsNotNone (time_data )
184+ # Check that the week day was interpreted properly
185+ adjusted_time = time .localtime (time .mktime (server_time ))
186+ self .assertEqual (server_time .tm_wday , adjusted_time .tm_wday )
187+
188+ def test_parse_time_struct (self ):
189+ """Ensure the _parse_time_struct method properly handles all 7
190+ week days. Particularly important to make sure Sunday is 6,
191+ not -1"""
192+ # Zero time is a dictionary as would be provided by server
193+ # (wday is one higher than it should be)
194+ zero_time = {'year' : 1970 ,
195+ 'mon' : 1 ,
196+ 'mday' : 1 ,
197+ 'hour' : 0 ,
198+ 'min' : 0 ,
199+ 'sec' : 0 ,
200+ 'wday' : 4 ,
201+ 'yday' : 1 ,
202+ 'isdst' : 0 }
203+
204+ # Create a good struct for each day of the week and make sure
205+ # the server-style dictionary is parsed correctly
206+ for k in range (7 ):
207+ real_struct = time .gmtime (k * 86400 )
208+ d = zero_time .copy ()
209+ d ['mday' ] += k
210+ d ['wday' ] += k
211+ d ['yday' ] += k
212+ newd = Client ._parse_time_struct (d )
213+ self .assertEqual (newd .tm_wday , real_struct .tm_wday )
184214
185215 # Test Feed Functionality
186216 def test_append_by_feed_name (self ):
@@ -286,6 +316,7 @@ def test_receive_group_by_key(self):
286316 response = io .groups (group .key )
287317 self .assertEqual (response .key , 'grouprx' )
288318
319+
289320 # Test Dashboard Functionality
290321 def test_dashboard_create_dashboard (self ):
291322 io = self .get_client ()
@@ -372,3 +403,7 @@ def test_layout_update_layout(self):
372403 self .assertEqual (response .lg [0 ]['w' ], 16 )
373404 io .delete_block (dash .key , block .id )
374405 io .delete_dashboard (dash .key )
406+
407+
408+ if __name__ == "__main__" :
409+ unittest .main ()
0 commit comments