Skip to content

Commit 6ce39f9

Browse files
Moving tests to their own folder
1 parent 53b930b commit 6ce39f9

File tree

6 files changed

+115
-91
lines changed

6 files changed

+115
-91
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env:
2727
- TEST_TWEET_ID=332992304010899457
2828
- TEST_LIST_ID=574
2929
install: pip install -r requirements.txt
30-
script: nosetests -v --logging-filter="twython" --with-cov --cov twython test_twython.py --cov-report term-missing
30+
script: nosetests -v --logging-filter="twython" --with-cov --cov twython tests/ --cov-report term-missing
3131
notifications:
3232
email: false
3333
branches:

tests/__init__.py

Whitespace-only changes.

tests/config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
app_key = os.environ.get('APP_KEY')
4+
app_secret = os.environ.get('APP_SECRET')
5+
oauth_token = os.environ.get('OAUTH_TOKEN')
6+
oauth_token_secret = os.environ.get('OAUTH_TOKEN_SECRET')
7+
8+
screen_name = os.environ.get('SCREEN_NAME', '__twython__')
9+
10+
# Protected Account you ARE following and they ARE following you
11+
protected_twitter_1 = os.environ.get('PROTECTED_TWITTER_1', 'TwythonSecure1')
12+
13+
# Protected Account you ARE NOT following
14+
protected_twitter_2 = os.environ.get('PROTECTED_TWITTER_2', 'TwythonSecure2')
15+
16+
# Test Ids
17+
test_tweet_id = os.environ.get('TEST_TWEET_ID', '318577428610031617')
18+
test_list_id = os.environ.get('TEST_LIST_ID', '574') # 574 is @twitter/team

tests/test_auth.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from twython import Twython, TwythonError, TwythonAuthError
2+
3+
from .config import app_key, app_secret, screen_name
4+
5+
import unittest
6+
7+
8+
class TwythonAuthTestCase(unittest.TestCase):
9+
def setUp(self):
10+
self.api = Twython(app_key, app_secret)
11+
self.bad_api = Twython('BAD_APP_KEY', 'BAD_APP_SECRET')
12+
13+
self.oauth2_api = Twython(app_key, app_secret, oauth_version=2)
14+
15+
def test_get_authentication_tokens(self):
16+
"""Test getting authentication tokens works"""
17+
self.api.get_authentication_tokens(callback_url='http://google.com/',
18+
force_login=True,
19+
screen_name=screen_name)
20+
21+
def test_get_authentication_tokens_bad_tokens(self):
22+
"""Test getting authentication tokens with bad tokens
23+
raises TwythonAuthError"""
24+
self.assertRaises(TwythonAuthError, self.bad_api.get_authentication_tokens,
25+
callback_url='http://google.com/')
26+
27+
def test_get_authorized_tokens_bad_tokens(self):
28+
"""Test getting final tokens fails with wrong tokens"""
29+
self.assertRaises(TwythonError, self.bad_api.get_authorized_tokens,
30+
'BAD_OAUTH_VERIFIER')
31+
32+
def test_get_authentication_tokens_raises_error_when_oauth2(self):
33+
"""Test when API is set for OAuth 2, get_authentication_tokens raises
34+
a TwythonError"""
35+
self.assertRaises(TwythonError, self.oauth2_api.get_authentication_tokens)
36+
37+
def test_get_authorization_tokens_raises_error_when_oauth2(self):
38+
"""Test when API is set for OAuth 2, get_authentication_tokens raises
39+
a TwythonError"""
40+
self.assertRaises(TwythonError, self.oauth2_api.get_authorized_tokens,
41+
'BAD_OAUTH_VERIFIER')

test_twython.py renamed to tests/test_core.py

Lines changed: 6 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,14 @@
1-
from twython import(
2-
Twython, TwythonStreamer, TwythonError,
3-
TwythonAuthError, TwythonStreamError
1+
from twython import Twython, TwythonError, TwythonAuthError
2+
3+
from .config import (
4+
app_key, app_secret, oauth_token, oauth_token_secret,
5+
protected_twitter_1, protected_twitter_2, screen_name,
6+
test_tweet_id, test_list_id
47
)
58

6-
import os
79
import time
810
import unittest
911

10-
app_key = os.environ.get('APP_KEY')
11-
app_secret = os.environ.get('APP_SECRET')
12-
oauth_token = os.environ.get('OAUTH_TOKEN')
13-
oauth_token_secret = os.environ.get('OAUTH_TOKEN_SECRET')
14-
15-
screen_name = os.environ.get('SCREEN_NAME', '__twython__')
16-
17-
# Protected Account you ARE following and they ARE following you
18-
protected_twitter_1 = os.environ.get('PROTECTED_TWITTER_1', 'TwythonSecure1')
19-
20-
# Protected Account you ARE NOT following
21-
protected_twitter_2 = os.environ.get('PROTECTED_TWITTER_2', 'TwythonSecure2')
22-
23-
# Test Ids
24-
test_tweet_id = os.environ.get('TEST_TWEET_ID', '318577428610031617')
25-
test_list_id = os.environ.get('TEST_LIST_ID', '574') # 574 is @twitter/team
26-
27-
28-
class TwythonAuthTestCase(unittest.TestCase):
29-
def setUp(self):
30-
self.api = Twython(app_key, app_secret)
31-
self.bad_api = Twython('BAD_APP_KEY', 'BAD_APP_SECRET')
32-
33-
def test_get_authentication_tokens(self):
34-
"""Test getting authentication tokens works"""
35-
self.api.get_authentication_tokens(callback_url='http://google.com/',
36-
force_login=True,
37-
screen_name=screen_name)
38-
39-
def test_get_authentication_tokens_bad_tokens(self):
40-
"""Test getting authentication tokens with bad tokens
41-
raises TwythonAuthError"""
42-
self.assertRaises(TwythonAuthError, self.bad_api.get_authentication_tokens,
43-
callback_url='http://google.com/')
44-
45-
def test_get_authorized_tokens_bad_tokens(self):
46-
"""Test getting final tokens fails with wrong tokens"""
47-
self.assertRaises(TwythonError, self.bad_api.get_authorized_tokens,
48-
'BAD_OAUTH_VERIFIER')
49-
5012

5113
class TwythonAPITestCase(unittest.TestCase):
5214
def setUp(self):
@@ -467,49 +429,3 @@ def test_get_closest_trends(self):
467429
"""Test getting the locations that Twitter has trending topic
468430
information for, closest to a specified location succeeds"""
469431
self.api.get_closest_trends(lat='37', long='-122')
470-
471-
472-
class TwythonStreamTestCase(unittest.TestCase):
473-
def setUp(self):
474-
class MyStreamer(TwythonStreamer):
475-
def on_success(self, data):
476-
self.disconnect()
477-
478-
def on_error(self, status_code, data):
479-
raise TwythonStreamError(data)
480-
481-
def on_delete(self, data):
482-
return
483-
484-
def on_limit(self, data):
485-
return
486-
487-
def on_disconnect(self, data):
488-
return
489-
490-
def on_timeout(self, data):
491-
return
492-
493-
self.api = MyStreamer(app_key, app_secret,
494-
oauth_token, oauth_token_secret)
495-
496-
def test_stream_status_filter(self):
497-
self.api.statuses.filter(track='twitter')
498-
499-
def test_stream_status_sample(self):
500-
self.api.statuses.sample()
501-
502-
def test_stream_status_firehose(self):
503-
self.assertRaises(TwythonStreamError, self.api.statuses.firehose,
504-
track='twitter')
505-
506-
def test_stream_site(self):
507-
self.assertRaises(TwythonStreamError, self.api.site,
508-
follow='twitter')
509-
510-
def test_stream_user(self):
511-
self.api.user(track='twitter')
512-
513-
514-
if __name__ == '__main__':
515-
unittest.main()

tests/test_streaming.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from twython import TwythonStreamer, TwythonStreamError
2+
3+
from .config import (
4+
app_key, app_secret, oauth_token, oauth_token_secret
5+
)
6+
7+
import unittest
8+
9+
10+
class TwythonStreamTestCase(unittest.TestCase):
11+
def setUp(self):
12+
class MyStreamer(TwythonStreamer):
13+
def on_success(self, data):
14+
self.disconnect()
15+
16+
def on_error(self, status_code, data):
17+
raise TwythonStreamError(data)
18+
19+
def on_delete(self, data):
20+
return
21+
22+
def on_limit(self, data):
23+
return
24+
25+
def on_disconnect(self, data):
26+
return
27+
28+
def on_timeout(self, data):
29+
return
30+
31+
self.api = MyStreamer(app_key, app_secret,
32+
oauth_token, oauth_token_secret)
33+
34+
def test_stream_status_filter(self):
35+
self.api.statuses.filter(track='twitter')
36+
37+
def test_stream_status_sample(self):
38+
self.api.statuses.sample()
39+
40+
def test_stream_status_firehose(self):
41+
self.assertRaises(TwythonStreamError, self.api.statuses.firehose,
42+
track='twitter')
43+
44+
def test_stream_site(self):
45+
self.assertRaises(TwythonStreamError, self.api.site,
46+
follow='twitter')
47+
48+
def test_stream_user(self):
49+
self.api.user(track='twitter')

0 commit comments

Comments
 (0)