Exemplo n.º 1
0
 def test_comment_order_invalid_sticky(self):
     self.link.sticky_comment_id = 101
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order,
         [100, 101, 102, 104, 105, 106, 103, 107, 108, 110, 109])
Exemplo n.º 2
0
 def test_comment_order_full_asc(self):
     sort = operators.asc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500)
     builder._get_comments()
     self.assertEqual(
         builder.comment_order,
         [109, 108, 107, 100, 103, 102, 106, 105, 101, 104, 110])
Exemplo n.º 3
0
 def test_comment_order_permalink(self):
     sort = operators.desc("_confidence")
     comment = MagicMock()
     comment._id = 100
     builder = CommentBuilder(self.link, sort, comment=comment, num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order,
                      [100, 101, 102, 104, 105, 106, 103])
Exemplo n.º 4
0
 def test_comment_order_children(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link,
                              sort,
                              children=[101, 102, 103],
                              num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [101, 102, 104, 105, 106, 103])
Exemplo n.º 5
0
 def test_comment_order_permalink_context(self):
     sort = operators.desc("_confidence")
     comment = MagicMock()
     comment._id = 104
     builder = CommentBuilder(
         self.link, sort, comment=comment, context=3, num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [100, 102, 104])
Exemplo n.º 6
0
 def test_comment_order_invalid_permalink_defocus(self):
     sort = operators.desc("_confidence")
     comment = MagicMock()
     comment._id = 999999
     builder = CommentBuilder(self.link, sort, comment=comment, num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order,
         [100, 101, 102, 104, 105, 106, 103, 107, 108, 110, 109])
Exemplo n.º 7
0
 def test_comment_order_invalid_sticky(self):
     self.link.sticky_comment_id = 101
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500)
     builder._get_comments()
     self.assertEqual(
         builder.comment_order,
         [100, 101, 102, 104, 105, 106, 103, 107, 108, 110, 109])
Exemplo n.º 8
0
 def test_comment_order_depth(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500, max_depth=1)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order, [100, 107, 108, 109])
     self.assertEqual(builder.missing_root_comments, set())
     self.assertEqual(builder.missing_root_count, 0)
Exemplo n.º 9
0
 def test_comment_order_limit(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=5)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order, [100, 101, 102, 104, 105])
     self.assertEqual(builder.missing_root_comments, {107, 108, 109})
     self.assertEqual(builder.missing_root_count, 4)
Exemplo n.º 10
0
 def test_comment_order_qa_multiple_responders(self):
     self.link.responder_ids = ("c", "d", "e")
     sort = operators.desc("_qa")
     builder = CommentBuilder(self.link, sort, num=1500)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order,
                      [100, 102, 104, 105, 106, 103, 107, 108, 109])
     self.assertEqual(builder.missing_root_comments, set())
     self.assertEqual(builder.missing_root_count, 0)
Exemplo n.º 11
0
 def test_comment_order_permalink(self):
     sort = operators.desc("_confidence")
     comment = MagicMock()
     comment._id = 100
     builder = CommentBuilder(self.link, sort, comment=comment, num=1500)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order, [100, 101, 102, 104, 105, 106, 103])
     self.assertEqual(builder.missing_root_comments, set())
     self.assertEqual(builder.missing_root_count, 0)
Exemplo n.º 12
0
 def test_comment_order_full_asc(self):
     sort = operators.asc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(
         comment_order,
         [109, 108, 107, 100, 103, 102, 106, 105, 101, 104, 110])
     self.assertEqual(builder.missing_root_comments, set())
     self.assertEqual(builder.missing_root_count, 0)
Exemplo n.º 13
0
 def test_comment_order_children_limit(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link,
                              sort,
                              children=[107, 108, 109],
                              num=3)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order, [107, 108, 110])
     self.assertEqual(builder.missing_root_comments, {109})
     self.assertEqual(builder.missing_root_count, 1)
Exemplo n.º 14
0
 def test_comment_order_children(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link,
                              sort,
                              children=[101, 102, 103],
                              num=1500)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order, [101, 102, 104, 105, 106, 103])
     self.assertEqual(builder.missing_root_comments, set())
     self.assertEqual(builder.missing_root_count, 0)
Exemplo n.º 15
0
 def test_comment_order_children_limit_bug(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link,
                              sort,
                              children=[101, 102, 103],
                              num=3)
     builder.load_comment_order()
     comment_order = [
         comment_tuple.comment_id
         for comment_tuple in builder.ordered_comment_tuples
     ]
     self.assertEqual(comment_order, [101, 102, 104])
     # missing_root_comments SHOULD be {103}, but there's a bug here.
     # if the requested children are not root level but we don't show some
     # of them we should add a MoreChildren to allow a subsequent request
     # to get the missing comments.
     self.assertEqual(builder.missing_root_comments, set())
     self.assertEqual(builder.missing_root_count, 0)
Exemplo n.º 16
0
def get_comment_items(srs, src, count=4):
    """Get hot links from srs, plus top comment from each link."""
    link_fullnames = normalized_hot([sr._id for sr in srs])
    hot_links = Link._by_fullname(link_fullnames[:count], return_dict=False)
    top_comments = []
    for link in hot_links:
        builder = CommentBuilder(link,
                                 operators.desc('_confidence'),
                                 comment=None,
                                 context=None,
                                 load_more=False)
        listing = NestedListing(builder, num=1,
                                parent_name=link._fullname).listing()
        top_comments.extend(listing.things)
    srs = Subreddit._byID([com.sr_id for com in top_comments])
    links = Link._byID([com.link_id for com in top_comments])
    comment_items = [
        ExploreItem(TYPE_COMMENT, src, srs[com.sr_id], links[com.link_id], com)
        for com in top_comments
    ]
    return comment_items
Exemplo n.º 17
0
 def test_comment_order_children_limit(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(
         self.link, sort, children=[107, 108, 109], num=3)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [107, 108, 110])
Exemplo n.º 18
0
 def test_comment_order_children(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(
         self.link, sort, children=[101, 102, 103], num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [101, 102, 104, 105, 106, 103])
Exemplo n.º 19
0
 def test_comment_order_depth(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500, max_depth=1)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [100, 107, 108, 109])
Exemplo n.º 20
0
 def test_comment_order_limit(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=5)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [100, 101, 102, 104, 105])
Exemplo n.º 21
0
 def test_comment_order_full_asc(self):
     sort = operators.asc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500)
     builder._get_comments()
     self.assertEqual(builder.comment_order,
         [109, 108, 107, 100, 103, 102, 106, 105, 101, 104, 110])
Exemplo n.º 22
0
 def test_comment_order_limit(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=5)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [100, 101, 102, 104, 105])
Exemplo n.º 23
0
 def test_comment_order_depth(self):
     sort = operators.desc("_confidence")
     builder = CommentBuilder(self.link, sort, num=1500, max_depth=1)
     builder._get_comments()
     self.assertEqual(builder.comment_order, [100, 107, 108, 109])