def test_flair_warning(create_bot):
    wiki_flair_posts = """
    [Setup]
    message_intervals = 5, 7, 9, 10, 15, 20, 25
    autoflair = 1

    message = message ${MESSAGE_NO}/${MAX_MESSAGES}/${SUBMISSION_LINK}

    [autoflair_test1]
    title_contains = ["testa", "testb"]
    flair_css_class = "testflair"
    """
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Update flair posts control panel
    sub.edit_wiki("control_panel", enable_flair_posts)
    sub.edit_wiki("flair_posts", wiki_flair_posts)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Give some time to the bot to get the new wiki configuration
    test.advance_time_60s()

    # Create a new submissinon that we will be testing against
    test_submission = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                          author_name="JohnDoe1",
                                          title="title_test")

    # Give the bot time to send all messages
    test.advance_time_30m()

    user = test.get_user("JohnDoe1")

    # Check that 7 messages have been sent
    assert (len(user.inbox) == 7)

    # Check each inbox message
    msg_no = 1
    while len(user.inbox) != 0:
        _, text = user.inbox[0]
        assert ("message %d/7/%s" % (msg_no, test_submission.shortlink)
                in text)

        msg_no += 1
        user.inbox = user.inbox[1:]
예제 #2
0
def test_notify(create_bot):
    wiki_trigger_words = """
    [Setup]
    word_list = ["12345", "abcdef", "aaa"]
    ignore_users = ["JohnDoe2"]
    """
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Update flair posts control panel
    sub.edit_wiki("control_panel", enable_flair_posts)
    sub.edit_wiki("word_notifier", wiki_trigger_words)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Give some time to the bot to get the new wiki configuration
    test.advance_time_60s()

    test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="JohnDoe1",
        title="title_test",
        body="blabla qweqw")
    test.advance_time_10m()

    submission = test.FakeSubmission(
        subreddit_name="some_other_sub",
        author_name="JohnDoe1",
        title="title_test",
        body="12345 oqiwjeoqiw aaa xxxabcdefxxx")
    test.advance_time_10m()

    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Check that modmail has been sent
    assert(len(sub.modmail) == 1)

    submission.add_comment("user1", "12345 1234")
    test.advance_time_10m()

    # Check that modmail has been sent
    assert(len(sub.modmail) == 2)
def test_changed_title(create_bot):
    wiki_flair_posts = """
    [Setup]
    minimum_overlap_percent = 60
    domains = ["google.com", "blabla.co.uk"]
    """
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Update control panel and plugin wiki
    sub.edit_wiki("control_panel", enable_flair_posts)
    sub.edit_wiki("changed_title", wiki_flair_posts)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Give some time to the bot to get the new wiki configuration
    test.advance_time_60s()

    # Create fake articles
    test.FakeURL("https://google.com/myarticle1",
                 "I don't like mosquitoes because they suck blood")
    test.FakeURL("https://google.com/myarticle2",
                 "qwerty asdfg zxcvb poiuy lkjhg mnbvc")

    # Test it
    test_submission1 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="JohnDoe1",
        title="AAAA BBBB CCCC DDDD EEEE FFFF",
        url="https://google.com/myarticle1")
    test_submission2 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="JohnDoe1",
        title="qwerty asdfg zxcvb poiuy lkjhg mnbvc",
        url="https://google.com/myarticle2")
    test.advance_time_10m()

    assert (len(test_submission1.reports) == 1)
    assert (len(test_submission2.reports) == 0)
예제 #4
0
def test_webhook(create_bot):
    wiki_cfg = """
    [Setup]
    modlog = http://webhook1
    submissions = http://webhook2
    """
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Update control panel and plugin wiki
    sub.edit_wiki("control_panel", enable_streamer)
    sub.edit_wiki("webhook_streamer", wiki_cfg)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Give some time to the bot to get the new wiki configuration
    test.advance_time_60s()

    # Check that the webhook target is None first
    # (aka does not exist because no messages have been sent)
    assert (test.get_webhook("http://webhook1") == None)

    # Add modlog item
    sub.add_modlog("mod1", "dummy_target", "test", "blabla",
                   "test description")

    # Check again
    assert (len(test.get_webhook("http://webhook1").messages) == 1)

    test.advance_time_60s()

    # Check that the webhook target is None first
    # (aka does not exist because no messages have been sent)
    assert (test.get_webhook("http://webhook2") == None)

    # Create a new submissinon to test submission webhooks too
    test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                        author_name="JohnDoe1",
                        title="AAAA BBBB CCCC DDDD EEEE FFFF")

    test.advance_time_60s()

    # Check again
    assert (len(test.get_webhook("http://webhook2").messages) == 1)
def test_auto_flair(create_bot):
    wiki_flair_posts = """
    [Setup]
    autoflair = 1

    [autoflair_test1]
    title_contains = ["test1", "test2"]
    flair_css_class = "testflair1"

    [autoflair_test2]
    title_contains = ["test3", "test4"]
    flair_css_class = "testflair2"

    [autoflair_test3]
    body_contains = ["test5", "test6"]
    flair_css_class = "testflair3"

    [autoflair_test4]
    domain = ["redditbot.com", "pula.ro"]
    flair_css_class = "testflair4"

    [autoflair_test5]
    title_contains = ["prio1", "prio2"]
    flair_css_class = "testflair5"
    priority = 50

    [autoflair_test6]
    title_contains = ["prio1", "prio2"]
    flair_css_class = "testflair6"
    priority = 40
    """

    sub = test.get_subreddit(TEST_SUBREDDIT)
    # Update flair posts control panel
    sub.edit_wiki("control_panel", enable_flair_posts)
    sub.edit_wiki("flair_posts", wiki_flair_posts)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Give some time to the bot to get the new wiki configuration
    test.advance_time_60s()

    subreddit = test.get_subreddit(TEST_SUBREDDIT)
    subreddit.set_flairs([
        "testflair1", "testflair2", "testflair3", "testflair4", "testflair5",
        "testflair6"
    ])

    # Test titles
    test_submission1 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe1",
                                           title="blabla test1 blabla")

    test_submission2 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe2",
                                           title="blabla test4 blabla")

    # Give the bot time to send all messages
    for _ in range(30):
        test.advance_time_60s()

    assert (test_submission1.flairs.set_flair_id == "testflair1")
    assert (test_submission2.flairs.set_flair_id == "testflair2")

    # Test body
    test_submission3 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="JohnDoe1",
        title="blabla 1234 blabla",
        body="qoweiqoiejqoiwjq test5 pqioejoqij")

    # Give the bot time to send all messages
    for _ in range(30):
        test.advance_time_60s()

    assert (test_submission3.flairs.set_flair_id == "testflair3")

    # Test domain
    test_submission4 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="JohnDoe1",
        title="blabla 1234 blabla",
        url="https://www.redditbot.com/12345.123")

    # Give the bot time to send all messages
    test.advance_time_30m()

    assert (test_submission4.flairs.set_flair_id == "testflair4")

    # Test priority
    test_submission5 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe1",
                                           title="blabla prio2 blabla")

    # Give the bot time to send all messages
    test.advance_time_30m()

    assert (test_submission5.flairs.set_flair_id == "testflair6")
예제 #6
0
def test_repost_detector(create_bot):
    wiki_flair_posts = """
    [Setup]
    minimum_word_length = 3
    minimum_nb_words = 5
    min_overlap_percent = 50
    ignore_users = ["AutoModerator"]
    """
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Update control panel and plugin wiki
    sub.edit_wiki("control_panel", enable_flair_posts)
    sub.edit_wiki("repost_detector", wiki_flair_posts)

    # Tell the bot to update the control panel
    test.get_reddit().inbox.add_message(
        "mod1", "/update_control_panel --subreddit %s" % TEST_SUBREDDIT)

    # Give some time to the bot to get the new wiki configuration
    test.advance_time_60s()

    # Create a new submissinon that we will be testing against
    test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                        author_name="JohnDoe1",
                        title="AAAA BBBB CCCC DDDD EEEE FFFF")

    test.advance_time_30m()

    # Create another submission
    test_submission2 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="JohnDoe1",
        title="AAAA BBBB CCCC DDDD EEEE GGGG")
    test.advance_time_10m()

    assert (len(test_submission2.reports) == 1)

    test.advance_time_30m()

    # Test short word elimination
    test_submission3 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe1",
                                           title="AAAA BBBB CCCC DDDD")

    assert (len(test_submission3.reports) == 0)

    # Jump in time one month
    test.advance_time(2592000)
    test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                        author_name="JohnDoe1",
                        title="AAAB BBBC CCCD DDDE EEEG GGGF")
    # Give the chance to remove a post from storage due to being too old
    test.advance_time_30m()

    # Test user ignore
    test_submission4 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="automoderator",
        title="AAAA BBBB CCCC DDDD EEEE GGGG")
    test.advance_time_10m()

    assert (len(test_submission4.reports) == 0)