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:]
def test_invalid_cfg(create_bot):
    wiki_flair_posts = """
    [Seup]

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

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

    test.advance_time_30m()

    assert (len(test.get_user("wikieditboy").inbox) == 1)
def test_invalid_cfg(create_bot):
    wiki_flair_posts = """
    [Seup]
    message_intervals = 2, 30

    message = message ${MESSAGE_NO}/${MAX_MESSAGES}/${SUBMISSION_LINK}
    """
    test.create_bot(TEST_SUBREDDIT)
    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,
                  author="wikieditboy_flair_posts")

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

    test.advance_time_30m()

    assert (len(test.get_user("wikieditboy_flair_posts").inbox) == 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")
def test_corner_cases(create_bot):
    wiki_flair_posts = """
    [Setup]
    message_intervals = 2, 30

    message = message ${MESSAGE_NO}/${MAX_MESSAGES}/${SUBMISSION_LINK}
    """
    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_10m()

    # Create new submissions
    test_submission1 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe123",
                                           title="random title")

    test_submission2 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe123",
                                           title="random title")

    test_submission3 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe123",
                                           title="random title")

    # Advance a few minutes so that one message is sent
    test.advance_time_10m()

    # Remove it by a mod
    test_submission1.delete_by_mod()

    # Remove it by the author
    test_submission2.delete_by_author()

    # Add flair by user
    test_submission3.set_link_flair_text("asdfg")

    # Give the bot time to remove the posts from queues
    test.advance_time_30m()
    test.advance_time_30m()

    user = test.get_user("JohnDoe123")

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

    # Try to exceed minimum trigger time
    test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                        author_name="granular",
                        title="random title")
    test.advance_time(test.GLOBAL_TIME + 61)

    assert (len(test.get_user("granular").inbox) == 0)
Exemplo n.º 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)