| author | Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> |
| Mon, 20 Feb 2012 01:35:15 +0100 | |
| changeset 527 | 80e5b9543cac |
| parent 207 | 621fa6caec0c |
| parent 14 | 10e7a0c7c64f |
| permissions | -rw-r--r-- |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
1 |
import contextlib |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
2 |
import threading |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
3 |
import time |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
4 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
5 |
from tweetstream import TweetStream, FollowStream, TrackStream, LocationStream |
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
6 |
from tweetstream import ConnectionError, AuthenticationError, SampleStream, FilterStream |
|
207
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
7 |
from tweepy.auth import BasicAuthHandler |
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
8 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
9 |
import pytest |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
10 |
from pytest import raises |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
11 |
slow = pytest.mark.slow |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
12 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
13 |
from servercontext import test_server |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
14 |
|
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
15 |
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" |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
16 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
17 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
18 |
def parameterized(funcarglist): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
19 |
def wrapper(function): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
20 |
function.funcarglist = funcarglist |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
21 |
return function |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
22 |
return wrapper |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
23 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
24 |
def pytest_generate_tests(metafunc): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
25 |
for funcargs in getattr(metafunc.function, 'funcarglist', ()): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
26 |
metafunc.addcall(funcargs=funcargs) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
27 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
28 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
29 |
streamtypes = [ |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
30 |
dict(cls=TweetStream, args=[], kwargs=dict()), |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
31 |
dict(cls=SampleStream, args=[], kwargs=dict()), |
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
32 |
dict(cls=FilterStream, args=[], kwargs=dict(track=("test",))), |
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
33 |
dict(cls=FollowStream, args=[[1, 2, 3]], kwargs=dict()), |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
34 |
dict(cls=TrackStream, args=["opera"], kwargs=dict()), |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
35 |
dict(cls=LocationStream, args=["123,4321"], kwargs=dict()) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
36 |
] |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
37 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
38 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
39 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
40 |
def test_bad_auth(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
41 |
"""Test that the proper exception is raised when the user could not be |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
42 |
authenticated""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
43 |
def auth_denied(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
44 |
request.send_error(401) |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
45 |
|
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
46 |
with raises(AuthenticationError): |
|
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
47 |
with test_server(handler=auth_denied, methods=("post", "get"), port="random") as server: |
|
527
80e5b9543cac
Merge with 9d7218514a08006f925f138df88d770b29fae4cc
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
48 |
auth = BasicAuthHandler("user", "passwd") |
|
80e5b9543cac
Merge with 9d7218514a08006f925f138df88d770b29fae4cc
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
49 |
stream = cls(auth, *args, url=server.baseurl) |
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
50 |
for e in stream: pass |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
51 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
52 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
53 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
54 |
def test_404_url(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
55 |
"""Test that the proper exception is raised when the stream URL can't be |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
56 |
found""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
57 |
def not_found(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
58 |
request.send_error(404) |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
59 |
|
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
60 |
with raises(ConnectionError): |
|
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
61 |
with test_server(handler=not_found, methods=("post", "get"), port="random") as server: |
|
527
80e5b9543cac
Merge with 9d7218514a08006f925f138df88d770b29fae4cc
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
62 |
auth = BasicAuthHandler("user", "passwd") |
|
80e5b9543cac
Merge with 9d7218514a08006f925f138df88d770b29fae4cc
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
63 |
stream = cls(auth, *args, url=server.baseurl) |
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
64 |
for e in stream: pass |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
65 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
66 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
67 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
68 |
def test_bad_content(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
69 |
"""Test error handling if we are given invalid data""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
70 |
def bad_content(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
71 |
for n in xrange(10): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
72 |
# what json we pass doesn't matter. It's not verifying the |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
73 |
# strcuture, only checking that it's parsable |
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
74 |
yield "[1,2,3]\r" |
|
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
75 |
yield "[1,2, I need no stinking close brace\r" |
|
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
76 |
yield "[1,2,3]\r" |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
77 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
78 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
79 |
with raises(ConnectionError): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
80 |
with test_server(handler=bad_content, methods=("post", "get"), port="random") as server: |
|
207
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
81 |
auth = BasicAuthHandler("user", "passwd") |
|
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
82 |
stream = cls(auth, *args, url=server.baseurl) |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
83 |
for tweet in stream: |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
84 |
pass |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
85 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
86 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
87 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
88 |
def test_closed_connection(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
89 |
"""Test error handling if server unexpectedly closes connection""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
90 |
cnt = 1000 |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
91 |
def bad_content(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
92 |
for n in xrange(cnt): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
93 |
# what json we pass doesn't matter. It's not verifying the |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
94 |
# strcuture, only checking that it's parsable |
|
14
10e7a0c7c64f
upgrade tweet stream to 1.1.1
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
13
diff
changeset
|
95 |
yield "[1,2,3]\r" |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
96 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
97 |
with raises(ConnectionError): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
98 |
with test_server(handler=bad_content, methods=("post", "get"), port="random") as server: |
|
207
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
99 |
auth = BasicAuthHandler("foo", "bar") |
|
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
100 |
stream = cls(auth, *args, url=server.baseurl) |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
101 |
for tweet in stream: |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
102 |
pass |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
103 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
104 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
105 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
106 |
def test_bad_host(cls, args, kwargs): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
107 |
"""Test behaviour if we can't connect to the host""" |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
108 |
with raises(ConnectionError): |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
109 |
stream = cls("username", "passwd", *args, url="http://wedfwecfghhreewerewads.foo") |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
110 |
stream.next() |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
111 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
112 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
113 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
114 |
def smoke_test_receive_tweets(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
115 |
"""Receive 100k tweets and disconnect (slow)""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
116 |
total = 100000 |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
117 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
118 |
def tweetsource(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
119 |
while True: |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
120 |
yield single_tweet + "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
121 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
122 |
with test_server(handler=tweetsource, methods=("post", "get"), port="random") as server: |
|
207
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
123 |
auth = BasicAuthHandler("foo", "bar") |
|
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
124 |
stream = cls(auth, *args, url=server.baseurl) |
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
125 |
for tweet in stream: |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
126 |
if stream.count == total: |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
127 |
break |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
128 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
129 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
130 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
131 |
def test_keepalive(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
132 |
"""Make sure we behave sanely when there are keepalive newlines in the |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
133 |
data recevived from twitter""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
134 |
def tweetsource(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
135 |
yield single_tweet+"\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
136 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
137 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
138 |
yield single_tweet+"\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
139 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
140 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
141 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
142 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
143 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
144 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
145 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
146 |
yield single_tweet+"\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
147 |
yield "\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
148 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
149 |
|
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
150 |
with test_server(handler=tweetsource, methods=("post", "get"), port="random") as server: |
|
207
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
151 |
auth = BasicAuthHandler("foo", "bar") |
|
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
152 |
stream = cls(auth, *args, url=server.baseurl) |
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
153 |
try: |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
154 |
for tweet in stream: |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
155 |
pass |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
156 |
except ConnectionError: |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
157 |
assert stream.count == 3, "Got %s, wanted 3" % stream.count |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
158 |
else: |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
159 |
assert False, "Didn't handle keepalive" |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
160 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
161 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
162 |
@slow |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
163 |
@parameterized(streamtypes) |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
164 |
def test_buffering(cls, args, kwargs): |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
165 |
"""Test if buffering stops data from being returned immediately. |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
166 |
If there is some buffering in play that might mean data is only returned |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
167 |
from the generator when the buffer is full. If buffer is bigger than a |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
168 |
tweet, this will happen. Default buffer size in the part of socket lib |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
169 |
that enables readline is 8k. Max tweet length is around 3k.""" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
170 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
171 |
def tweetsource(request): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
172 |
yield single_tweet+"\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
173 |
time.sleep(2) |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
174 |
# need to yield a bunch here so we're sure we'll return from the |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
175 |
# blocking call in case the buffering bug is present. |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
176 |
for n in xrange(100): |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
177 |
yield single_tweet+"\n" |
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
178 |
|
|
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
179 |
|
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
180 |
with test_server(handler=tweetsource, methods=("post", "get"), port="random") as server: |
|
207
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
181 |
auth = BasicAuthHandler("foo", "bar") |
|
621fa6caec0c
Merge with f093196961e770387cc7cd3e11f2b7c0881b003b
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
diff
changeset
|
182 |
stream = cls(auth, *args, url=server.baseurl) |
|
13
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
183 |
start = time.time() |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
184 |
stream.next() |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
185 |
first = time.time() |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
186 |
diff = first - start |
|
79b6e132e3d7
upgrade tweetstream to 1.0.0
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
12
diff
changeset
|
187 |
assert diff < 1, "Getting first tweet took more than a second!" |
|
12
4daf47fcf792
move lib and prepare tweetstream for modification
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff
changeset
|
188 |