Skip to content

Commit 58c3cf9

Browse files
committed
happy travis time
1 parent 4a22517 commit 58c3cf9

3 files changed

Lines changed: 53 additions & 43 deletions

File tree

‎.travis.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
notifications:
77
email:
88
- thierryschellenbach@gmail.com
9+
- tbarbugli@gmail.com
910
install:
1011
- pip install pep8==1.5.7 --use-mirrors
1112
- pip install python-coveralls --use-mirrors

‎stream/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def connect(api_key=None, api_secret=None, app_id=None, version='v1.0', timeout=
2424
# support for the heroku STREAM_URL syntax
2525
if stream_url and not api_key:
2626
pattern = re.compile(
27-
'https\:\/\/(\w+)\:(\w+).*app=(\d+)', re.IGNORECASE)
27+
'https\:\/\/(\w+)\:(\w+).*app_id=(\d+)', re.IGNORECASE)
2828
result = pattern.match(stream_url)
2929
if result and len(result.groups()) == 3:
3030
api_key, api_secret, app_id = result.groups()

‎stream/tests.py‎

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ def connect_debug():
1818

1919
random_postfix = str(random.randint(0, 1000000))
2020
client = connect_debug()
21-
user1 = client.feed('user', '1' + random_postfix)
22-
user2 = client.feed('user', '2' + random_postfix)
23-
aggregated2 = client.feed('aggregated', '2' + random_postfix)
24-
aggregated3 = client.feed('aggregated', '3' + random_postfix)
25-
topic1 = client.feed('topic', '1' + random_postfix)
26-
flat3 = client.feed('flat', '3' + random_postfix)
21+
22+
def getfeed(feed_slug, user_id):
23+
'''
24+
Adds the random postfix to the user id
25+
'''
26+
return client.feed(feed_slug, user_id + random_postfix)
27+
28+
user1 = getfeed('user', '1')
29+
user2 = getfeed('user', '2')
30+
aggregated2 = getfeed('aggregated', '2')
31+
aggregated3 = getfeed('aggregated', '3')
32+
topic1 = getfeed('topic', '1')
33+
flat3 = getfeed('flat', '3')
2734

2835

2936
class ClientTest(TestCase):
@@ -39,15 +46,15 @@ def setUp(self):
3946
self.flat3 = flat3
4047

4148
def test_heroku(self):
42-
url = 'https://thierry:pass@getstream.io/?app=1'
49+
url = 'https://thierry:pass@getstream.io/?app_id=1'
4350
os.environ['STREAM_URL'] = url
4451
client = stream.connect()
4552
self.assertEqual(client.api_key, 'thierry')
4653
self.assertEqual(client.api_secret, 'pass')
4754
self.assertEqual(client.app_id, '1')
4855

4956
def test_heroku_real(self):
50-
url = 'https://bvt88g4kvc63:twc5ywfste5bm2ngqkzs7ukxk3pn96yweghjrxcmcrarnt3j4dqj3tucbhym5wfd@getstream.io/?app=669'
57+
url = 'https://bvt88g4kvc63:twc5ywfste5bm2ngqkzs7ukxk3pn96yweghjrxcmcrarnt3j4dqj3tucbhym5wfd@getstream.io/?app_id=669'
5158
os.environ['STREAM_URL'] = url
5259
client = stream.connect()
5360
self.assertEqual(client.api_key, 'bvt88g4kvc63')
@@ -56,7 +63,7 @@ def test_heroku_real(self):
5663
self.assertEqual(client.app_id, '669')
5764

5865
def test_heroku_overwrite(self):
59-
url = 'https://thierry:pass@getstream.io/?app=1'
66+
url = 'https://thierry:pass@getstream.io/?app_id=1'
6067
os.environ['STREAM_URL'] = url
6168
client = stream.connect('a', 'b', 'c')
6269
self.assertEqual(client.api_key, 'a')
@@ -67,7 +74,7 @@ def test_token_retrieval(self):
6774
self.user1.token
6875

6976
def test_add_activity(self):
70-
feed = client.feed('user', 'py1')
77+
feed = getfeed('user', 'py1')
7178
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
7279
response = feed.add_activity(activity_data)
7380
activity_id = response['id']
@@ -77,10 +84,10 @@ def test_add_activity(self):
7784
def test_add_activity_to(self):
7885
activity_data = {
7986
'actor': 1, 'verb': 'tweet', 'object': 1,
80-
'to': ['user:pyto1']
87+
'to': [getfeed('user', 'pyto1').id]
8188
}
8289
response = self.user1.add_activity(activity_data)
83-
feed = client.feed('user', 'pyto1')
90+
feed = getfeed('user', 'pyto1')
8491
activity_id = response['id']
8592
activities = feed.get(limit=1)['results']
8693
self.assertEqual(activities[0]['id'], activity_id)
@@ -114,7 +121,7 @@ def test_add_activities(self):
114121
self.assertEqual(get_activity_ids, activity_ids[::-1])
115122

116123
def test_add_activities_to(self):
117-
to = ['user:pyto2', 'user:pyto3']
124+
to = [getfeed('user', 'pyto2').id, getfeed('user', 'pyto3').id]
118125
activity_data = [
119126
{'actor': 1, 'verb': 'tweet', 'object': 1, 'to': to},
120127
{'actor': 2, 'verb': 'watch', 'object': 2, 'to': to},
@@ -125,47 +132,47 @@ def test_add_activities_to(self):
125132
get_activity_ids = [a['id'] for a in activities]
126133
self.assertEqual(get_activity_ids, activity_ids[::-1])
127134
# test first target
128-
feed = client.feed('user', 'pyto2')
135+
feed = getfeed('user', 'pyto2')
129136
activities = feed.get(limit=2)['results']
130137
get_activity_ids = [a['id'] for a in activities]
131138
self.assertEqual(get_activity_ids, activity_ids[::-1])
132139
# test second target
133-
feed = client.feed('user', 'pyto3')
140+
feed = getfeed('user', 'pyto3')
134141
activities = feed.get(limit=2)['results']
135142
get_activity_ids = [a['id'] for a in activities]
136143
self.assertEqual(get_activity_ids, activity_ids[::-1])
137144

138145
def test_follow(self):
139-
feed = client.feed('user', 'test_follow')
140-
agg_feed = client.feed('aggregated', 'test_follow')
146+
feed = getfeed('user', 'test_follow')
147+
agg_feed = getfeed('aggregated', 'test_follow')
141148
actor_id = random.randint(10, 100000)
142149
activity_data = {'actor': actor_id, 'verb': 'tweet', 'object': 1}
143150
activity_id = feed.add_activity(activity_data)['id']
144-
agg_feed.follow('user', 'test_follow')
151+
agg_feed.follow(feed.slug, feed.user_id)
145152
time.sleep(10)
146153
activities = agg_feed.get(limit=3)['results']
147154
activity = self._get_first_aggregated_activity(activities)
148155
activity_id_found = activity['id'] if activity is not None else None
149156
self.assertEqual(activity_id_found, activity_id)
150157

151158
def test_follow_private(self):
152-
feed = client.feed('secret', 'py1')
153-
agg_feed = client.feed('aggregated', 'test_follow_private')
159+
feed = getfeed('secret', 'py1')
160+
agg_feed = getfeed('aggregated', 'test_follow_private')
154161
actor_id = random.randint(10, 100000)
155162
activity_data = {'actor': actor_id, 'verb': 'tweet', 'object': 1}
156163
activity_id = feed.add_activity(activity_data)['id']
157-
agg_feed.follow('secret', 'py1')
164+
agg_feed.follow(feed.slug, feed.user_id)
158165
time.sleep(10)
159166
activities = agg_feed.get(limit=3)['results']
160167
activity = self._get_first_aggregated_activity(activities)
161168
activity_id_found = activity['id'] if activity is not None else None
162169
self.assertEqual(activity_id_found, activity_id)
163170

164171
def test_flat_follow(self):
165-
feed = client.feed('user', 'test_flat_follow' + random_postfix)
172+
feed = getfeed('user', 'test_flat_follow')
166173
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
167174
activity_id = feed.add_activity(activity_data)['id']
168-
self.flat3.follow('user', 'test_flat_follow' + random_postfix)
175+
self.flat3.follow(feed.slug, feed.user_id)
169176
time.sleep(10)
170177
activities = self.flat3.get(limit=3)['results']
171178
activity = self._get_first_activity(activities)
@@ -196,59 +203,61 @@ def test_unfollow(self):
196203
self.assertNotEqual(activity_id_found, activity_id)
197204

198205
def test_empty_followings(self):
199-
asocial = client.feed('user', 'asocialpython')
206+
asocial = getfeed('user', 'asocialpython')
200207
followings = asocial.following()
201208
self.assertEqual(followings['results'], [])
202209

203210
def test_get_followings(self):
204-
social = client.feed('user', 'psocial')
211+
social = getfeed('user', 'psocial')
205212
social.follow('user', 'apy')
206213
social.follow('user', 'bpy')
207214
social.follow('user', 'cpy')
208215
followings = social.following(offset=0, limit=2)
209216
self.assertEqual(len(followings['results']), 2)
210-
self.assertEqual(followings['results'][0]['feed_id'], 'user:psocial')
217+
self.assertEqual(followings['results'][0]['feed_id'], social.id)
211218
self.assertEqual(followings['results'][0]['target_id'], 'user:cpy')
212219
followings = social.following(offset=1, limit=2)
213220
self.assertEqual(len(followings['results']), 2)
214-
self.assertEqual(followings['results'][0]['feed_id'], 'user:psocial')
221+
self.assertEqual(followings['results'][0]['feed_id'], social.id)
215222
self.assertEqual(followings['results'][0]['target_id'], 'user:bpy')
216223

217224
def test_empty_followers(self):
218-
asocial = client.feed('user', 'asocialpython')
225+
asocial = getfeed('user', 'asocialpython')
219226
followers = asocial.followers()
220227
self.assertEqual(len(followers['results']), 0)
221228
self.assertEqual(followers['results'], [])
222229

223230
def test_get_followers(self):
224-
social = client.feed('user', 'psocial')
225-
client.feed('user', 'spammy1').follow('user', 'psocial')
226-
client.feed('user', 'spammy2').follow('user', 'psocial')
227-
client.feed('user', 'spammy3').follow('user', 'psocial')
231+
social = getfeed('user', 'psocial')
232+
spammy1 = getfeed('user', 'spammy1')
233+
spammy2 = getfeed('user', 'spammy2')
234+
spammy3 = getfeed('user', 'spammy3')
235+
for feed in [spammy1, spammy2, spammy3]:
236+
feed.follow('user', social.user_id)
228237
followers = social.followers(offset=0, limit=2)
229238
self.assertEqual(len(followers['results']), 2)
230-
self.assertEqual(followers['results'][0]['feed_id'], 'user:spammy3')
231-
self.assertEqual(followers['results'][0]['target_id'], 'user:psocial')
239+
self.assertEqual(followers['results'][0]['feed_id'], spammy3.id)
240+
self.assertEqual(followers['results'][0]['target_id'], social.id)
232241
followers = social.followers(offset=1, limit=2)
233242
self.assertEqual(len(followers['results']), 2)
234-
self.assertEqual(followers['results'][0]['feed_id'], 'user:spammy2')
235-
self.assertEqual(followers['results'][0]['target_id'], 'user:psocial')
243+
self.assertEqual(followers['results'][0]['feed_id'], spammy2.id)
244+
self.assertEqual(followers['results'][0]['target_id'], social.id)
236245

237246
def test_empty_do_i_follow(self):
238-
social = client.feed('user', 'psocial')
247+
social = getfeed('user', 'psocial')
239248
social.follow('user', 'apy')
240249
social.follow('user', 'bpy')
241250
followings = social.following(feeds=['user:missingpy'])
242251
self.assertEqual(len(followings['results']), 0)
243252
self.assertEqual(followings['results'], [])
244253

245254
def test_do_i_follow(self):
246-
social = client.feed('user', 'psocial')
255+
social = getfeed('user', 'psocial')
247256
social.follow('user', 'apy')
248257
social.follow('user', 'bpy')
249258
followings = social.following(feeds=['user:apy'])
250259
self.assertEqual(len(followings['results']), 1)
251-
self.assertEqual(followings['results'][0]['feed_id'], 'user:psocial')
260+
self.assertEqual(followings['results'][0]['feed_id'], social.id)
252261
self.assertEqual(followings['results'][0]['target_id'], 'user:apy')
253262

254263
def test_get(self):
@@ -271,7 +280,7 @@ def test_get(self):
271280
self.assertEqual(activities[0]['id'], activity_id)
272281

273282
def test_mark_read(self):
274-
notification_feed = client.feed('notification', 'py3')
283+
notification_feed = getfeed('notification', 'py3')
275284
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
276285
notification_feed.add_activity(activity_data)
277286
activity_data = {'actor': 2, 'verb': 'add', 'object': 2}
@@ -287,7 +296,7 @@ def test_mark_read(self):
287296
self.assertTrue(activity['is_read'])
288297

289298
def test_mark_read_by_id(self):
290-
notification_feed = client.feed('notification', 'py2')
299+
notification_feed = getfeed('notification', 'py2')
291300
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
292301
notification_feed.add_activity(activity_data)['id']
293302
activity_data = {'actor': 2, 'verb': 'add', 'object': 2}
@@ -432,7 +441,7 @@ def test_wrong_feed_spec(self):
432441
'5crf3bhfzesnMISSING',
433442
'tfq2sdqpj9g446sbv653x3aqmgn33hsn8uzdc9jpskaw8mj6vsnhzswuwptuj9su'
434443
)
435-
self.assertRaises(TypeError, lambda: self.c.feed('user1'))
444+
self.assertRaises(TypeError, lambda: getfeed('user1'))
436445

437446
def test_serialization(self):
438447
today = datetime.date.today()

0 commit comments

Comments
 (0)