diff -r 3c14302784f8 -r 80e5b9543cac script/lib/tweetstream/tests/test_tweetstream.py --- a/script/lib/tweetstream/tests/test_tweetstream.py Thu Feb 16 16:40:16 2012 +0100 +++ b/script/lib/tweetstream/tests/test_tweetstream.py Mon Feb 20 01:35:15 2012 +0100 @@ -1,10 +1,9 @@ import contextlib import threading import time -from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from tweetstream import TweetStream, FollowStream, TrackStream, LocationStream -from tweetstream import ConnectionError, AuthenticationError, SampleStream +from tweetstream import ConnectionError, AuthenticationError, SampleStream, FilterStream from tweepy.auth import BasicAuthHandler import pytest @@ -13,7 +12,7 @@ from servercontext import test_server -single_tweet = r"""{"in_reply_to_status_id":null,"in_reply_to_user_id":null,"favorited":false,"created_at":"Tue Jun 16 10:40:14 +0000 2009","in_reply_to_screen_name":null,"text":"record industry just keeps on amazing me: http:\/\/is.gd\/13lFo - $150k per song you've SHARED, not that somebody has actually DOWNLOADED.","user":{"notifications":null,"profile_background_tile":false,"followers_count":206,"time_zone":"Copenhagen","utc_offset":3600,"friends_count":191,"profile_background_color":"ffffff","profile_image_url":"http:\/\/s3.amazonaws.com\/twitter_production\/profile_images\/250715794\/profile_normal.png","description":"Digital product developer, currently at Opera Software. My tweets are my opinions, not those of my employer.","verified_profile":false,"protected":false,"favourites_count":0,"profile_text_color":"3C3940","screen_name":"eiriksnilsen","name":"Eirik Stridsklev N.","following":null,"created_at":"Tue May 06 12:24:12 +0000 2008","profile_background_image_url":"http:\/\/s3.amazonaws.com\/twitter_production\/profile_background_images\/10531192\/160x600opera15.gif","profile_link_color":"0099B9","profile_sidebar_fill_color":"95E8EC","url":"http:\/\/www.stridsklev-nilsen.no\/eirik","id":14672543,"statuses_count":506,"profile_sidebar_border_color":"5ED4DC","location":"Oslo, Norway"},"id":2190767504,"truncated":false,"source":"Twitter Opera widget<\/a>"}""" +single_tweet = r"""{"in_reply_to_status_id":null,"in_reply_to_user_id":null,"favorited":false,"created_at":"Tue Jun 16 10:40:14 +0000 2009","in_reply_to_screen_name":null,"text":"record industry just keeps on amazing me: http:\/\/is.gd\/13lFo - $150k per song you've SHARED, not that somebody has actually DOWNLOADED.","user":{"notifications":null,"profile_background_tile":false,"followers_count":206,"time_zone":"Copenhagen","utc_offset":3600,"friends_count":191,"profile_background_color":"ffffff","profile_image_url":"http:\/\/s3.amazonaws.com\/twitter_production\/profile_images\/250715794\/profile_normal.png","description":"Digital product developer, currently at Opera Software. My tweets are my opinions, not those of my employer.","verified_profile":false,"protected":false,"favourites_count":0,"profile_text_color":"3C3940","screen_name":"eiriksnilsen","name":"Eirik Stridsklev N.","following":null,"created_at":"Tue May 06 12:24:12 +0000 2008","profile_background_image_url":"http:\/\/s3.amazonaws.com\/twitter_production\/profile_background_images\/10531192\/160x600opera15.gif","profile_link_color":"0099B9","profile_sidebar_fill_color":"95E8EC","url":"http:\/\/www.stridsklev-nilsen.no\/eirik","id":14672543,"statuses_count":506,"profile_sidebar_border_color":"5ED4DC","location":"Oslo, Norway"},"id":2190767504,"truncated":false,"source":"Twitter Opera widget<\/a>"}""" + "\r" def parameterized(funcarglist): @@ -30,6 +29,7 @@ streamtypes = [ dict(cls=TweetStream, args=[], kwargs=dict()), dict(cls=SampleStream, args=[], kwargs=dict()), + dict(cls=FilterStream, args=[], kwargs=dict(track=("test",))), dict(cls=FollowStream, args=[[1, 2, 3]], kwargs=dict()), dict(cls=TrackStream, args=["opera"], kwargs=dict()), dict(cls=LocationStream, args=["123,4321"], kwargs=dict()) @@ -43,9 +43,11 @@ def auth_denied(request): request.send_error(401) - with test_server(handler=auth_denied, methods=("post", "get"), port="random") as server: - auth = BasicAuthHandler("user", "passwd") - stream = cls(auth, *args, url=server.baseurl) + with raises(AuthenticationError): + with test_server(handler=auth_denied, methods=("post", "get"), port="random") as server: + auth = BasicAuthHandler("user", "passwd") + stream = cls(auth, *args, url=server.baseurl) + for e in stream: pass @parameterized(streamtypes) @@ -55,9 +57,11 @@ def not_found(request): request.send_error(404) - with test_server(handler=not_found, methods=("post", "get"), port="random") as server: - auth = BasicAuthHandler("user", "passwd") - stream = cls(auth, *args, url=server.baseurl) + with raises(ConnectionError): + with test_server(handler=not_found, methods=("post", "get"), port="random") as server: + auth = BasicAuthHandler("user", "passwd") + stream = cls(auth, *args, url=server.baseurl) + for e in stream: pass @parameterized(streamtypes) @@ -67,9 +71,9 @@ for n in xrange(10): # what json we pass doesn't matter. It's not verifying the # strcuture, only checking that it's parsable - yield "[1,2,3]" - yield "[1,2, I need no stinking close brace" - yield "[1,2,3]" + yield "[1,2,3]\r" + yield "[1,2, I need no stinking close brace\r" + yield "[1,2,3]\r" with raises(ConnectionError): @@ -88,7 +92,7 @@ for n in xrange(cnt): # what json we pass doesn't matter. It's not verifying the # strcuture, only checking that it's parsable - yield "[1,2,3]" + yield "[1,2,3]\r" with raises(ConnectionError): with test_server(handler=bad_content, methods=("post", "get"), port="random") as server: