def test_report(handle_spam): try: msg = Fake({ "owner": { "name": "El'endia Starman", "id": 1, "is_moderator": False }, "room": { "id": 11540, "name": "Charcoal HQ", "_client": { "host": "stackexchange.com" } }, "_client": { "host": "stackexchange.com" }, "id": 1337 }) assert chatcommands.report("test", original_msg=msg) == "Post 1: That does not look like a valid post URL." assert chatcommands.report("one two three four five plus-an-extra", original_msg=msg) == ( "To avoid SmokeDetector reporting posts too slowly, you can report at most 5 posts at a time. This is to avoid " "SmokeDetector's chat messages getting rate-limited too much, which would slow down reports." ) assert chatcommands.report('http://stackoverflow.com/q/1', original_msg=msg) == \ "Post 1: Could not find data for this post in the API. It may already have been deleted." # Valid post assert chatcommands.report('http://stackoverflow.com/a/1732454', original_msg=msg) is None _, call = handle_spam.call_args_list[0] assert isinstance(call["post"], Post) assert call["reasons"] == ["Manually reported answer"] assert call["why"] == "Post manually reported by user *El'endia Starman* in room *Charcoal HQ*.\n" # Don't re-report GlobalVars.latest_questions = [('stackoverflow.com', '1732454', 'RegEx match open tags except XHTML self-contained tags')] assert chatcommands.report('http://stackoverflow.com/a/1732454', original_msg=msg).startswith("Post 1: Already recently " "reported") # Can use report command multiple times in 30s if only one URL was used assert chatcommands.report('http://stackoverflow.com/q/1732348', original_msg=msg) is None finally: GlobalVars.blacklisted_users = [] GlobalVars.latest_questions = []
def test_report(handle_spam): # Documentation: The process before scanning the post is identical regardless of alias_used. # No need to supply alias_used to test that part. # If no alias_used is supplied, it acts as if it's "scan" try: msg = Fake({ "owner": { "name": "El'endia Starman", "id": 1, "is_moderator": False }, "room": { "id": 11540, "name": "Charcoal HQ", "_client": { "host": "stackexchange.com" } }, "_client": { "host": "stackexchange.com" }, "id": 1337 }) assert chatcommands.report( "test", original_msg=msg, alias_used="report" ) == "Post 1: That does not look like a valid post URL." assert chatcommands.report( "one two three four five plus-an-extra", original_msg=msg, alias_used="report" ) == ( "To avoid SmokeDetector reporting posts too slowly, you can report at most 5 posts at a time. This is to avoid " "SmokeDetector's chat messages getting rate-limited too much, which would slow down reports." ) # assert chatcommands.report('a a a a a "invalid"""', original_msg=msg) \ # .startswith("You cannot provide multiple custom report reasons.") assert chatcommands.report('https://stackoverflow.com/q/1', original_msg=msg) == \ "Post 1: Could not find data for this post in the API. It may already have been deleted." # Valid post assert chatcommands.report('https://stackoverflow.com/a/1732454', original_msg=msg, alias_used="scan") == \ "Post 1: This does not look like spam" assert chatcommands.report( 'https://stackoverflow.com/a/1732454 "~o.O~"', original_msg=msg, alias_used="report") is None _, call = handle_spam.call_args_list[-1] assert isinstance(call["post"], Post) assert call["reasons"] == ["Manually reported answer"] assert call["why"] == ( "Post manually reported by user *El'endia Starman* in room *Charcoal HQ* with reason: *~o.O~*." "\n\nThis post would not have been caught otherwise.") # Bad post # This post is found in Sandbox Archive, so it will remain intact and is a reliable test post # backup: https://meta.stackexchange.com/a/228635 test_post_url = "https://meta.stackexchange.com/a/209772" assert chatcommands.report( test_post_url, original_msg=msg, alias_used="scan") is None _, call = handle_spam.call_args_list[-1] assert isinstance(call["post"], Post) assert call["why"].startswith( "Post manually scanned by user *El'endia Starman* in room *Charcoal HQ*." ) # Now with report-force GlobalVars.blacklisted_users.clear() GlobalVars.latest_questions.clear() assert chatcommands.report( test_post_url, original_msg=msg, alias_used="report-force") is None _, call = handle_spam.call_args_list[-1] assert isinstance(call["post"], Post) assert call["why"].startswith( "Post manually reported by user *El'endia Starman* in room *Charcoal HQ*." "\n\nThis post would have also been caught for:") # Don't re-report GlobalVars.latest_questions = [ ('stackoverflow.com', '1732454', 'RegEx match open tags except XHTML self-contained tags') ] assert chatcommands.report( 'https://stackoverflow.com/a/1732454', original_msg=msg).startswith("Post 1: Already recently reported") # Can use report command multiple times in 30s if only one URL was used assert chatcommands.report('https://stackoverflow.com/q/1732348', original_msg=msg, alias_used="report") is None finally: GlobalVars.blacklisted_users.clear() GlobalVars.latest_questions.clear()
def test_report(handle_spam): # Documentation: The process before scanning the post is identical regardless of alias_used. # No need to supply alias_used to test that part. # If no alias_used is supplied, it acts as if it's "scan" try: msg = Fake({ "owner": { "name": "ArtOfCode", "id": 121520, "is_moderator": False }, "room": { "id": 11540, "name": "Charcoal HQ", "_client": { "host": "stackexchange.com" } }, "_client": { "host": "stackexchange.com" }, "id": 1337 }) assert chatcommands.report("test", original_msg=msg, alias_used="report") == "Post 1: That does not look like a valid post URL." assert chatcommands.report("one two three four five plus-an-extra", original_msg=msg, alias_used="report") == ( "To avoid SmokeDetector reporting posts too slowly, you can report at most 5 posts at a time. This is to avoid " "SmokeDetector's chat messages getting rate-limited too much, which would slow down reports." ) # assert chatcommands.report('a a a a a "invalid"""', original_msg=msg) \ # .startswith("You cannot provide multiple custom report reasons.") assert chatcommands.report('https://stackoverflow.com/q/1', original_msg=msg) == \ "Post 1: Could not find data for this post in the API. It may already have been deleted." # Valid post assert chatcommands.report('https://stackoverflow.com/a/1732454', original_msg=msg, alias_used="scan") == \ "Post 1: This does not look like spam" assert chatcommands.report('https://stackoverflow.com/a/1732454 "~o.O~"', original_msg=msg, alias_used="report") is None _, call = handle_spam.call_args_list[-1] assert isinstance(call["post"], Post) assert call["reasons"] == ["Manually reported answer"] assert call["why"] == ( "Post manually reported by user *ArtOfCode* in room *Charcoal HQ* with reason: *~o.O~*." "\n\nThis post would not have been caught otherwise." ) # Bad post # This post is found in Sandbox Archive, so it will remain intact and is a reliable test post # backup: https://meta.stackexchange.com/a/228635 test_post_url = "https://meta.stackexchange.com/a/209772" assert chatcommands.report(test_post_url, original_msg=msg, alias_used="scan") is None _, call = handle_spam.call_args_list[-1] assert isinstance(call["post"], Post) assert call["why"].startswith("Post manually scanned by user *ArtOfCode* in room *Charcoal HQ*.") # Now with report-direct GlobalVars.blacklisted_users.clear() GlobalVars.latest_questions.clear() assert chatcommands.report(test_post_url, original_msg=msg, alias_used="report-direct") is None _, call = handle_spam.call_args_list[-1] assert isinstance(call["post"], Post) assert call["why"].startswith( "Post manually reported by user *ArtOfCode* in room *Charcoal HQ*." "\n\nThis post would have also been caught for:" ) # Don't re-report GlobalVars.latest_questions = [('stackoverflow.com', '1732454', 'RegEx match open tags except XHTML self-contained tags')] assert chatcommands.report('https://stackoverflow.com/a/1732454', original_msg=msg).startswith("Post 1: Already recently reported") # Can use report command multiple times in 30s if only one URL was used assert chatcommands.report('https://stackoverflow.com/q/1732348', original_msg=msg, alias_used="report") is None finally: GlobalVars.blacklisted_users.clear() GlobalVars.latest_questions.clear()