Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])
Esempio 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])