Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Add mutual_friends method and it's tests. this will bump the version …
Browse files Browse the repository at this point in the history
…to 0.0.2
  • Loading branch information
emre committed Aug 7, 2015
1 parent 2b9be76 commit c1cf067
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions relationships/relationship.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


import redis

from keys import key_list as default_key_list
Expand Down Expand Up @@ -81,6 +82,11 @@ def friends(self):
"user:{}:{}".format(self._get_actor(), self.key_list["followers"]),
)

def mutual_friends(self, to_id):
actor_friends, to_id_friends = self(self._get_actor()).friends(), self(to_id).friends()

return actor_friends.intersection(to_id_friends)

def followers(self):
return self._list_call(self.key_list["followers"])

Expand Down
15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup

setup(
name='relationships',
version='0.0.2',
packages=['relationships'],
url='http://github.com/emre/relationships',
license='MIT',
author='Emre Yilmaz',
author_email='[email protected]',
description='redis backed user relationships',
install_requires=['redis'],

)

21 changes: 21 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ def test_blocked_by(self):

self.assertEqual(r(100).blocked(), set(['10000', '10001', '10002']))

def test_mutual_friends(self):

r = Relationship(redis_connection=self.redis_connection)

r('Emre').follow('Aydan')
r('Aydan').follow('Emre')

r('Emre').follow('Samed')
r('Samed').follow('Emre')

r('Emre').follow('Fka')
r('Fka').follow('Emre')

r('Fka').follow('Aydan')
r('Aydan').follow('Fka')

r('Fka').follow('Samed')
r('Samed').follow('Fka')

self.assertEqual(r('Emre').mutual_friends('Fka'), set(['Samed', 'Aydan']))


if __name__ == '__main__':
unittest.main()

0 comments on commit c1cf067

Please sign in to comment.