Skip to content

Commit fef0f30

Browse files
committed
Split up tests into modules.
- Keep auth tests disabled in CI since they require user input.
1 parent 0b47bfe commit fef0f30

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
script: nosetests -v tests:TweepyAPITests tests:TweepyCursorTests tests:TweepyCacheTests tests:TweepyErrorTests
2+
script: nosetests -v tests.test_api
33
language: python
44
env:
55
global:

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
username = os.environ.get('TWITTER_USERNAME', '')
4+
oauth_consumer_key = os.environ.get('CONSUMER_KEY', '')
5+
oauth_consumer_secret = os.environ.get('CONSUMER_SECRET', '')
6+
oauth_token = os.environ.get('ACCESS_KEY', '')
7+
oauth_token_secret = os.environ.get('ACCESS_SECRET', '')
8+

tests.py renamed to tests/test_api.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
from tweepy import (API, OAuthHandler, Friendship, Cursor,
99
MemoryCache, FileCache)
1010

11-
"""Configurations"""
12-
# Must supply twitter account credentials for tests
13-
username = os.environ.get('TWITTER_USERNAME', '')
14-
oauth_consumer_key = os.environ.get('CONSUMER_KEY', '')
15-
oauth_consumer_secret = os.environ.get('CONSUMER_SECRET', '')
16-
oauth_token = os.environ.get('ACCESS_KEY', '')
17-
oauth_token_secret = os.environ.get('ACCESS_SECRET', '')
11+
from config import *
1812

1913
test_tweet_id = '266367358078169089'
2014

@@ -355,25 +349,6 @@ def testcursorcursorpages(self):
355349
pages = list(Cursor(self.api.followers_ids, 'twitter').pages(5))
356350
self.assert_(len(pages) == 5)
357351

358-
class TweepyAuthTests(unittest.TestCase):
359-
360-
def testoauth(self):
361-
auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
362-
363-
# test getting access token
364-
auth_url = auth.get_authorization_url()
365-
print 'Please authorize: ' + auth_url
366-
verifier = raw_input('PIN: ').strip()
367-
self.assert_(len(verifier) > 0)
368-
access_token = auth.get_access_token(verifier)
369-
self.assert_(access_token is not None)
370-
371-
# build api object test using oauth
372-
api = API(auth)
373-
s = api.update_status('test %i' % random.randint(0, 1000))
374-
api.destroy_status(s.id)
375-
376-
377352
class TweepyCacheTests(unittest.TestCase):
378353

379354
timeout = 2.0

tests/test_auth.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
3+
from config import *
4+
from tweepy import API, OAuthHandler
5+
6+
class TweepyAuthTests(unittest.TestCase):
7+
8+
def testoauth(self):
9+
auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
10+
11+
# test getting access token
12+
auth_url = auth.get_authorization_url()
13+
print 'Please authorize: ' + auth_url
14+
verifier = raw_input('PIN: ').strip()
15+
self.assert_(len(verifier) > 0)
16+
access_token = auth.get_access_token(verifier)
17+
self.assert_(access_token is not None)
18+
19+
# build api object test using oauth
20+
api = API(auth)
21+
s = api.update_status('test %i' % random.randint(0, 1000))
22+
api.destroy_status(s.id)
23+

0 commit comments

Comments
 (0)