This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
177 lines (108 loc) · 4.37 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import redis
try:
import unittest2 as unittest
except ImportError:
import unittest
from relationships import Relationship
from relationships.relationship import default_key_list
class RelationshipsTestCase(unittest.TestCase):
def setUp(self):
self.redis_connection = redis.StrictRedis(
host='localhost',
port=6379,
db=15)
def tearDown(self):
self.redis_connection.flushdb()
def test_no_redis_connection(self):
r = Relationship()
self.assertEqual(r.redis_connection.connection_pool.connection_kwargs.get("host"), "localhost")
self.assertEqual(r.redis_connection.connection_pool.connection_kwargs.get("db"), 0)
self.assertEqual(r.redis_connection.connection_pool.connection_kwargs.get("port"), 6379)
def test_follow(self):
r = Relationship(redis_connection=self.redis_connection)
r(1).follow(42)
self.assertEqual(r(1).is_following(42), True)
self.assertEqual(r(42).is_follower(1), True)
def test_unfollow(self):
r = Relationship(redis_connection=self.redis_connection)
r(2).follow(42)
r(2).unfollow(42)
self.assertEqual(r(2).is_following(42), False)
self.assertEqual(r(42).is_follower(2), False)
def test_block(self):
r = Relationship(redis_connection=self.redis_connection)
r(1).block(42)
self.assertEqual(r(1).is_blocked(42), True)
self.assertEqual(r(42).is_blocked_by(1), True)
def test_unblock(self):
r = Relationship(redis_connection=self.redis_connection)
r(2).block(42)
r(2).unblock(42)
self.assertEqual(r(42).is_blocked_by(2), False)
self.assertEqual(r(2).is_blocked(42), False)
def test_friends(self):
r = Relationship(redis_connection=self.redis_connection)
r(5).follow(1)
r(1).follow(5)
r(100).follow(1)
r(1).follow(100)
self.assertEqual(r(1).friends(), set(['100', '5']))
def test_follower_count(self):
r = Relationship(redis_connection=self.redis_connection)
r(1000).follow(2000)
r(1001).follow(2000)
r(1002).follow(2000)
self.assertEqual(r(2000).follower_count(), 3)
def test_following_count(self):
r = Relationship(redis_connection=self.redis_connection)
r(1000).follow(2000)
r(1000).follow(1001)
self.assertEqual(r(1000).following_count(), 2)
def test_blocked_by_count(self):
r = Relationship(redis_connection=self.redis_connection)
r(1000).block(2000)
r(1001).block(2000)
r(1002).block(2000)
self.assertEqual(r(2000).blocked_count(), 3)
def test_blocking_count(self):
r = Relationship(redis_connection=self.redis_connection)
r(1000).block(2000)
r(1000).block(2001)
self.assertEqual(r(1000).block_count(), 2)
def test_followers(self):
r = Relationship(redis_connection=self.redis_connection)
r(10000).follow(100)
r(10001).follow(100)
r(10002).follow(100)
self.assertEqual(r(100).followers(), set(['10000', '10001', '10002']))
def test_following(self):
r = Relationship(redis_connection=self.redis_connection)
r(100).follow(900)
r(100).follow(901)
self.assertEqual(r(100).following(), set(['900', '901']))
def test_blocked(self):
r = Relationship(redis_connection=self.redis_connection)
r(100).block(900)
r(100).block(901)
self.assertEqual(r(100).blocks(), set(['900', '901']))
def test_blocked_by(self):
r = Relationship(redis_connection=self.redis_connection)
r(10000).block(100)
r(10001).block(100)
r(10002).block(100)
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()