@@ -231,3 +231,32 @@ def testLimitsViaHeadersWithSleep(self):
231231 self .assertEqual (api .rate_limit .get_limit ('/search/tweets' ).limit , 63 )
232232 self .assertEqual (api .rate_limit .get_limit ('/search/tweets' ).remaining , 63 )
233233 self .assertEqual (api .rate_limit .get_limit ('/search/tweets' ).reset , 626672700 )
234+
235+ @responses .activate
236+ def testLimitsViaHeadersWithSleepLimitReached (self ):
237+ api = twitter .Api (
238+ consumer_key = 'test' ,
239+ consumer_secret = 'test' ,
240+ access_token_key = 'test' ,
241+ access_token_secret = 'test' ,
242+ sleep_on_rate_limit = True )
243+
244+ # Add handler for ratelimit check - this forces the codepath which goes through the time.sleep call
245+ url = '%s/application/rate_limit_status.json?tweet_mode=compat' % api .base_url
246+ responses .add (
247+ method = responses .GET , url = url ,
248+ body = '{"resources": {"search": {"/search/tweets": {"limit": 1, "remaining": 0, "reset": 1}}}}' ,
249+ match_querystring = True )
250+
251+ # Get initial rate limit data to populate api.rate_limit object
252+ url = "https://api.twitter.com/1.1/search/tweets.json?tweet_mode=compat&q=test&count=15&result_type=mixed"
253+ responses .add (
254+ method = responses .GET ,
255+ url = url ,
256+ body = '{}' ,
257+ match_querystring = True ,
258+ adding_headers = HEADERS )
259+
260+ resp = api .GetSearch (term = 'test' )
261+ self .assertTrue (api .rate_limit )
262+ self .assertEqual (resp , [])
0 commit comments