Exemplo n.º 1
0
 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'
Exemplo n.º 2
0
    def test_should_get_only_one_meme_post(self):
        yql_query = 'SELECT * FROM meme.posts(1) WHERE owner_guid = "foo123bar"'
        yql_mock = Mock()
        when(yql_mock).execute(yql_query).thenReturn(self.single_query_result)

        post_repository = PostRepository()
        post_repository.yql = yql_mock
        posts = post_repository.get_by_meme("foo123bar", 1)
        assert len(posts) == 1
        assert posts[0].guid == "123"
Exemplo n.º 3
0
    def test_should_search_posts(self):
        yql_query = 'SELECT * FROM meme.search(5) WHERE query = "a sample query"'
        yql_mock = Mock()
        when(yql_mock).execute(yql_query).thenReturn(self.single_query_result)

        post_repository = PostRepository()
        post_repository.yql = yql_mock
        posts = post_repository.search("a sample query", 5)
        assert len(posts) == 1
        assert posts[0].guid == "123"
Exemplo n.º 4
0
    def test_should_get_one_post(self):
        yql_query = 'SELECT * FROM meme.posts WHERE owner_guid = "123guid" and pubid = "123pubid"'
        yql_mock = Mock()
        when(yql_mock).execute(yql_query).thenReturn(self.single_query_result)

        post_repository = PostRepository()
        post_repository.yql = yql_mock
        posts = post_repository.get("123guid", "123pubid")
        assert len(posts) == 1
        assert posts[0].guid == "123"
Exemplo n.º 5
0
    def test_should_get_meme_posts(self):
        yql_query = 'SELECT * FROM meme.posts(2) WHERE owner_guid = "foo123bar"'
        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.get_by_meme("foo123bar", 2)
        assert len(posts) == 2
        assert posts[0].guid == "123"
        assert posts[1].guid == "456"
Exemplo n.º 6
0
    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"
Exemplo n.º 7
0
    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"
Exemplo n.º 8
0
    def test_should_get_most_reposted_posts_of_a_meme(self):
        yql_query = 'SELECT * FROM meme.search(2) WHERE query = "from:gchapiewski sort:reposts type:text"'
        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.get_most_reposted_by_meme("gchapiewski", "text", 2)

        assert len(posts) == 2
        assert posts[0].guid == "123"
        assert posts[1].guid == "456"
Exemplo n.º 9
0
    def test_should_search_posts(self):
        yql_mock = Mock()
        yql_query = 'SELECT * FROM meme.search(0,10) WHERE query="a sample query"'
        query_result = Mock()
        query_result.rows = {'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.count = 1
        when(yql_mock).execute(yql_query).thenReturn(query_result)

        repository = PostRepository()
        repository.yql = yql_mock

        posts = repository.search('a sample query', 10)
        assert len(posts) == 1
        assert posts[0].guid == '123'
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    def test_should_get_meme_posts(self):
        yql_mock = Mock()
        yql_query = 'SELECT * FROM meme.posts(2) WHERE owner_guid="foo123bar"'
        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.posts('foo123bar', 2)
        assert len(posts) == 2
        assert posts[0].guid == '123'
        assert posts[1].guid == '456'