import json
from twitter import Twitter, NoAuth, OAuth, read_token_file, TwitterHTTPError
-from twitter.api import TwitterDictResponse, TwitterListResponse
+from twitter.api import TwitterDictResponse, TwitterListResponse, POST_ACTIONS, method_for_uri
from twitter.cmdline import CONSUMER_KEY, CONSUMER_SECRET
noauth = NoAuth()
res2 = json.loads(p)
assert res == res2
assert res2[2] == 3
+
+
+def test_method_for_uri():
+ for action in POST_ACTIONS:
+ assert method_for_uri(get_random_str() + '/' + action) == 'POST'
+ assert method_for_uri('statuses/timeline') == 'GET'
res = response
return res
+
+POST_ACTIONS_RE = re.compile('(' + '|'.join(POST_ACTIONS) + r')(/\d+)?$')
+
def method_for_uri(uri):
- method = "GET"
- for action in POST_ACTIONS:
- if re.search("%s(/\d+)?$" % action, uri):
- method = "POST"
- break
- return method
+ if POST_ACTIONS_RE.search(uri):
+ return "POST"
+ return "GET"
class TwitterCall(object):