Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
2734d077
Unverified
Commit
2734d077
authored
Nov 06, 2016
by
Aaron Hill
Browse files
Merge cache fixes
parents
c3dc358b
14d17783
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
cassettes/testcachedresult.json
View file @
2734d077
This diff is collapsed.
Click to expand it.
tests/test_api.py
View file @
2734d077
...
...
@@ -427,6 +427,19 @@ class TweepyAPITests(TweepyTestCase):
self
.
api
.
home_timeline
()
self
.
assertTrue
(
self
.
api
.
cached_result
)
@
tape
.
use_cassette
(
'testcachedresult.json'
)
def
testcachedifferentqueryparameters
(
self
):
self
.
api
.
cache
=
MemoryCache
()
user1
=
self
.
api
.
get_user
(
'TheTweepyTester'
)
self
.
assertFalse
(
self
.
api
.
cached_result
)
self
.
assertEquals
(
'TheTweepyTester'
,
user1
.
screen_name
)
user2
=
self
.
api
.
get_user
(
'tweepytest'
)
self
.
assertEquals
(
'tweepytest'
,
user2
.
screen_name
)
self
.
assertFalse
(
self
.
api
.
cached_result
)
class
TweepyCacheTests
(
unittest
.
TestCase
):
timeout
=
0.5
...
...
tweepy/binder.py
View file @
2734d077
...
...
@@ -7,7 +7,7 @@ from __future__ import print_function
import
time
import
re
from
six.moves.urllib.parse
import
quote
from
six.moves.urllib.parse
import
quote
,
urlencode
import
requests
import
logging
...
...
@@ -132,7 +132,7 @@ def bind_api(**config):
# Query the cache if one is available
# and this request uses a GET method.
if
self
.
use_cache
and
self
.
api
.
cache
and
self
.
method
==
'GET'
:
cache_result
=
self
.
api
.
cache
.
get
(
url
)
cache_result
=
self
.
api
.
cache
.
get
(
'%s?%s'
%
(
url
,
urlencode
(
self
.
session
.
params
))
)
# if cache result found and not expired, return it
if
cache_result
:
# must restore api reference
...
...
@@ -233,7 +233,7 @@ def bind_api(**config):
# Store result into cache if one is available.
if
self
.
use_cache
and
self
.
api
.
cache
and
self
.
method
==
'GET'
and
result
:
self
.
api
.
cache
.
store
(
url
,
result
)
self
.
api
.
cache
.
store
(
'%s?%s'
%
(
url
,
urlencode
(
self
.
session
.
params
))
,
result
)
return
result
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment