Esempio n. 1
0
def test_sidebar_pic(create_bot):
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Update control panel and plugin wiki
    sub.edit_wiki("control_panel", enable_wiki)
    sub.edit_wiki("change_sidebar", wiki_content)

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

    # Set fake sidebar
    sub.edit_wiki("config/sidebar", sub_decr)
    test.advance_time_10m()

    # Jump in time 23 hours and simulate one
    test.advance_time(60 * 60 * 23)
    test.advance_time_1h()
    assert(sub.widgets.sidebar[0].mod.data[0]
           ["linkUrl"] == "https://www.reddit.com/r/123")

    # Jump in time 23 hours and simulate one
    test.advance_time(60 * 60 * 23)
    test.advance_time_1h()
    assert(sub.widgets.sidebar[0].mod.data[0]
           ["linkUrl"] == "https://www.reddit.com/r/456")
def test_clone_post(create_bot):
    # Test cloned post
    test_submission = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                          author_name="JohnDoe1",
                                          title="title_test",
                                          body="asd1234")

    test.get_reddit().inbox.add_message(
        "mod1",
        "/clone_post --subreddit=testsub123 --sticky --title=test2 --sub_link=%s"
        % test_submission.shortlink)
    test.advance_time_10m()

    _, body = test.get_user("mod1").inbox[-1]

    # Get first line
    fline = body.split("\n")[0]

    # Get id
    target_sub = None
    id = fline.split(" ")[1]
    for sub in test.cache_submissions.values():
        if sub.shortlink == id:
            target_sub = sub

    # Check for content
    assert "asd1234" in target_sub.body

    # Edit the original body
    test_submission.edit("asd5678")

    test.advance_time_10m()

    # Check for content
    assert "asd5678" in target_sub.body
def test_create_from_wiki(create_bot):
    content = """
    content

    multi

    line
    """
    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 control panel and plugin wiki
    sub.edit_wiki("wiki123", content)

    test.get_reddit().inbox.add_message(
        "mod1",
        "/create_post --subreddit=%s --sticky --title=test --wikibody=wiki123"
        % TEST_SUBREDDIT)
    test.advance_time_10m()

    _, body = test.get_user("mod1").inbox[-1]

    # Get first line
    fline = body.split("\n")[0]

    # Get id
    target_sub = None
    id = fline.split(" ")[1]
    for s in test.cache_submissions.values():
        if s.shortlink == id:
            target_sub = s

    # Check for a word
    assert "multi" in target_sub.body

    # Edit the wiki
    sub.edit_wiki("wiki123", content + "XXX")

    # Check it again
    test.advance_time_10m()
    assert "XXX" in target_sub.body
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)
Esempio n. 5
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)
Esempio n. 6
0
def test_usernotes(create_bot):
    sub = test.get_subreddit(TEST_SUBREDDIT)

    unotes = sub.get_wiki("usernotes")
    unotes.set_content(open("tests/test_usernotes.json", "r").read(), "me")

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

    # Add a mod report
    submission.report("test1", "mod1")
    submission.report("test2", "invalid_mod")
    submission.report("test3")
    test.advance_time_10m()

    mod1 = test.get_user("mod1")

    assert(len(test.get_user("bot_owner").inbox) == 2)
    assert(len(mod1.inbox) == 0)

    submission.report("/get_notes", "invalid_mod")
    assert(len(test.get_user("bot_owner").inbox) == 3)

    submission.report("/get_notes", "mod1")
    assert(len(mod1.inbox) == 1)
    assert("Usernotes not found" in mod1.inbox[0][0])
    mod1.inbox = []

    submission2 = test.FakeSubmission(
        subreddit_name=TEST_SUBREDDIT,
        author_name="RoCirclejerk",
        title="title_test",
        body="12345 oqiwjeoqiw aaa xxxabcdefxxx")
    test.advance_time_10m()

    submission2.report("/get_notes", "mod1")
    assert(len(mod1.inbox) == 1)
    assert("test1" in mod1.inbox[0][1])
def test_sched_post(create_bot):
    enable_sched_posts = """
    [Enabled Plugins]
    schedule_posts
    """

    sub = test.get_subreddit(TEST_SUBREDDIT)

    test.set_time(22 * 60 * 60)
    test_submission = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                          author_name="JohnDoe1",
                                          title="title_test",
                                          body="asd1234")

    wiki_sched_posts = r"""
    [post_at_12AM]
    title=test1 test2 ${DAY}.${MONTH}.${YEAR}
    body=aaa
     bbb
     ccc
    interval= 0 0 * * * *

    [post_at_1AM]
    title=test3 test4
    wikibody=post1AM
    interval= 0 1 * * * *

    [post_at_2AM]
    title=test5 test6
    clonepost=%s
    interval= 0 2 * * * *
    """ % test_submission.permalink

    sub.edit_wiki("post1AM", "xx1")

    # Update control panel and plugin wiki
    sub.edit_wiki("control_panel", enable_sched_posts)
    sub.edit_wiki("schedule_posts", wiki_sched_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_10m()

    test.advance_time_1h()
    test.advance_time_1h()
    test.advance_time_1h()
    test.advance_time_1h()

    post_12am = None
    post_1am = None
    post_2am = None

    # Get the posts
    for post in test.cache_submissions.values():
        if post.title.startswith("test1 test2"):
            post_12am = post

        if post.title == "test3 test4":
            post_1am = post

        if post.title == "test5 test6":
            post_2am = post

    assert post_12am
    assert post_1am
    assert post_2am

    assert post_12am.created_utc - 86400 < 60
    assert post_1am.created_utc - 90000 < 60
    assert post_2am.created_utc - 93600 < 60
def test_create_post(create_bot):
    # Test basic commands
    test.get_reddit().inbox.add_message(
        "mod1",
        "/create_post --subreddit=testsub123 --sticky --title test1 test2 test3 --body zzz ddd"
    )
    test.advance_time_10m()

    _, body = test.get_user("mod1").inbox[-1]

    # Get first line
    fline = body.split("\n")[0]

    # Get id
    target_sub = None
    id = fline.split(" ")[1]
    for sub in test.cache_submissions.values():
        if sub.shortlink == id:
            target_sub = sub

    # Create comments
    comm1 = target_sub.add_comment("asd", "xxx1")
    comm2 = target_sub.add_comment("asd", "qwe1")

    # Tell the bot to add them
    test.get_reddit().inbox.add_message(
        "mod1", "/integrate_comment --sub_link %s --comment_link %s" %
        (target_sub.shortlink, comm1.permalink))
    test.get_reddit().inbox.add_message(
        "mod1", "/integrate_comment --sub_link %s --comment_link %s" %
        (target_sub.shortlink, comm2.permalink))

    # Check if added
    test.advance_time_10m()
    assert "xxx1" in target_sub.body
    assert "qwe1" in target_sub.body

    # Edit and check again
    comm1.edit("xxx2")
    comm2.edit("qwe2")

    # Check if added again
    test.advance_time_10m()
    assert "xxx2" in target_sub.body
    assert "qwe2" in target_sub.body

    test.get_reddit().inbox.add_message(
        "mod1", "/nointegrate_comment --sub_link %s --comment_link %s" %
        (target_sub.shortlink, comm1.permalink))

    # Check if added again
    test.advance_time_10m()
    assert "xxx2" not in target_sub.body
    assert "qwe2" in target_sub.body

    # Unsticky the comment
    target_sub.mod.sticky(False, False)

    # Edit the comments
    comm2.edit("qwe3")

    # Make sure that comments were not added
    test.advance_time_10m()
    assert "qwe2" in target_sub.body

    # resticky the comment
    test.get_reddit().inbox.add_message(
        "mod1", "/resticky --sub_link %s" % (target_sub.shortlink))

    # Check if it was updated
    test.advance_time_10m()
    assert "qwe3" in target_sub.body
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)
Esempio n. 10
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)
def test_inbox_help(create_bot):
    # Test basic commands
    test.get_reddit().inbox.add_message("randomuser", "/help")
    test.advance_time_10m()
    test.get_reddit().inbox.add_message("randomuser", "/ping")
    test.advance_time_10m()
    # Test unauthrized command
    test.get_reddit().inbox.add_message("randomuser", "/system_status")
    test.advance_time_10m()
    test.get_reddit().inbox.add_message("randomuser", "/reset_image")
    test.advance_time_10m()
    assert(len(test.get_user("randomuser").inbox) == 2)

    test.get_reddit().inbox.add_message("bot_owner", "/help")
    test.advance_time_10m()
    test.get_reddit().inbox.add_message("bot_owner", "/system_status")
    test.advance_time_10m()

    assert(len(test.get_user("bot_owner").inbox) == 5)
Esempio n. 12
0
def test_yt_post(create_bot):
    sub = test.get_subreddit(TEST_SUBREDDIT)

    # Update control panel and plugin wiki
    sub.edit_wiki("control_panel", yt_plugin)
    sub.edit_wiki(
        "youtube", r"""
    [ch1]
    id = 101
    message = got a post by some channel ${AUTHOR} ${KIND}

    [ch2]
    id = 102
    message = got a post by some channel ${AUTHOR} ${KIND}
    report = blah

    [ch3]
    id = 103
    message = got a post by some channel ${AUTHOR} ${KIND}
    delete = True
    """)

    # 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()

    ###
    # Test1
    ###
    test_submission1 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe1",
                                           title="asdfg",
                                           url="https://youtube.com/watch?v=1")
    test.advance_time_30s()

    # Check conditions are successful for t1
    assert (len(sub.modmail) == 1)
    assert (test_submission1.deleted == False)
    assert (len(test_submission1.reports) == 0)

    ###
    # Test2
    ###
    test_submission2 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe1",
                                           title="asdfg",
                                           url="https://youtube.com/watch?v=2")
    test.advance_time_30s()
    # Check conditions are successful for t2
    assert (len(sub.modmail) == 2)
    assert (test_submission2.deleted == False)
    assert (len(test_submission2.reports) == 1)

    ###
    # Test3
    ###
    test_submission3 = test.FakeSubmission(subreddit_name=TEST_SUBREDDIT,
                                           author_name="JohnDoe1",
                                           title="asdfg",
                                           url="https://youtube.com/watch?v=3")
    test.advance_time_30s()
    # Check conditions are successful for t3
    assert (len(sub.modmail) == 3)
    assert (test_submission3.deleted == True)
    assert (len(test_submission3.reports) == 0)