Skip to content

Commit 2c7a42a

Browse files
authored
Add unfollow many support (#111)
Fixes #110
1 parent 8e019e7 commit 2c7a42a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

stream/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ def follow_many(self, follows, activity_copy_limit=None):
323323
token = self.create_jwt_token("follower", "*", feed_id="*")
324324
return self.post("follow_many/", token, params=params, data=follows)
325325

326+
def unfollow_many(self, unfollows):
327+
"""
328+
Unfollows many feeds at batch
329+
:param unfollows: the list of unfollow relations
330+
331+
eg. [{'source': source, 'target': target, 'keep_history': keep_history}]
332+
"""
333+
params = None
334+
335+
token = self.create_jwt_token("follower", "*", feed_id="*")
336+
return self.post("unfollow_many/", token, params=params, data=unfollows)
337+
326338
def update_activities(self, activities):
327339
"""
328340
Update or create activities

stream/tests/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,21 @@ def test_follow_many_acl(self):
10201020
activities = feed.get(limit=5)["results"]
10211021
self.assertEqual(len(activities), 0)
10221022

1023+
def test_unfollow_many(self):
1024+
unfollows = [
1025+
{"source": "user:1", "target": "timeline:1"},
1026+
{"source": "user:2", "target": "timeline:2", "keep_history": False},
1027+
]
1028+
1029+
self.c.unfollow_many(unfollows)
1030+
1031+
unfollows.append({"source": "user:1", "target": 42})
1032+
1033+
def failing_unfollow():
1034+
self.c.unfollow_many(unfollows)
1035+
1036+
self.assertRaises(InputException, failing_unfollow)
1037+
10231038
def test_add_to_many(self):
10241039
activity = {"actor": 1, "verb": "tweet", "object": 1, "custom": "data"}
10251040
feeds = [getfeed("flat", str(i)).id for i in range(10, 20)]

0 commit comments

Comments
 (0)