config.py 1.02 KB
Newer Older
1
import os
2
import unittest
Mark Smith's avatar
Mark Smith committed
3
import vcr
4

Joshua Roesslein's avatar
Joshua Roesslein committed
5
from tweepy.auth import OAuthHandler
6
from tweepy.api import API
Joshua Roesslein's avatar
Joshua Roesslein committed
7

Mark Smith's avatar
Mark Smith committed
8

Joshua Roesslein's avatar
Joshua Roesslein committed
9
username = os.environ.get('TWITTER_USERNAME', 'tweepytest')
10
11
12
13
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', '')
14
15
16
use_replay = os.environ.get('USE_REPLAY', False)


Mark Smith's avatar
Mark Smith committed
17
18
19
20
21
tape = vcr.VCR(
    cassette_library_dir='cassettes',
    filter_headers=['Authorization'],
    serializer='json',
    # Either use existing cassettes, or never use recordings:
22
    record_mode='none' if use_replay else 'all',
Mark Smith's avatar
Mark Smith committed
23
24
25
26
)


class TweepyTestCase(unittest.TestCase):
27
28
29
30
    def setUp(self):
        self.auth = create_auth()
        self.api = API(self.auth)
        self.api.retry_count = 2
31
        self.api.retry_delay = 0 if use_replay else 5
32

33

Joshua Roesslein's avatar
Joshua Roesslein committed
34
35
36
37
def create_auth():
    auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
    auth.set_access_token(oauth_token, oauth_token_secret)
    return auth