Skip to content

Commit 28c2f4c

Browse files
committed
Default to YAML serializer for cassettes
1 parent e31e640 commit 28c2f4c

File tree

4 files changed

+103
-107
lines changed

4 files changed

+103
-107
lines changed

tests/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
tape = vcr.VCR(
2121
cassette_library_dir='cassettes',
2222
filter_headers=['Authorization'],
23-
serializer='json',
2423
# Either use existing cassettes, or never use recordings:
2524
record_mode='none' if use_replay else 'all',
2625
)

tests/test_api.py

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,52 @@ class TweepyAPITests(TweepyTestCase):
3030
# self.assertEqual(cm.exception.api_code, 215)
3131

3232
# TODO: Actually have some sort of better assertion
33-
@tape.use_cassette('testgetoembed.json')
33+
@tape.use_cassette('testgetoembed.json', serializer='json')
3434
def testgetoembed(self):
3535
data = self.api.get_oembed("https://twitter.com/Twitter/status/" + test_tweet_id)
3636
self.assertEqual(data['author_name'], "Twitter")
3737

38-
@tape.use_cassette('testparserargumenthastobeaparserinstance.json')
38+
@tape.use_cassette('testparserargumenthastobeaparserinstance.json',
39+
serializer='json')
3940
def testparserargumenthastobeaparserinstance(self):
4041
""" Testing the issue https://github.com/tweepy/tweepy/issues/421"""
4142
self.assertRaises(TypeError, API, self.auth, parser=Parser)
4243

43-
@tape.use_cassette('testhometimeline.json')
44+
@tape.use_cassette('testhometimeline.json', serializer='json')
4445
def testhometimeline(self):
4546
self.api.home_timeline()
4647

47-
@tape.use_cassette('testusertimeline.json')
48+
@tape.use_cassette('testusertimeline.json', serializer='json')
4849
def testusertimeline(self):
4950
self.api.user_timeline()
5051
self.api.user_timeline(screen_name='Twitter')
5152

52-
@tape.use_cassette('testmentionstimeline.json')
53+
@tape.use_cassette('testmentionstimeline.json', serializer='json')
5354
def testmentionstimeline(self):
5455
self.api.mentions_timeline()
5556

56-
@tape.use_cassette('testgetretweetsofme.json')
57+
@tape.use_cassette('testgetretweetsofme.json', serializer='json')
5758
def testgetretweetsofme(self):
5859
self.api.get_retweets_of_me()
5960

60-
@tape.use_cassette('testretweetandunretweet.json')
61+
@tape.use_cassette('testretweetandunretweet.json', serializer='json')
6162
def testretweetandunretweet(self):
6263
self.api.retweet(test_tweet_id)
6364
self.api.unretweet(test_tweet_id)
6465

65-
@tape.use_cassette('testgetretweets.json')
66+
@tape.use_cassette('testgetretweets.json', serializer='json')
6667
def testgetretweets(self):
6768
self.api.get_retweets(test_tweet_id)
6869

69-
@tape.use_cassette('testgetretweeterids.json')
70+
@tape.use_cassette('testgetretweeterids.json', serializer='json')
7071
def testgetretweeterids(self):
7172
self.api.get_retweeter_ids(test_tweet_id)
7273

73-
@tape.use_cassette('testgetstatus.json')
74+
@tape.use_cassette('testgetstatus.json', serializer='json')
7475
def testgetstatus(self):
7576
self.api.get_status(id=test_tweet_id)
7677

77-
@tape.use_cassette('testupdateanddestroystatus.json')
78+
@tape.use_cassette('testupdateanddestroystatus.json', serializer='json')
7879
def testupdateanddestroystatus(self):
7980
# test update
8081
update = self.api.update_status(status=tweet_text)
@@ -84,7 +85,7 @@ def testupdateanddestroystatus(self):
8485
deleted = self.api.destroy_status(id=update.id)
8586
self.assertEqual(deleted.id, update.id)
8687

87-
@tape.use_cassette('testupdateanddestroystatus.json')
88+
@tape.use_cassette('testupdateanddestroystatus.json', serializer='json')
8889
def testupdateanddestroystatuswithoutkwarg(self):
8990
# test update, passing text as a positional argument (#554)
9091
update = self.api.update_status(tweet_text)
@@ -94,47 +95,48 @@ def testupdateanddestroystatuswithoutkwarg(self):
9495
deleted = self.api.destroy_status(id=update.id)
9596
self.assertEqual(deleted.id, update.id)
9697

97-
@tape.use_cassette('testupdatestatuswithmedia.yaml', serializer='yaml')
98+
@tape.use_cassette('testupdatestatuswithmedia.yaml')
9899
def testupdatestatuswithmedia(self):
99100
update = self.api.update_status_with_media(tweet_text, 'assets/banner.png')
100101
self.assertIn(tweet_text + ' https://t.co', update.text)
101102

102-
@tape.use_cassette('testmediauploadpng.yaml', serializer='yaml')
103+
@tape.use_cassette('testmediauploadpng.yaml')
103104
def testmediauploadpng(self):
104105
self.api.media_upload('assets/banner.png')
105106

106-
@tape.use_cassette('testmediauploadgif.yaml', serializer='yaml')
107+
@tape.use_cassette('testmediauploadgif.yaml')
107108
def testmediauploadgif(self):
108109
self.api.media_upload('assets/animated.gif')
109110

110-
@tape.use_cassette('testmediauploadmp4.yaml', serializer='yaml')
111+
@tape.use_cassette('testmediauploadmp4.yaml')
111112
def testmediauploadmp4(self):
112113
self.api.media_upload('assets/video.mp4')
113114

114-
@tape.use_cassette('testgetuser.yaml', serializer='yaml')
115+
@tape.use_cassette('testgetuser.yaml')
115116
def testgetuser(self):
116117
u = self.api.get_user(screen_name='Twitter')
117118
self.assertEqual(u.screen_name, 'Twitter')
118119

119120
u = self.api.get_user(user_id=783214)
120121
self.assertEqual(u.screen_name, 'Twitter')
121122

122-
@tape.use_cassette('testlookupusers.json')
123+
@tape.use_cassette('testlookupusers.json', serializer='json')
123124
def testlookupusers(self):
124125
def check(users):
125126
self.assertEqual(len(users), 2)
126127
check(self.api.lookup_users(user_id=[6844292, 6253282]))
127128
check(self.api.lookup_users(screen_name=['twitterapi', 'twitter']))
128129

129-
@tape.use_cassette('testsearchusers.json')
130+
@tape.use_cassette('testsearchusers.json', serializer='json')
130131
def testsearchusers(self):
131132
self.api.search_users('twitter')
132133

133-
@tape.use_cassette('testgetdirectmessages.json')
134+
@tape.use_cassette('testgetdirectmessages.json', serializer='json')
134135
def testgetdirectmessages(self):
135136
self.api.get_direct_messages()
136137

137-
@tape.use_cassette('testsendanddeletedirectmessage.json')
138+
@tape.use_cassette('testsendanddeletedirectmessage.json',
139+
serializer='json')
138140
def testsendanddeletedirectmessage(self):
139141
me = self.api.verify_credentials()
140142

@@ -147,46 +149,45 @@ def testsendanddeletedirectmessage(self):
147149
# destroy
148150
self.api.delete_direct_message(sent_dm.id)
149151

150-
@tape.use_cassette('testindicatedirectmessagetyping.yaml',
151-
serializer='yaml')
152+
@tape.use_cassette('testindicatedirectmessagetyping.yaml')
152153
def testindicatedirectmessagetyping(self):
153154
me = self.api.verify_credentials()
154155

155156
self.api.indicate_direct_message_typing(me.id)
156157

157158
# TODO: Test API.mark_direct_message_read
158159

159-
@tape.use_cassette('testcreatedestroyfriendship.yaml', serializer='yaml')
160+
@tape.use_cassette('testcreatedestroyfriendship.yaml')
160161
def testcreatedestroyfriendship(self):
161162
enemy = self.api.destroy_friendship(screen_name='Twitter')
162163
self.assertEqual(enemy.screen_name, 'Twitter')
163164

164165
friend = self.api.create_friendship(screen_name='Twitter')
165166
self.assertEqual(friend.screen_name, 'Twitter')
166167

167-
@tape.use_cassette('testgetfriendship.json')
168+
@tape.use_cassette('testgetfriendship.json', serializer='json')
168169
def testgetfriendship(self):
169170
source, target = self.api.get_friendship(target_screen_name='twitter')
170171
self.assertTrue(isinstance(source, Friendship))
171172
self.assertTrue(isinstance(target, Friendship))
172173

173-
@tape.use_cassette('testgetfriendids.yaml', serializer='yaml')
174+
@tape.use_cassette('testgetfriendids.yaml')
174175
def testgetfriendids(self):
175176
self.api.get_friend_ids(screen_name=username)
176177

177-
@tape.use_cassette('testgetfollowerids.yaml', serializer='yaml')
178+
@tape.use_cassette('testgetfollowerids.yaml')
178179
def testgetfollowerids(self):
179180
self.api.get_follower_ids(screen_name=username)
180181

181-
@tape.use_cassette('testgetfriends.yaml', serializer='yaml')
182+
@tape.use_cassette('testgetfriends.yaml')
182183
def testgetfriends(self):
183184
self.api.get_friends(screen_name=username)
184185

185-
@tape.use_cassette('testgetfollowers.yaml', serializer='yaml')
186+
@tape.use_cassette('testgetfollowers.yaml')
186187
def testgetfollowers(self):
187188
self.api.get_followers(screen_name=username)
188189

189-
@tape.use_cassette('testverifycredentials.json')
190+
@tape.use_cassette('testverifycredentials.json', serializer='json')
190191
def testverifycredentials(self):
191192
self.api.verify_credentials()
192193

@@ -198,11 +199,11 @@ def testverifycredentials(self):
198199
me = self.api.verify_credentials(skip_status=True)
199200
self.assertFalse(hasattr(me, 'status'))
200201

201-
@tape.use_cassette('testratelimitstatus.json')
202+
@tape.use_cassette('testratelimitstatus.json', serializer='json')
202203
def testratelimitstatus(self):
203204
self.api.rate_limit_status()
204205

205-
@tape.use_cassette('testupdateprofilecolors.json')
206+
@tape.use_cassette('testupdateprofilecolors.json', serializer='json')
206207
def testupdateprofilecolors(self):
207208
original = self.api.verify_credentials()
208209
updated = self.api.update_profile(profile_link_color='D0F900')
@@ -224,11 +225,11 @@ def testupateprofileimage(self):
224225
"""
225226
# TODO: Use logo
226227

227-
@tape.use_cassette('testupdateprofilebannerimage.yaml', serializer='yaml')
228+
@tape.use_cassette('testupdateprofilebannerimage.yaml')
228229
def testupdateprofilebannerimage(self):
229230
self.api.update_profile_banner('assets/banner.png')
230231

231-
@tape.use_cassette('testupdateprofile.json')
232+
@tape.use_cassette('testupdateprofile.json', serializer='json')
232233
def testupdateprofile(self):
233234
original = self.api.verify_credentials()
234235
profile = {
@@ -246,61 +247,61 @@ def testupdateprofile(self):
246247
if k == 'email': continue
247248
self.assertEqual(getattr(updated, k), v)
248249

249-
@tape.use_cassette('testgetfavorites.json')
250+
@tape.use_cassette('testgetfavorites.json', serializer='json')
250251
def testgetfavorites(self):
251252
self.api.get_favorites()
252253

253-
@tape.use_cassette('testcreatedestroyfavorite.json')
254+
@tape.use_cassette('testcreatedestroyfavorite.json', serializer='json')
254255
def testcreatedestroyfavorite(self):
255256
self.api.create_favorite(145344012)
256257
self.api.destroy_favorite(145344012)
257258

258-
@tape.use_cassette('testcreatedestroyblock.yaml', serializer='yaml')
259+
@tape.use_cassette('testcreatedestroyblock.yaml')
259260
def testcreatedestroyblock(self):
260261
self.api.create_block(screen_name='twitter')
261262
self.api.destroy_block(screen_name='twitter')
262263
self.api.create_friendship(screen_name='twitter') # restore
263264

264-
@tape.use_cassette('testgetblocks.json')
265+
@tape.use_cassette('testgetblocks.json', serializer='json')
265266
def testgetblocks(self):
266267
self.api.get_blocks()
267268

268-
@tape.use_cassette('testgetblockedids.json')
269+
@tape.use_cassette('testgetblockedids.json', serializer='json')
269270
def testgetblockedids(self):
270271
self.api.get_blocked_ids()
271272

272-
@tape.use_cassette('testcreateupdatedestroylist.yaml', serializer='yaml')
273+
@tape.use_cassette('testcreateupdatedestroylist.yaml')
273274
def testcreateupdatedestroylist(self):
274275
l = self.api.create_list(name="tweeps")
275276
l = self.api.update_list(list_id=l.id, description='updated!')
276277
self.assertEqual(l.description, 'updated!')
277278
self.api.destroy_list(list_id=l.id)
278279

279-
@tape.use_cassette('testgetlists.json')
280+
@tape.use_cassette('testgetlists.json', serializer='json')
280281
def testgetlists(self):
281282
self.api.get_lists()
282283

283-
@tape.use_cassette('testgetlistmemberships.json')
284+
@tape.use_cassette('testgetlistmemberships.json', serializer='json')
284285
def testgetlistmemberships(self):
285286
self.api.get_list_memberships()
286287

287-
@tape.use_cassette('testgetlistownerships.json')
288+
@tape.use_cassette('testgetlistownerships.json', serializer='json')
288289
def testgetlistownerships(self):
289290
self.api.get_list_ownerships()
290291

291-
@tape.use_cassette('testgetlistsubscriptions.json')
292+
@tape.use_cassette('testgetlistsubscriptions.json', serializer='json')
292293
def testgetlistsubscriptions(self):
293294
self.api.get_list_subscriptions()
294295

295-
@tape.use_cassette('testlisttimeline.json')
296+
@tape.use_cassette('testlisttimeline.json', serializer='json')
296297
def testlisttimeline(self):
297298
self.api.list_timeline(owner_screen_name='Twitter', slug='Official-Twitter-Accounts')
298299

299-
@tape.use_cassette('testgetlist.json')
300+
@tape.use_cassette('testgetlist.json', serializer='json')
300301
def testgetlist(self):
301302
self.api.get_list(owner_screen_name='Twitter', slug='Official-Twitter-Accounts')
302303

303-
@tape.use_cassette('testaddremovelistmember.json')
304+
@tape.use_cassette('testaddremovelistmember.json', serializer='json')
304305
def testaddremovelistmember(self):
305306
params = {
306307
'slug': 'test',
@@ -314,7 +315,7 @@ def assert_list(l):
314315
assert_list(self.api.add_list_member(**params))
315316
assert_list(self.api.remove_list_member(**params))
316317

317-
@tape.use_cassette('testaddremovelistmembers.json')
318+
@tape.use_cassette('testaddremovelistmembers.json', serializer='json')
318319
def testaddremovelistmembers(self):
319320
params = {
320321
'slug': 'test',
@@ -328,15 +329,15 @@ def assert_list(l):
328329
assert_list(self.api.add_list_members(**params))
329330
assert_list(self.api.remove_list_members(**params))
330331

331-
@tape.use_cassette('testgetlistmembers.json')
332+
@tape.use_cassette('testgetlistmembers.json', serializer='json')
332333
def testgetlistmembers(self):
333334
self.api.get_list_members(owner_screen_name='Twitter', slug='Official-Twitter-Accounts')
334335

335-
@tape.use_cassette('testgetlistmember.json')
336+
@tape.use_cassette('testgetlistmember.json', serializer='json')
336337
def testgetlistmember(self):
337338
self.assertTrue(self.api.get_list_member(owner_screen_name='Twitter', slug='Official-Twitter-Accounts', screen_name='TwitterAPI'))
338339

339-
@tape.use_cassette('testsubscribeunsubscribelist.json')
340+
@tape.use_cassette('testsubscribeunsubscribelist.json', serializer='json')
340341
def testsubscribeunsubscribelist(self):
341342
params = {
342343
'owner_screen_name': 'Twitter',
@@ -345,26 +346,26 @@ def testsubscribeunsubscribelist(self):
345346
self.api.subscribe_list(**params)
346347
self.api.unsubscribe_list(**params)
347348

348-
@tape.use_cassette('testgetlistsubscribers.json')
349+
@tape.use_cassette('testgetlistsubscribers.json', serializer='json')
349350
def testgetlistsubscribers(self):
350351
self.api.get_list_subscribers(owner_screen_name='Twitter', slug='Official-Twitter-Accounts')
351352

352-
@tape.use_cassette('testgetlistsubscriber.json')
353+
@tape.use_cassette('testgetlistsubscriber.json', serializer='json')
353354
def testgetlistsubscriber(self):
354355
self.assertTrue(self.api.get_list_subscriber(owner_screen_name='Twitter', slug='Official-Twitter-Accounts', screen_name='TwitterMktg'))
355356

356-
@tape.use_cassette('testsavedsearches.json')
357+
@tape.use_cassette('testsavedsearches.json', serializer='json')
357358
def testsavedsearches(self):
358359
s = self.api.create_saved_search('test')
359360
self.api.get_saved_searches()
360361
self.assertEqual(self.api.get_saved_search(s.id).query, 'test')
361362
self.api.destroy_saved_search(s.id)
362363

363-
@tape.use_cassette('testsearchtweets.json')
364+
@tape.use_cassette('testsearchtweets.json', serializer='json')
364365
def testsearchtweets(self):
365366
self.api.search_tweets('tweepy')
366367

367-
@tape.use_cassette('testgeoapis.json')
368+
@tape.use_cassette('testgeoapis.json', serializer='json')
368369
def testgeoapis(self):
369370
def place_name_in_list(place_name, place_list):
370371
"""Return True if a given place_name is in place_list."""
@@ -375,7 +376,7 @@ def place_name_in_list(place_name, place_list):
375376
self.assertTrue(place_name_in_list('Austin, TX',
376377
self.api.reverse_geocode(lat=30.2673701685, long= -97.7426147461))) # Austin, TX, USA
377378

378-
@tape.use_cassette('testsupportedlanguages.json')
379+
@tape.use_cassette('testsupportedlanguages.json', serializer='json')
379380
def testsupportedlanguages(self):
380381
languages = self.api.supported_languages()
381382
expected_dict = {
@@ -387,15 +388,15 @@ def testsupportedlanguages(self):
387388
}
388389
self.assertTrue(expected_dict in languages)
389390

390-
@tape.use_cassette('testcachedresult.yaml', serializer='yaml')
391+
@tape.use_cassette('testcachedresult.yaml')
391392
def testcachedresult(self):
392393
self.api.cache = MemoryCache()
393394
self.api.home_timeline()
394395
self.assertFalse(self.api.cached_result)
395396
self.api.home_timeline()
396397
self.assertTrue(self.api.cached_result)
397398

398-
@tape.use_cassette('testcachedresult.yaml', serializer='yaml')
399+
@tape.use_cassette('testcachedresult.yaml')
399400
def testcachedifferentqueryparameters(self):
400401
self.api.cache = MemoryCache()
401402

0 commit comments

Comments
 (0)