Skip to content

Commit 4da98de

Browse files
committed
Create a common test case class.
- Sets up authentication. - Handles recording or replaying HTTP traffic.
1 parent afe19c2 commit 4da98de

File tree

3 files changed

+2768
-21
lines changed

3 files changed

+2768
-21
lines changed

tests/config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import os
2+
from unittest import TestCase
3+
4+
from httreplay import start_replay, stop_replay
5+
from httreplay.utils import filter_headers_key
26

37
from tweepy.auth import OAuthHandler
8+
from tweepy.api import API
49

510
username = os.environ.get('TWITTER_USERNAME', '')
611
oauth_consumer_key = os.environ.get('CONSUMER_KEY', '')
712
oauth_consumer_secret = os.environ.get('CONSUMER_SECRET', '')
813
oauth_token = os.environ.get('ACCESS_KEY', '')
914
oauth_token_secret = os.environ.get('ACCESS_SECRET', '')
15+
use_replay = os.environ.get('USE_REPLAY', False)
16+
17+
class TweepyTestCase(TestCase):
18+
19+
def setUp(self):
20+
self.auth = create_auth()
21+
self.api = API(self.auth)
22+
self.api.retry_count = 2
23+
self.api.retry_delay = 5
24+
25+
if use_replay:
26+
start_replay('tests/record.json',
27+
headers_key=filter_headers_key(['Authorization']))
28+
29+
def tearDown(self):
30+
if use_replay:
31+
stop_replay()
1032

1133
def create_auth():
1234
auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)

0 commit comments

Comments
 (0)