def test_should_get_activity_around_post(self): #activity means reposts + comments data = {'guid':'123', 'pubid':'456', 'type':'post', 'caption':'blah', 'content':'blah', 'comment':'blah', 'url':'http://meme.yahoo.com/p/123', 'timestamp':'1234567890', 'repost_count':'12345'} post = Post(data) yql_mock = Mock() activity_result = Mock() activity_result.rows = [] activity_result.rows.append({'guid':'123', 'pubid':'123', 'type':'repost', 'caption':'blah', 'content':'blah', 'comment':'blah', 'url':'http://meme.yahoo.com/p/123', 'timestamp':'1234567890', 'repost_count':'12345'}) activity_result.rows.append({'guid':'456', 'pubid':'456', 'type':'comment', 'caption':'blah', 'content':'blah', 'comment':'blah', 'url':'http://meme.yahoo.com/p/456', 'timestamp':'1234567890', 'repost_count':'12345'}) yql_query = 'SELECT * FROM meme.post.info(%d) WHERE owner_guid="%s" AND pubid="%s"' % (2, '123', '456') when(yql_mock).execute(yql_query).thenReturn(activity_result) repository = PostRepository() repository.yql = yql_mock activity = repository.activity('123', '456', 2) assert len(activity) == 2 assert activity[0].type == 'repost' assert activity[1].type == 'comment'
def test_should_get_posts_activity(self): yql_query = 'SELECT * FROM meme.post.info(2) WHERE owner_guid = "123guid" AND pubid = "123pubid"' yql_mock = Mock() when(yql_mock).execute(yql_query).thenReturn(self.multiple_query_result) post_repository = PostRepository() post_repository.yql = yql_mock posts = post_repository.activity("123guid", "123pubid", 2) assert len(posts) == 2 assert posts[0].guid == "123" assert posts[1].guid == "456"