Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5c49f5

Browse files
committed
Raise clear error when to field is supplied as a string
1 parent a3bc83b commit c5c49f5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

stream/feed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def add_activity(self, activity_data):
4646
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
4747
activity_id = feed.add_activity(activity_data)
4848
'''
49+
if activity_data.get('to') and type(activity_data.get('to')) is str:
50+
raise TypeError('please provide the activity\'s to field as a list not a string')
51+
4952
if activity_data.get('to'):
5053
activity_data['to'] = self.add_to_signature(activity_data['to'])
5154

stream/tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ def test_add_activity_to(self):
155155
# and the flat feed
156156
activities = team_follower_feed.get(limit=1)['results']
157157
self.assertFirstActivityIDNotEqual(activities, activity_id)
158+
159+
160+
def test_add_activity_to_type_error(self):
161+
user_feed = getfeed('user', '1')
162+
activity_data = {
163+
'actor': 1, 'verb': 'tweet', 'object': 1,
164+
'to': 'string'
165+
}
166+
167+
with self.assertRaises(TypeError):
168+
user_feed.add_activity(activity_data)
158169

159170
def assertFirstActivityIDEqual(self, activities, correct_activity_id):
160171
activity_id = None

0 commit comments

Comments
 (0)