@@ -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 ):
@@ -138,7 +138,7 @@ def test_create_data(self):
138138 data = Data (value = 42 )
139139 result = aio .create_data ('testfeed' , data )
140140 self .assertEqual (int (result .value ), 42 )
141-
141+
142142 def test_location_data (self ):
143143 """receive_location
144144 """
@@ -160,11 +160,41 @@ def test_time_data(self):
160160 """receive_time
161161 """
162162 aio = self .get_client ()
163- time = aio .receive_time ()
163+ server_time = aio .receive_time ()
164164 # Check that each value is rx'd properly
165165 # (should never be None type)
166- for time_data in time :
166+ for time_data in server_time :
167167 self .assertIsNotNone (time_data )
168+ # Check that the week day was interpreted properly
169+ adjusted_time = time .localtime (time .mktime (server_time ))
170+ self .assertEqual (server_time .tm_wday , adjusted_time .tm_wday )
171+
172+ def test_parse_time_struct (self ):
173+ """Ensure the _parse_time_struct method properly handles all 7
174+ week days. Particularly important to make sure Sunday is 6,
175+ not -1"""
176+ # Zero time is a dictionary as would be provided by server
177+ # (wday is one higher than it should be)
178+ zero_time = {'year' : 1970 ,
179+ 'mon' : 1 ,
180+ 'mday' : 1 ,
181+ 'hour' : 0 ,
182+ 'min' : 0 ,
183+ 'sec' : 0 ,
184+ 'wday' : 4 ,
185+ 'yday' : 1 ,
186+ 'isdst' : 0 }
187+
188+ # Create a good struct for each day of the week and make sure
189+ # the server-style dictionary is parsed correctly
190+ for k in range (7 ):
191+ real_struct = time .gmtime (k * 86400 )
192+ d = zero_time .copy ()
193+ d ['mday' ] += k
194+ d ['wday' ] += k
195+ d ['yday' ] += k
196+ newd = Client ._parse_time_struct (d )
197+ self .assertEqual (newd .tm_wday , real_struct .tm_wday )
168198
169199 # Test Feed Functionality
170200 def test_append_by_feed_name (self ):
@@ -269,3 +299,7 @@ def test_receive_group_by_key(self):
269299 group = io .create_group (Group (name = 'grouprx' ))
270300 response = io .groups (group .key )
271301 self .assertEqual (response .key , 'grouprx' )
302+
303+
304+ if __name__ == "__main__" :
305+ unittest .main ()
0 commit comments