adds tests for Create/DestroyListsMember() methods · hacktoolkit/python-twitter@76f61c2 · GitHub
Skip to content

Commit 76f61c2

Browse files
committed
adds tests for Create/DestroyListsMember() methods
1 parent 3e1976b commit 76f61c2

6 files changed

Lines changed: 67 additions & 5 deletions
Lines changed: 1 addition & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"member_count": 3, "created_at": "Fri Dec 18 20:00:45 +0000 2015", "subscriber_count": 0, "user": {"profile_background_tile": false, "profile_sidebar_fill_color": "DDEEF6", "default_profile_image": true, "is_translation_enabled": false, "name": "notinourselves", "has_extended_profile": false, "url": null, "friends_count": 1, "follow_request_sent": false, "profile_link_color": "0084B4", "verified": false, "profile_use_background_image": true, "profile_text_color": "333333", "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "profile_background_color": "C0DEED", "followers_count": 1, "contributors_enabled": false, "profile_sidebar_border_color": "C0DEED", "notifications": false, "time_zone": null, "screen_name": "notinourselves", "location": "", "profile_banner_url": "https://pbs.twimg.com/profile_banners/4012966701/1453123196", "id": 4012966701, "listed_count": 1, "id_str": "4012966701", "geo_enabled": true, "entities": {"description": {"urls": []}}, "statuses_count": 67, "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "description": "", "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "is_translator": false, "utc_offset": null, "default_profile": true, "protected": true, "favourites_count": 1, "lang": "en", "created_at": "Wed Oct 21 23:53:04 +0000 2015", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "following": false}, "id": 229581524, "id_str": "229581524", "description": "", "uri": "/notinourselves/lists/test", "full_name": "@notinourselves/test", "mode": "public", "following": true, "name": "test", "slug": "test"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"member_count": 1, "created_at": "Fri Dec 18 20:00:45 +0000 2015", "subscriber_count": 0, "user": {"profile_background_tile": false, "profile_sidebar_fill_color": "DDEEF6", "default_profile_image": true, "is_translation_enabled": false, "name": "notinourselves", "has_extended_profile": false, "url": null, "friends_count": 1, "follow_request_sent": false, "profile_link_color": "0084B4", "verified": false, "profile_use_background_image": true, "profile_text_color": "333333", "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "profile_background_color": "C0DEED", "followers_count": 1, "contributors_enabled": false, "profile_sidebar_border_color": "C0DEED", "notifications": false, "time_zone": null, "screen_name": "notinourselves", "location": "", "profile_banner_url": "https://pbs.twimg.com/profile_banners/4012966701/1453123196", "id": 4012966701, "listed_count": 1, "id_str": "4012966701", "geo_enabled": true, "entities": {"description": {"urls": []}}, "statuses_count": 67, "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "description": "", "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "is_translator": false, "utc_offset": null, "default_profile": true, "protected": true, "favourites_count": 1, "lang": "en", "created_at": "Wed Oct 21 23:53:04 +0000 2015", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "following": false}, "id": 229581524, "id_str": "229581524", "description": "", "uri": "/notinourselves/lists/test", "full_name": "@notinourselves/test", "mode": "public", "following": true, "name": "test", "slug": "test"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"member_count": 0, "created_at": "Fri Dec 18 20:00:45 +0000 2015", "subscriber_count": 0, "user": {"profile_background_tile": false, "profile_sidebar_fill_color": "DDEEF6", "default_profile_image": true, "is_translation_enabled": false, "name": "notinourselves", "has_extended_profile": false, "url": null, "friends_count": 1, "follow_request_sent": false, "profile_link_color": "0084B4", "verified": false, "profile_use_background_image": true, "profile_text_color": "333333", "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "profile_background_color": "C0DEED", "followers_count": 1, "contributors_enabled": false, "profile_sidebar_border_color": "C0DEED", "notifications": false, "time_zone": null, "screen_name": "notinourselves", "location": "", "profile_banner_url": "https://pbs.twimg.com/profile_banners/4012966701/1453123196", "id": 4012966701, "listed_count": 1, "id_str": "4012966701", "geo_enabled": true, "entities": {"description": {"urls": []}}, "statuses_count": 67, "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "description": "", "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png", "is_translator": false, "utc_offset": null, "default_profile": true, "protected": true, "favourites_count": 1, "lang": "en", "created_at": "Wed Oct 21 23:53:04 +0000 2015", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "following": false}, "id": 229581524, "id_str": "229581524", "description": "", "uri": "/notinourselves/lists/test", "full_name": "@notinourselves/test", "mode": "public", "following": true, "name": "test", "slug": "test"}

tests/test_api_30.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def testGetListMembersPaged(self):
10231023
skip_status=True,
10241024
include_entities=False,
10251025
count=100)
1026-
self.assertFalse(resp[0].status)
1026+
self.assertFalse(resp[0].status)
10271027

10281028
@responses.activate
10291029
def testGetListTimeline(self):
@@ -1241,3 +1241,65 @@ def testGetMemberships(self):
12411241
resp = self.api.GetMemberships(screen_name='himawari8bot')
12421242
self.assertEqual(len(resp), 20)
12431243
self.assertTrue([isinstance(lst, twitter.List) for lst in resp])
1244+
1245+
@responses.activate
1246+
def testCreateListsMember(self):
1247+
with open('testdata/post_create_lists_member.json') as f:
1248+
resp_data = f.read()
1249+
responses.add(
1250+
responses.POST,
1251+
'https://api.twitter.com/1.1/lists/members/create.json',
1252+
body=resp_data,
1253+
match_querystring=True,
1254+
status=200)
1255+
resp = self.api.CreateListsMember(list_id=229581524, user_id=372018022)
1256+
self.assertTrue(isinstance(resp, twitter.List))
1257+
self.assertEqual(resp.name, 'test')
1258+
self.assertEqual(resp.member_count, 2)
1259+
1260+
@responses.activate
1261+
def testCreateListsMemberMultiple(self):
1262+
with open('testdata/post_create_lists_member_multiple.json') as f:
1263+
resp_data = f.read()
1264+
responses.add(
1265+
responses.POST,
1266+
'https://api.twitter.com/1.1/lists/members/create_all.json',
1267+
body=resp_data,
1268+
match_querystring=True,
1269+
status=200)
1270+
resp = self.api.CreateListsMember(list_id=229581524,
1271+
user_id=[372018022, 4040207472])
1272+
self.assertTrue(isinstance(resp, twitter.List))
1273+
self.assertEqual(resp.name, 'test')
1274+
self.assertEqual(resp.member_count, 3)
1275+
1276+
@responses.activate
1277+
def testDestroyListsMember(self):
1278+
with open('testdata/post_destroy_lists_member.json') as f:
1279+
resp_data = f.read()
1280+
responses.add(
1281+
responses.POST,
1282+
'https://api.twitter.com/1.1/lists/members/destroy.json',
1283+
body=resp_data,
1284+
match_querystring=True,
1285+
status=200)
1286+
resp = self.api.DestroyListsMember(list_id=229581524, user_id=372018022)
1287+
self.assertTrue(isinstance(resp, twitter.List))
1288+
self.assertEqual(resp.name, 'test')
1289+
self.assertEqual(resp.member_count, 1)
1290+
1291+
@responses.activate
1292+
def testDestroyListsMemberMultiple(self):
1293+
with open('testdata/post_destroy_lists_member_multiple.json') as f:
1294+
resp_data = f.read()
1295+
responses.add(
1296+
responses.POST,
1297+
'https://api.twitter.com/1.1/lists/members/destroy_all.json',
1298+
body=resp_data,
1299+
match_querystring=True,
1300+
status=200)
1301+
resp = self.api.DestroyListsMember(list_id=229581524,
1302+
user_id=[372018022, 4040207472])
1303+
self.assertEqual(resp.member_count, 0)
1304+
self.assertEqual(resp.name, 'test')
1305+
self.assertTrue(isinstance(resp, twitter.List))

twitter/api.py

Lines changed: 0 additions & 4 deletions

0 commit comments

Comments
 (0)