Skip to content

Commit ec9dd85

Browse files
committed
testing for improved to support
1 parent 60cb5c9 commit ec9dd85

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎stream/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__copyright__ = 'Copyright 2014, Thierry Schellenbach'
66
__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach']
77
__license__ = 'BSD'
8-
__version__ = '2.0.2'
8+
__version__ = '2.0.3'
99
__maintainer__ = 'Thierry Schellenbach'
1010
__email__ = 'thierryschellenbach@gmail.com'
1111
__status__ = 'Production'

‎stream/client.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, api_key, api_secret, app_id, version='v1.0', timeout=3.0, bas
4747
self.base_url = base_url
4848
if os.environ.get('LOCAL'):
4949
self.base_url = 'http://localhost:8000/api/'
50+
self.timeout = 20
5051
self.session = requests.Session()
5152
# TODO: turn this back on after we verify it doesnt retry on slower requests
5253
self.session.mount(self.base_url, HTTPAdapter(max_retries=0))
@@ -102,7 +103,7 @@ def _make_request(self, method, relative_url, signature, params=None, data=None)
102103
parsed_result = serializer.loads(response.text)
103104
except ValueError:
104105
parsed_result = None
105-
if parsed_result.get('exception') or response.status_code >= 500:
106+
if parsed_result is None or parsed_result.get('exception') or response.status_code >= 500:
106107
self.raise_exception(parsed_result, status_code=response.status_code)
107108
return parsed_result
108109

‎stream/tests.py‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,33 @@ def test_add_activity(self):
100100
self.assertEqual(activities[0]['id'], activity_id)
101101

102102
def test_add_activity_to(self):
103+
# test for sending an activities to the team feed using to
104+
feeds = ['user', 'team', 'team_follower']
105+
user_feed, team_feed, team_follower_feed = map(lambda x: getfeed('user', x), feeds)
106+
team_follower_feed.follow(team_feed.slug, team_feed.user_id)
103107
activity_data = {
104108
'actor': 1, 'verb': 'tweet', 'object': 1,
105-
'to': [getfeed('user', 'pyto1').id]
109+
'to': [team_feed.id]
106110
}
107-
response = self.user1.add_activity(activity_data)
108-
feed = getfeed('user', 'pyto1')
111+
response = user_feed.add_activity(activity_data)
109112
activity_id = response['id']
110-
activities = feed.get(limit=1)['results']
113+
# see if the new activity is also in the team feed
114+
activities = team_feed.get(limit=1)['results']
111115
self.assertEqual(activities[0]['id'], activity_id)
112-
116+
self.assertEqual(activities[0]['origin'], team_feed.id)
117+
# see if the fanout process also works
118+
activities = team_follower_feed.get(limit=1)['results']
119+
self.assertEqual(activities[0]['id'], activity_id)
120+
self.assertEqual(activities[0]['origin'], team_feed.id)
121+
# and validate removing also works
122+
self.user1.remove_activity(response['id'])
123+
# check the user pyto feed
124+
activities = team_feed.get(limit=1)['results']
125+
self.assertNotEqual(activities[0]['id'], activity_id)
126+
# and the flat feed
127+
activities = team_follower_feed.get(limit=1)['results']
128+
self.assertNotEqual(activities[0]['id'], activity_id)
129+
113130
def test_remove_activity(self):
114131
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
115132
activity_id = self.user1.add_activity(activity_data)['id']
@@ -160,7 +177,7 @@ def test_add_activities_to(self):
160177
get_activity_ids = [a['id'] for a in activities]
161178
self.assertEqual(get_activity_ids, activity_ids[::-1])
162179

163-
def test_follow(self):
180+
def test_follow_and_source(self):
164181
feed = getfeed('user', 'test_follow')
165182
agg_feed = getfeed('aggregated', 'test_follow')
166183
actor_id = random.randint(10, 100000)
@@ -171,6 +188,7 @@ def test_follow(self):
171188
activities = agg_feed.get(limit=3)['results']
172189
activity = self._get_first_aggregated_activity(activities)
173190
activity_id_found = activity['id'] if activity is not None else None
191+
self.assertEqual(activity['origin'], feed.id)
174192
self.assertEqual(activity_id_found, activity_id)
175193

176194
def test_follow_private(self):

0 commit comments

Comments
 (0)