Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
247b02f6
Commit
247b02f6
authored
May 18, 2013
by
Joshua Roesslein
Browse files
Add streaming test suite.
- test_userstream
parent
fef0f30c
Changes
4
Hide whitespace changes
Inline
Side-by-side
.travis.yml
View file @
247b02f6
---
script
:
nosetests -v tests.test_api
script
:
nosetests -v tests.test_api
tests.test_streaming
language
:
python
env
:
global
:
...
...
tests/config.py
View file @
247b02f6
import
os
from
tweepy.auth
import
OAuthHandler
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'
,
''
)
def
create_auth
():
auth
=
OAuthHandler
(
oauth_consumer_key
,
oauth_consumer_secret
)
auth
.
set_access_token
(
oauth_token
,
oauth_token_secret
)
return
auth
tests/mock.py
0 → 100644
View file @
247b02f6
import
random
import
string
def
mock_tweet
():
"""Generate some random tweet text."""
count
=
random
.
randint
(
70
,
140
)
return
''
.
join
([
random
.
choice
(
string
.
letters
)
for
i
in
xrange
(
count
)])
tests/test_streaming.py
0 → 100644
View file @
247b02f6
from
time
import
sleep
import
unittest
from
tweepy.api
import
API
from
tweepy.streaming
import
Stream
,
StreamListener
from
config
import
create_auth
from
mock
import
mock_tweet
class
MockStreamListener
(
StreamListener
):
def
__init__
(
self
):
super
(
MockStreamListener
,
self
).
__init__
()
self
.
status_count
=
0
def
on_status
(
self
,
status
):
self
.
status_count
+=
1
return
False
class
TweepyStreamTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
auth
=
create_auth
()
self
.
listener
=
MockStreamListener
()
self
.
stream
=
Stream
(
self
.
auth
,
self
.
listener
)
def
tearDown
(
self
):
self
.
stream
.
disconnect
()
def
test_userstream
(
self
):
self
.
stream
.
userstream
(
async
=
True
)
# Generate random tweet which should show up in the stream.
# Wait a bit of time for it to arrive before asserting.
API
(
self
.
auth
).
update_status
(
mock_tweet
())
sleep
(
1
)
self
.
assertEqual
(
self
.
listener
.
status_count
,
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment