Commit 06614606 authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

Add API.cached_result.

This will be True if the last result was cached.
Otherwise this will be False if the result was freshly
requested from the Twitter API servers.
parent 66302747
......@@ -326,6 +326,13 @@ class TweepyAPITests(TweepyTestCase):
}
self.assertTrue(expected_dict in languages)
def testcachedresult(self):
self.api.cache = MemoryCache()
self.api.home_timeline()
self.assertFalse(self.api.cached_result)
self.api.home_timeline()
self.assertTrue(self.api.cached_result)
class TweepyCacheTests(unittest.TestCase):
timeout = 2.0
......
......@@ -104,6 +104,8 @@ def bind_api(**config):
self.path = self.path.replace(variable, value)
def execute(self):
self.api.cached_result = False
# Build the request URL
url = self.api_root + self.path
if len(self.parameters):
......@@ -123,6 +125,7 @@ def bind_api(**config):
else:
if isinstance(cache_result, Model):
cache_result._api = self.api
self.api.cached_result = True
return cache_result
# Continue attempting request until successful
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment