Skip to content

Commit 387691e

Browse files
committed
added a test for testing uniqueness
1 parent e470acd commit 387691e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎stream/tests.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def connect_debug():
2020
user1 = client.feed('user:1')
2121
aggregated2 = client.feed('aggregated:2')
2222
aggregated3 = client.feed('aggregated:3')
23+
topic1 = client.feed('topic:1')
2324
flat3 = client.feed('flat:3')
2425

2526

@@ -31,6 +32,7 @@ def setUp(self):
3132
self.user1 = user1
3233
self.aggregated2 = aggregated2
3334
self.aggregated3 = aggregated3
35+
self.topic1 = topic1
3436
self.flat3 = flat3
3537

3638
def test_heroku(self):
@@ -184,6 +186,26 @@ def test_uniqueness(self):
184186
self.assertDatetimeAlmostEqual(activities[0]['time'], utcnow)
185187
self.assertClearlyNotEqual(activities[1]['time'], utcnow)
186188

189+
def test_uniqueness_topic(self):
190+
'''
191+
In order for things to be considere unique they need:
192+
a.) The same time and activity data, or
193+
b.) The same time and foreign id
194+
'''
195+
# follow both the topic and the user
196+
self.flat3.follow('topic:1')
197+
self.flat3.follow('user:1')
198+
# add the same activity twice
199+
now = datetime.datetime.now(tzlocal())
200+
tweet = 'My Way %s' % random.randint(10, 100000)
201+
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1, 'time': now, 'tweet': tweet}
202+
self.topic1.add_activity(activity_data)
203+
self.user1.add_activity(activity_data)
204+
# verify that flat3 contains the activity exactly once
205+
response = self.flat3.get(limit=3)
206+
activity_tweets = [a.get('tweet') for a in response['results']]
207+
self.assertEqual(activity_tweets.count(tweet), 1)
208+
187209
def test_uniqueness_foreign_id(self):
188210
now = datetime.datetime.now(tzlocal())
189211
utcnow = datetime.datetime.utcnow()
@@ -196,6 +218,7 @@ def test_uniqueness_foreign_id(self):
196218
self.assertEqual(activities[0]['object'], '3')
197219
self.assertEqual(activities[0]['foreign_id'], 'tweet:11')
198220
self.assertDatetimeAlmostEqual(activities[0]['time'], utcnow)
221+
self.assertNotEqual(activities[1]['foreign_id'], 'tweet:11')
199222

200223
def test_missing_actor(self):
201224
activity_data = {'verb': 'tweet', 'object':

0 commit comments

Comments
 (0)