-
Notifications
You must be signed in to change notification settings - Fork 262
/
Copy pathtest_oauth.py
38 lines (29 loc) · 1.22 KB
/
test_oauth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from TwitterAPI import TwitterAPI, TwitterOAuth
import unittest
class OAuthTest(unittest.TestCase):
"""Test user and application authentication."""
def setUp(self):
"""Read credentials from TwitterAPI/credentials.txt. You
must copy your credentials into this text file.
"""
self.oa = TwitterOAuth.read_file()
def test_oauth_1(self):
"""Test user authentication."""
api = TwitterAPI(self.oa.consumer_key, self.oa.consumer_secret,
self.oa.access_token_key, self.oa.access_token_secret)
status_code = self.verify_credentials(api)
# 200 means success
self.assertEqual(status_code, 200)
def test_oauth_2(self):
"""Test application authentication."""
api = TwitterAPI(self.oa.consumer_key, self.oa.consumer_secret,
auth_type='oAuth2')
status_code = self.verify_credentials(api)
# 403 means no access, which is correct since no user credentials
# provided
self.assertEqual(status_code, 403)
def verify_credentials(self, api):
r = api.request('account/verify_credentials')
return r.status_code
if __name__ == '__main__':
unittest.main()