def test_should_get_popular_posts_by_language(self): yql_query = 'SELECT * FROM meme.popular(2) WHERE locale = "pt"' 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.popular("pt", 2) assert len(posts) == 2 assert posts[0].guid == "123" assert posts[1].guid == "456"
def test_should_get_popular_posts_by_language(self): yql_mock = Mock() yql_query = 'SELECT * FROM meme.popular WHERE locale="pt"' query_result = Mock() query_result.rows = [] query_result.rows.append({'guid':'123', 'pubid':'123', 'type':'post', 'caption':'blah', 'content':'blah', 'comment':'blah', 'url':'http://meme.yahoo.com/p/123', 'timestamp':'1234567890', 'repost_count':'12345'}) query_result.rows.append({'guid':'456', 'pubid':'456', 'type':'post', 'caption':'blah', 'content':'blah', 'comment':'blah', 'url':'http://meme.yahoo.com/p/456', 'timestamp':'1234567890', 'repost_count':'12345'}) query_result.count = 2 when(yql_mock).execute(yql_query).thenReturn(query_result) repository = PostRepository() repository.yql = yql_mock posts = repository.popular('pt') assert len(posts) == 2