--- a/script/lib/tweetstream/tests/test_tweetstream.py Fri Jul 01 10:15:32 2011 +0200
+++ b/script/lib/tweetstream/tests/test_tweetstream.py Mon Feb 20 00:12:16 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
import pytest
from pytest import raises
@@ -12,7 +11,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":"<a href=\"http:\/\/widgets.opera.com\/widget\/7206\">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":"<a href=\"http:\/\/widgets.opera.com\/widget\/7206\">Twitter Opera widget<\/a>"}""" + "\r"
def parameterized(funcarglist):
@@ -29,6 +28,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())
@@ -42,8 +42,10 @@
def auth_denied(request):
request.send_error(401)
- with test_server(handler=auth_denied, methods=("post", "get"), port="random") as server:
- stream = cls("user", "passwd", *args, url=server.baseurl)
+ with raises(AuthenticationError):
+ with test_server(handler=auth_denied, methods=("post", "get"), port="random") as server:
+ stream = cls("user", "passwd", *args, url=server.baseurl)
+ for e in stream: pass
@parameterized(streamtypes)
@@ -53,8 +55,10 @@
def not_found(request):
request.send_error(404)
- with test_server(handler=not_found, methods=("post", "get"), port="random") as server:
- stream = cls("user", "passwd", *args, url=server.baseurl)
+ with raises(ConnectionError):
+ with test_server(handler=not_found, methods=("post", "get"), port="random") as server:
+ stream = cls("user", "passwd", *args, url=server.baseurl)
+ for e in stream: pass
@parameterized(streamtypes)
@@ -64,9 +68,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):
@@ -84,7 +88,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: