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
c1594632
Commit
c1594632
authored
Aug 11, 2009
by
Josh Roesslein
Browse files
Added unit test for oauth.
parent
79a1e8ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests.py
View file @
c1594632
...
...
@@ -13,8 +13,8 @@ from tweepy import *
class
TweepyAPITests
(
unittest
.
TestCase
):
# Must supply twitter account credentials for tests
username
=
''
password
=
''
username
=
'
tweebly
'
password
=
'
omega1987twitter
'
def
setUp
(
self
):
self
.
api
=
API
(
BasicAuthHandler
(
self
.
username
,
self
.
password
),
self
.
username
)
...
...
@@ -98,6 +98,24 @@ class TweepyAPITests(unittest.TestCase):
self
.
assert_
(
isinstance
(
source
,
Friendship
))
self
.
assert_
(
isinstance
(
target
,
Friendship
))
class
TweepyAuthTests
(
unittest
.
TestCase
):
consumer_key
=
'ZbzSsdQj7t68VYlqIFvdcA'
consumer_secret
=
'4yDWgrBiRs2WIx3bfvF9UWCRmtQ2YKpKJKBahtZcU'
def
testoauth
(
self
):
auth
=
OAuthHandler
(
self
.
consumer_key
,
self
.
consumer_secret
)
auth_url
=
auth
.
get_authorization_url
()
self
.
assert_
(
auth_url
.
startswith
(
'http://twitter.com/oauth/authorize?'
))
print
'Please authorize: '
+
auth_url
verifier
=
raw_input
(
'PIN: '
).
strip
()
self
.
assert_
(
len
(
verifier
)
>
0
)
access_token
=
auth
.
get_access_token
(
verifier
)
self
.
assert_
(
access_token
is
not
None
)
api
=
API
(
auth
)
self
.
assertTrue
(
api
.
verify_credentials
())
if
__name__
==
'__main__'
:
unittest
.
main
()
tweepy/auth.py
View file @
c1594632
...
...
@@ -55,6 +55,9 @@ class OAuthHandler(AuthHandler):
except
Exception
,
e
:
raise
TweepError
(
e
)
def
set_access_token
(
self
,
key
,
secret
):
self
.
access_token
=
oauth
.
OAuthToken
(
key
,
secret
)
def
get_authorization_url
(
self
):
"""Get the authorization URL to redirect the user"""
try
:
...
...
tweepy/binder.py
View file @
c1594632
...
...
@@ -67,9 +67,9 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
# Open connection
if
api
.
secure
:
conn
=
httplib
.
HTTPSConnection
(
_host
)
conn
=
httplib
.
HTTPSConnection
(
_host
,
timeout
=
10.0
)
else
:
conn
=
httplib
.
HTTPConnection
(
_host
)
conn
=
httplib
.
HTTPConnection
(
_host
,
timeout
=
10.0
)
# Build request
conn
.
request
(
method
,
url
,
headers
=
headers
)
...
...
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