Skip to content

Commit 016d399

Browse files
author
Neil Brandt
committed
For #20562, implement 'followers' support in python-api.
1 parent 5b27e9b commit 016d399

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

shotgun_api3/shotgun.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,24 @@ def unfollow(self, user, entity):
837837

838838
return self._call_rpc('unfollow', params)
839839

840+
def followers(self, entity):
841+
"""Gets all followers of the entity.
842+
843+
:param dict entity: Find all followers of this entity
844+
845+
:returns list of dicts for all the users following the entity
846+
"""
847+
848+
if not self.server_caps.version or self.server_caps.version < (5, 2, 0):
849+
raise ShotgunError("Follow support requires server version 5.2 or "\
850+
"higher, server is %s" % (self.server_caps.version,))
851+
852+
params = dict(
853+
entity=entity
854+
)
855+
856+
return self._call_rpc('followers', params)
857+
840858
def schema_entity_read(self):
841859
"""Gets all active entities defined in the schema.
842860

tests/test_api.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ def test_unsupported_filters(self):
12841284

12851285
class TestFollow(base.TestBase):
12861286
def test_follow(self):
1287-
'''Test methods to follow/unfollow'''
1287+
'''Test follow method'''
12881288

12891289
project = self.sg.find_one('Project', [])
12901290
user = self.sg.find_one('HumanUser', [['projects', 'is', project]], ['name'])
@@ -1294,7 +1294,7 @@ def test_follow(self):
12941294
assert(result['followed'])
12951295

12961296
def test_unfollow(self):
1297-
'''Test methods to follow/unfollow'''
1297+
'''Test unfollow method'''
12981298

12991299
project = self.sg.find_one('Project', [])
13001300
user = self.sg.find_one('HumanUser', [['projects', 'is', project]], ['name'])
@@ -1303,6 +1303,20 @@ def test_unfollow(self):
13031303
result = self.sg.unfollow(user, entity)
13041304
print( result )
13051305
assert(result['unfollowed'])
1306+
1307+
def test_followers(self):
1308+
'''Test followers method'''
1309+
1310+
project = self.sg.find_one('Project', [])
1311+
user = self.sg.find_one('HumanUser', [['projects', 'is', project]], ['name'])
1312+
entity = self.sg.find_one('Shot', [['project', 'is', project]], ['name'])
1313+
1314+
result = self.sg.follow(user, entity)
1315+
assert(result['followed'])
1316+
1317+
result = self.sg.followers(entity)
1318+
self.assertEqual( 1, len(result) )
1319+
self.assertEqual( user['id'], result[0]['id'] )
13061320

13071321
class TestErrors(base.TestBase):
13081322
def test_bad_auth(self):

0 commit comments

Comments
 (0)