def test_invalid_reply_to_seed(self): reddit = Login.create_reddit_object() url = "https://www.reddit.com/r/AskReddit/comments/md0ny3/what_nonsensical_invasive_thoughts_do_you_have/" forest = Comments.Forest( reddit.submission(url = url), url ) metadata = { "body": "A test node.", "id": "test", "parent_id": "t1_inv@l1d", } reply = Comments.CommentNode(metadata) EncodeNode().encode(reply) try: forest.seed(reply) assert False except IndexError: assert True assert len(forest.root.replies) == 0
def test_init_method_with_comment_metadata(self): metadata = { "author": "u/test", "body": "A top level comment here.", "created_utc": "06-06-2006 06:06:06", "distinguished": None, "edited": False, "id": "qwerty1", "is_submitter": False, "link_id": "t3_asdfgh", "parent_id": "t3_abc123", "score": 666, "stickied": False } test_node = Comments.CommentNode(metadata) assert getattr(test_node, "author") == "u/test" assert getattr(test_node, "body") == "A top level comment here." assert getattr(test_node, "created_utc") == "06-06-2006 06:06:06" assert getattr(test_node, "distinguished") == None assert getattr(test_node, "edited") == False assert getattr(test_node, "id") == "qwerty1" assert getattr(test_node, "is_submitter") == False assert getattr(test_node, "link_id") == "t3_asdfgh" assert getattr(test_node, "parent_id") == "t3_abc123" assert getattr(test_node, "score") == 666 assert getattr(test_node, "stickied") == False
def test_init_method_set_root(self): reddit = Login.create_reddit_object() url = "https://www.reddit.com/r/AskReddit/comments/md0ny3/what_nonsensical_invasive_thoughts_do_you_have/" forest = Comments.Forest(reddit.submission(url=url), url) assert getattr(forest.root, "id") == "md0ny3"
def test_init_method_with_one_id_attribute(self): metadata = {"id": "test_id"} test_node = Comments.CommentNode(metadata) assert getattr(test_node, "id") == "test_id" assert getattr(test_node, "replies") == []
def test_sort_structured_method(self): reddit = Login.create_reddit_object() url = "https://www.reddit.com/r/AskReddit/comments/mg8fhz/if_you_could_tell_yourself_anything_what_would/" submission = reddit.submission(url = url) forest_replies = Comments.SortComments().sort_structured(submission, url) assert len(forest_replies) > 0
def test_sort_raw_method(self): reddit = Login.create_reddit_object() url = "https://www.reddit.com/r/AskReddit/comments/mg8fhz/if_you_could_tell_yourself_anything_what_would/" all_comments = [] submission = reddit.submission(url=url) Comments.SortComments().sort_raw(all_comments, submission) assert len(all_comments) > 0
def test_get_comments_init_method_titles_instance_variable(self): assert Comments.GetComments()._titles == [ "parent_id", "comment_id", "author", "date_created", "upvotes", "text", "edited", "is_submitter", "stickied" ]
def test_get_sort_no_raw_flag_is_included_with_limit(self): parser = MakeArgs.make_scraper_args() args = parser.parse_args([]) reddit = Login.create_reddit_object() url = "https://www.reddit.com/r/AskReddit/comments/mg8fhz/if_you_could_tell_yourself_anything_what_would/" submission = reddit.submission(url = url) test_get_sort = Comments.GetSort(args, submission, url) all_comments = test_get_sort.get_sort(args, 1) assert len(all_comments) == 1