From fef0f30c17ec6171e498e9564ea9c65123cccb71 Mon Sep 17 00:00:00 2001 From: Joshua Roesslein Date: Sat, 18 May 2013 21:49:15 -0700 Subject: [PATCH] Split up tests into modules. - Keep auth tests disabled in CI since they require user input. --- .travis.yml | 2 +- tests/__init__.py | 1 + tests/config.py | 8 ++++++++ tests.py => tests/test_api.py | 27 +-------------------------- tests/test_auth.py | 23 +++++++++++++++++++++++ 5 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/config.py rename tests.py => tests/test_api.py (93%) create mode 100644 tests/test_auth.py diff --git a/.travis.yml b/.travis.yml index 5919e7b..1f77e2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ --- -script: nosetests -v tests:TweepyAPITests tests:TweepyCursorTests tests:TweepyCacheTests tests:TweepyErrorTests +script: nosetests -v tests.test_api language: python env: global: diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/config.py b/tests/config.py new file mode 100644 index 0000000..67ee00a --- /dev/null +++ b/tests/config.py @@ -0,0 +1,8 @@ +import os + +username = os.environ.get('TWITTER_USERNAME', '') +oauth_consumer_key = os.environ.get('CONSUMER_KEY', '') +oauth_consumer_secret = os.environ.get('CONSUMER_SECRET', '') +oauth_token = os.environ.get('ACCESS_KEY', '') +oauth_token_secret = os.environ.get('ACCESS_SECRET', '') + diff --git a/tests.py b/tests/test_api.py similarity index 93% rename from tests.py rename to tests/test_api.py index e7db7a8..65a37db 100644 --- a/tests.py +++ b/tests/test_api.py @@ -8,13 +8,7 @@ from nose import SkipTest from tweepy import (API, OAuthHandler, Friendship, Cursor, MemoryCache, FileCache) -"""Configurations""" -# Must supply twitter account credentials for tests -username = os.environ.get('TWITTER_USERNAME', '') -oauth_consumer_key = os.environ.get('CONSUMER_KEY', '') -oauth_consumer_secret = os.environ.get('CONSUMER_SECRET', '') -oauth_token = os.environ.get('ACCESS_KEY', '') -oauth_token_secret = os.environ.get('ACCESS_SECRET', '') +from config import * test_tweet_id = '266367358078169089' @@ -355,25 +349,6 @@ class TweepyCursorTests(unittest.TestCase): pages = list(Cursor(self.api.followers_ids, 'twitter').pages(5)) self.assert_(len(pages) == 5) -class TweepyAuthTests(unittest.TestCase): - - def testoauth(self): - auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret) - - # test getting access token - auth_url = auth.get_authorization_url() - 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) - - # build api object test using oauth - api = API(auth) - s = api.update_status('test %i' % random.randint(0, 1000)) - api.destroy_status(s.id) - - class TweepyCacheTests(unittest.TestCase): timeout = 2.0 diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 0000000..bc37d36 --- /dev/null +++ b/tests/test_auth.py @@ -0,0 +1,23 @@ +import unittest + +from config import * +from tweepy import API, OAuthHandler + +class TweepyAuthTests(unittest.TestCase): + + def testoauth(self): + auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret) + + # test getting access token + auth_url = auth.get_authorization_url() + 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) + + # build api object test using oauth + api = API(auth) + s = api.update_status('test %i' % random.randint(0, 1000)) + api.destroy_status(s.id) + -- 2.25.1