Commit c9c1dceb authored by Aaron Hill's avatar Aaron Hill
Browse files

Merge branch 'master' into remove_basic

parents 81297fe7 a5bae83e
......@@ -3,3 +3,4 @@
build/
dist/
tweepy.egg-info/
.env/
---
script: nosetests -v tests.test_api tests.test_streaming tests.test_cursors
language: python
python:
- "2.7"
install:
- pip install -r test_requirements.txt
script: ./run_tests.sh
env:
global:
- TWITTER_USERNAME="tweepytest"
......@@ -20,8 +24,4 @@ env:
nKkytraqLGUm33K1GpwkjOyxACDHYw4GMvOGyDwVTX7VNwqxbkUojB7qXYoQ
JjlEyFWS487IFteR87U9pt18qongJJIphaBdT9/lDVLsMWZ0Jh5ZLQfX+2jS
aF2UwsrYkzBUMrqMqYCc2+X6CuswLEZTVXDAlNh+emvhxZ5faMI=
python:
- "2.7"
branches:
only:
- master
#! /usr/bin/env bash
if [[ $TRAVIS_SECURE_ENV_VARS == "false" ]]; then
USE_REPLAY=1 nosetests -v tests.test_api tests.test_utils
else
nosetests -v tests.test_api tests.test_streaming tests.test_cursors tests.test_utils
fi
......@@ -10,6 +10,6 @@ setup(name="tweepy",
author="Joshua Roesslein",
author_email="tweepy@googlegroups.com",
url="http://github.com/tweepy/tweepy",
packages = find_packages(),
keywords= "twitter library",
zip_safe = True)
packages=find_packages(exclude=['tests']),
keywords="twitter library",
zip_safe=True)
import os
from unittest import TestCase
from httreplay import start_replay, stop_replay
from httreplay.utils import filter_headers_key
from tweepy.auth import OAuthHandler
from tweepy.api import API
username = os.environ.get('TWITTER_USERNAME', '')
username = os.environ.get('TWITTER_USERNAME', 'tweepytest')
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', '')
use_replay = os.environ.get('USE_REPLAY', False)
class TweepyTestCase(TestCase):
def setUp(self):
self.auth = create_auth()
self.api = API(self.auth)
self.api.retry_count = 2
self.api.retry_delay = 5
if use_replay:
start_replay('tests/record.json',
headers_key=filter_headers_key(['Authorization']))
def tearDown(self):
if use_replay:
stop_replay()
def create_auth():
auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
......
This diff is collapsed.
......@@ -5,12 +5,11 @@ import os
from nose import SkipTest
from tweepy import (API, OAuthHandler, Friendship, Cursor,
MemoryCache, FileCache)
from config import *
from tweepy import Friendship, MemoryCache, FileCache
from config import TweepyTestCase, username, use_replay
test_tweet_id = '266367358078169089'
tweet_text = 'testing 1000'
"""Unit tests"""
......@@ -27,14 +26,7 @@ class TweepyErrorTests(unittest.TestCase):
self.assertEqual(e.reason, e2.reason)
self.assertEqual(e.response, e2.response)
class TweepyAPITests(unittest.TestCase):
def setUp(self):
auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
auth.set_access_token(oauth_token, oauth_token_secret)
self.api = API(auth)
self.api.retry_count = 2
self.api.retry_delay = 5
class TweepyAPITests(TweepyTestCase):
# TODO: Actually have some sort of better assertion
def testgetoembed(self):
......@@ -62,12 +54,15 @@ class TweepyAPITests(unittest.TestCase):
def testretweets(self):
self.api.retweets(test_tweet_id)
def testretweeters(self):
self.api.retweeters(test_tweet_id)
def testgetstatus(self):
self.api.get_status(id=test_tweet_id)
def testupdateanddestroystatus(self):
# test update
text = 'testing %i' % random.randint(0, 1000)
text = tweet_text if use_replay else 'testing %i' % random.randint(0, 1000)
update = self.api.update_status(status=text)
self.assertEqual(update.text, text)
......
from unittest import TestCase
from tweepy.utils import *
class TweepyUtilsTests(TestCase):
def testparse_datetime(self):
result = parse_datetime("Wed Aug 27 13:08:45 +0000 2008")
self.assertEqual(datetime(2008, 8, 27, 13, 8, 45), result)
......@@ -57,14 +57,6 @@ class API(object):
require_auth = True
)
"""/statuses/:id/retweeted_by.format"""
retweeted_by = bind_api(
path = '/statuses/{id}/retweeted_by.json',
payload_type = 'status', payload_list = True,
allowed_param = ['id', 'count', 'page'],
require_auth = True
)
"""/related_results/show/:id.format"""
related_results = bind_api(
path = '/related_results/show/{id}.json',
......@@ -73,14 +65,6 @@ class API(object):
require_auth = False
)
"""/statuses/:id/retweeted_by/ids.format"""
retweeted_by_ids = bind_api(
path = '/statuses/{id}/retweeted_by/ids.json',
payload_type = 'ids',
allowed_param = ['id', 'count', 'page'],
require_auth = True
)
""" statuses/retweets_of_me """
retweets_of_me = bind_api(
path = '/statuses/retweets_of_me.json',
......@@ -131,6 +115,12 @@ class API(object):
require_auth = True
)
retweeters = bind_api(
path = '/statuses/retweeters/ids.json',
payload_type = 'ids',
allowed_param = ['id', 'cursor', 'stringify_ids']
)
""" users/show """
get_user = bind_api(
path = '/users/show.json',
......
......@@ -108,12 +108,11 @@ class Stream(object):
break
try:
if self.scheme == "http":
conn = httplib.HTTPConnection(self.host)
conn = httplib.HTTPConnection(self.host, timeout=self.timeout)
else:
conn = httplib.HTTPSConnection(self.host)
conn = httplib.HTTPSConnection(self.host, timeout=self.timeout)
self.auth.apply_auth(url, 'POST', self.headers, self.parameters)
conn.connect()
conn.sock.settimeout(self.timeout)
conn.request('POST', self.url, self.body, headers=self.headers)
resp = conn.getresponse()
if resp.status != 200:
......
......@@ -8,19 +8,11 @@ import htmlentitydefs
import re
import locale
from urllib import quote
from email.utils import parsedate
def parse_datetime(string):
# Set locale for date parsing
locale.setlocale(locale.LC_TIME, 'C')
# We must parse datetime this way to work in python 2.4
date = datetime(*(time.strptime(string, '%a %b %d %H:%M:%S +0000 %Y')[0:6]))
# Reset locale back to the default setting
locale.setlocale(locale.LC_TIME, '')
return date
return datetime(*(parsedate(string)[:6]))
def parse_html_value(html):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment